Add new path to path variable linux
To add a new path to the PATH
variable in Linux, you can follow these steps:
Method 1: Using the export
command
- Open a terminal and type the following command:
export PATH=$PATH:/new/path
Replace
/new/path
with the actual path you want to add.
Method 2: Using the export
command with a permanent change
- Open a terminal and type the following command:
export PATH=$PATH:/new/path echo "export PATH=$PATH:/new/path" >> ~/.bashrc
This will add the new path to the
PATH
variable and also update the~/.bashrc
file, which is a configuration file that is read by the shell when it starts.
Method 3: Using the export
command with a system-wide change
- Open a terminal and type the following command:
sudo export PATH=$PATH:/new/path
This will add the new path to the
PATH
variable system-wide, which means it will affect all users on the system.
Method 4: Editing the ~/.bashrc
file
- Open the
~/.bashrc
file in a text editor:nano ~/.bashrc
- Add the following line at the end of the file:
export PATH=$PATH:/new/path
- Save the file and restart your terminal or run
source ~/.bashrc
to apply the changes.
Method 5: Using the update-alternatives
command (for system-wide changes)
- Open a terminal and type the following command:
sudo update-alternatives --install /usr/bin/path path /new/path 1
This will add the new path to the
PATH
variable system-wide and make it the default.
Note: The update-alternatives
command is used to manage alternatives for commands, but it can also be used to add new paths to the PATH
variable.
After adding the new path, you can verify that it has been added by running the following command:
echo $PATH
This will display the updated PATH
variable.