To permanently add a directory to the $PATH
variable in Bash on Linux, you can follow these steps:
Open the .bashrc
file in a text editor. This file is located in your home directory (e.g., /home/username/.bashrc
).
Add the following line to the end of the file, replacing /path/to/directory
with the actual path of the directory you want to add to the $PATH
variable:
export PATH=$PATH:/path/to/directory
Save the file and exit the editor.
Run the following command to reload the .bashrc
file and apply the changes:
source ~/.bashrc
You can now use executables located in the directory you added to the $PATH
variable without specifying the full path to the executable.
Note: The
.bashrc
file is only read by Bash when you start a new terminal session or when you run thesource
command. If you want the changes to take effect in all terminal sessions, you can also add the same line to the/etc/environment
file. This file is read by all processes on the system and is used to set environment variables for all users.