Add a directory to PATH in ZSH
December 27, 2020 ‐ 2 min read
The place where you want to add directories to your PATH is in the
.zshrc file. Since this file gets loaded once you enter the shell, you make sure your settings don’t disappear when restarting the shell.
The more generic way to add a directory to the path is to export a PATH variable in your
.zshrc file. This approach works just as well in the Bash shell. You set this PATH variable equal to a string of paths separated by a colon(
:). Often you want to include the current value of PATH in this string as well, by doing this you add paths instead of overwriting PATH.
For example, if you would like to add the paths
/home/koen/.local/bin to your PATH you would add the following to your
.zshrc. You can make use of tilde expansion here, as a shortcut for your home directory.
ZSH does also offer another way to add paths to the PATH variable, like it is a list of some sort.
path+=('~/bin') path+=('/home/koen/.local/bin') export PATH
So what exactly is this $PATH?
PATH is an environment variable where you tell your system to look for executables when you enter a command in the shell.
You can inspect the value of the PATH variable by running the following.
$ echo $PATH
This outputs a string with locations like
/bin. When you install a program like git, the executable program for git is placed in one of these directories. So that your system can actually find the commands you run.