Home » Questions » Computers [ Ask a new question ]

How can I edit the $PATH on linux?

How can I edit the $PATH on linux?

I am using ubuntu 9.04 I need to add some folder to my $PATH. I know how to read the path:

Asked by: Guest | Views: 414
Total answers/comments: 5
Guest [Entry]

"To permanently store your path, you have a few options.

I suggest you read the Ubuntu community wiki on Environment Variables but the short answer is the best place is ~/.profile for your per-user PATH setting or /etc/profile for global settings.

Do something like export PATH=$PATH:/your/new/path/here"
Guest [Entry]

"You can also put this in the global environment:

sudo emacs /etc/environment

Append to the entries already in your path

PATH=""/path/to/file:/other/paths""

Reload the environment

source /etc/environment"
Guest [Entry]

"A variant from above, if you don't want to change the /etc/profile file directly.
You can create a new file yourpath.sh in the /etc/profile.d/ directory. Then edit this file like that. With vim editor (but feel free to edit it with another editor):
vim /etc/profile.d/yourpath.sh

MYPATH='/your/new/path/'
export MYPATH
export PATH=$PATH:$MYPATH

:write and quit and it's done your path has been modified. If your are using the terminal, close it and reopen it . your new variable will be updated.
Now it is cleaner, you can remove this file when you don't need it anymore and it doesn't interfer with the initial configuration."
Guest [Entry]

"All answers intend to add to the PATH but this is how you remove an environment variable

Suppose you had the path

PATH=/home/pradan/ti-processor-sdk-linux-am57xx-evm-06.02.00.81/linux-devkit/sysroots/x86_64-arago-linux/usr/bin:...other variables...:/snap/bin

and want to remove the first variable /home/pradan/ti-processor-sdk-linux-am57xx-evm-06.02.00.81/linux-devkit/sysroots/x86_64-arago-linux/usr/bin.

Open the .profile and edit it

$ gedit ~/.profile

A text editor open up with the hated variable as shown
Comment it out and after Ctrl+S, close this file.

Source the script

$ source /etc/environment

And Done :)

To verify, recheck the updated path using printenv."
Guest [Entry]

"If you're using ZSH, you can edit your paths like this:
nano ~/.zshrc"