How to add to bash $PATH permanently on Linux

To add a directory to your $PATH environment variable on a Linux system permanently, you can edit the shell profile file. The exact file you need to edit depends on your shell. For the bash shell, you can add a directory to the $PATH environment variable by editing the .bashrc file in your home directory.

Here’s how to add a directory to $PATH in the bash shell:

  1. Open the .bashrc file: You can open the .bashrc file in a text editor, such as nano, by running the following command:
nano ~/.bashrc
  1. Add the directory to $PATH: At the end of the file, add the following line, replacing /path/to/directory with the path to the directory you want to add to $PATH:
export PATH=$PATH:/path/to/directory
  1. Save the changes: Save the changes to the .bashrc file by pressing CTRL + X and then Y.
  2. Refresh the shell: To apply the changes, you’ll need to refresh the shell. You can do this by running the following command:
source ~/.bashrc
  1. Verify the change: You can verify that the directory has been added to $PATH by running the following command:
echo $PATH

This will display a list of directories in $PATH, including the directory you just added.

By following these steps, you should be able to add a directory to the $PATH environment variable in the bash shell permanently.

Leave a Comment