To add a new directory to the PATH environment variable in Linux, you can follow these steps:
- Open a terminal window.
- Check your current
PATHby running the following command:echo $PATH
This will display a list of directories separated by colons. These directories are searched in order when you type a command in the terminal.
- Create a new directory that you want to add to the
PATH. For example, you might create a directory calledbinin your home directory:mkdir ~/bin
- Add the new directory to your
PATHby editing your shell startup file. The exact file you need to edit will depend on which shell you’re using. For example, if you’re using the Bash shell, you would edit your~/.bashrcfile:nano ~/.bashrc
Add the following line at the end of the file:
export PATH=$PATH:~/bin
This appends the new directory to the existing
PATHvariable, separated by a colon. - Save and close the file. In nano, you can do this by pressing
Ctrl+X, thenY, thenEnter. - Reload your shell startup file by running the following command:
source ~/.bashrc
This will apply the changes you made to your
PATHenvironment variable. - Verify that the new directory has been added to your
PATHby running the following command:echo $PATH
This should display the original directories in your
PATH, followed by the new directory you added.
You can now place executable files in your new directory (~/bin in this example) and run them from any location in the terminal.