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:
- Open the
.bashrcfile: You can open the.bashrcfile in a text editor, such asnano, by running the following command:
nano ~/.bashrc
- Add the directory to
$PATH: At the end of the file, add the following line, replacing/path/to/directorywith the path to the directory you want to add to$PATH:
export PATH=$PATH:/path/to/directory
- Save the changes: Save the changes to the
.bashrcfile by pressingCTRL + Xand thenY. - 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
- Verify the change: You can verify that the directory has been added to
$PATHby 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.