The right way to set the $PATH variable in .zshrc

shellzsh

When I first installed Zsh (using Oh My Zsh), the ~/.zshrc file had the following commented lines by default:

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH

What is the author trying to say here? Bash was the default shell on macOS and Linux, so yes, I was coming from Bash. Were they trying to say that I should just uncomment the second line? Or were they saying that I should do some other setup that I should look for on theĀ internet?

Anyone who is well versed is welcome to explain how should I configure the $PATH the right way when I first install Zsh on my MacBook with OS X 10.11 El Capitan.

Best Answer

There is nothing wrong in setting your path by uncommenting the second line. However, having that path enabled by default in oh-my-zsh will, at the very least, be annoying. Why? You could have already set up your own PATH and then this will break functionality you've explicitly set up.

The author is trying to say that bash environments do not have $HOME/bin and /usr/local/bin in their default PATH, however, both places are quite popular for packets(/usr/local/bin is where anything you install lives in UNIX systems like FreeBSD while $HOME/bin is usually for user installed packets that were installed without root privileges).

Lastly, you can set up your PATH the best way that fits your needs. A good way will be to start with examining what's currently in your PATH and adding any extra paths to it as you find fit

export PATH=/some/path:$PATH
Related Question