To add a new directory to the PATH
environment variable in Linux, you can follow these steps:
- Open a terminal window.
- Check your current
PATH
by 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 calledbin
in your home directory:mkdir ~/bin
- Add the new directory to your
PATH
by 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~/.bashrc
file:nano ~/.bashrc
Add the following line at the end of the file:
export PATH=$PATH:~/bin
This appends the new directory to the existing
PATH
variable, 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
PATH
environment variable. - Verify that the new directory has been added to your
PATH
by 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.