How to permanently set $PATH on Linux/Unix


To permanently set the $PATH environment variable on Linux/Unix systems, you can modify the configuration files for your shell. The exact files to modify depend on the shell you are using, such as Bash, Zsh, or Fish. Here are the common configuration files you can edit:

Bash Shell:

  • Open your terminal and open the ~/.bashrc file in a text editor.
  • Add the following line at the end of the file to set the PATH variable:
         export PATH=/your/new/path:$PATH
  • Save the file and exit the text editor.
  • Run the following command to apply the changes:
          source ~/.bashrc

Zsh Shell:

  • Open your terminal and open the ~/.zshrc file in a text editor.
  • Add the following line at the end of the file to set the PATH variable
        export PATH=/your/new/path:$PATH
  • Save the file and exit the text editor.
  • Run the following command to apply the changes:
      source ~/.zshrc

Fish Shell:

  • Open your terminal and open the ~/.config/fish/config.fish file in a text editor.
  • Add the following line at the end of the file to set the PATH variable:
   set -x PATH /your/new/path $PATH
  • Save the file and exit the text editor.

The changes should take effect immediately.

Replace /your/new/path with the desired path you want to add to the $PATH variable. You can specify multiple paths by separating them with a colon (:). The existing $PATH variable is appended to the new path using $PATH.

After making these changes, any new terminal sessions you open will have the modified $PATH variable permanently set.

Note that different shells have different configuration files, so make sure you modify the appropriate file based on the shell you are using. If you are unsure which shell you are using, you can check by running the echo $SHELL command in your terminal.