Add a Directory to PATH in Linux

-


What is $PATH in Linux

The $PATH environmental variable is a colon-delimited list of directories that tells the shell which directories to search for executable files.

1
2
 ✘ gecheng@A ~  echo $PATH
/Users/gecheng/.jenv/shims:/Users/gecheng/.jenv/bin:/Users/gecheng/.jenv/shims:/Users/gecheng/.jenv/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin

Adding a Directory to your $PATH

To make the change permanent, you need to define the $PATH variable in the shell configuration files. In most Linux distributions when you start a new session, environment variables are read from the following files:

  • Global shell specific configuration files such as /etc/environment and /etc/profile. Use this file if you want the new directory to be added to all system users $PATH.
  • Per-user shell specific configuration files. For example, if you are using Bash, you can set the $PATH variable in the ~/.bashrc file and if you are using Zsh the file name is ~/.zshrc.
1
export PATH="$HOME/.local/bin:$PATH"

Save the file and load the new $PATH into the current shell session using the source command:

1
source ~/.bashrc

  linux
Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×