2

I just recently got a M1 Mac which uses the Z-shell (zsh) terminal. All my new installations that I run through my terminal (such as on homebrew, npm, etc.) are installed to /Users/myusername/Library/ which is not in PATH and therefore causes a ton of headaches and problems down the line as I need to add each new add each newly installed directory to PATH.

I am quite new to the terminal and completely new to zsh and am having trouble figuring this out.

Is there a way in which I can set up my PATH so that any new installations from the command-line are immediately in PATH and I don't have to do it manually each time?

Right now I'll get errors any time I try to access a newly installed directory. It will say something like:

Could not find dependency or I'll get a WARNING: The script is 
installed in Users/myusername/Library/... which is not on PATH. 
Consider adding this directory to PATH...

And every time this is due to my newly installed directory being added to my Library which is not in PATH and every time I'll have to do some tweaking of my ~/.zshrc file in order to access them.

I take it this has something to do with the way in which I set up my development environment from the start? All help is greatly appreciated.

1 Answer 1

2

Install directory ≠ PATH.

Your path (environment variable) is an ordered listing of directories your shell will go through to find a command/resource. Your install directory is where the binaries, libraries, configuration files, etc. get installed.

To put it another way, your PATH can reference you install directory, but you can’t install something to your PATH.

Could not find dependency… WARNING: The script is installed in... which is not on PATH. Consider adding this directory to PATH...

That error message is telling you that a binary you just executed, expects certain files to be found in your PATH but it’s not finding them.

How to add items to PATH

You can find out what’s in your PATH by executing the command:

echo $PATH

You should get output similar to the following:

/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

You can add a directory immediately (temporarily) to the PATH variable by simply setting it with the directory you want to include:

% PATH=$PATH:/foo/bar:/foobar/foobar

Note that each directory is separated with a colon (:). We also reference the existing PATH variable with the $PATH.

To make it permanent, you would put this command in either your .zprofile or .zshrc (whichever one has your existing PATH set). These files are located in your home directory referenced by $HOME or the tilde ~/.

To edit it, use and editor like nano or vi (I prefer nano, but it might not be included in Ventura anymore)

% nano ~/.zprofile

Simply add/edit the file to include the PATH command shown above, save, then restart terminal.


You might hear that you need to EXPORT your path. I deliberately left that out here as to not overwhelm you with info. EXPORTing a variable in a shell makes it available to subshells. You can experiment with this by setting the PATH as shown above, then open a new shell by typing zsh and then echo $PATH again. Try it with EXPORT and without.

1
  • this works for me. I tried a few other methods but this is the only one that worked. Nov 9, 2023 at 19:59

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .