How do I add a directory to the $PATH in Ubuntu and make the changes permanent?
|
|
||||
migrated from serverfault.com Sep 6 '11 at 7:35This question came from our site for system and network administrators. |
||||
|
|
||||
Using ~/.profile to set $PATHA path set in For example
Btw, you can check the PATH variable of a process by looking at its environment in Note:
See the answers below for information about |
|||||||||||||||||||||
|
|
Edit
You will need to source your
|
|||||||||||||||||||||
|
|
The recommended place to define permanent, system-wide environment variables applying to all users is in:
(which is where the default This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)
To effect changes, run Related: |
|||||||||||||
|
|
I think the canonical way in Ubuntu is:
|
|||||||||
|
|
For complete newbies (like I am) who are more comfortable with GUI:
|
|||||||||||||||||||||
|
|
For persistent environment variables available to particular users only. I highly recommend Ubuntu official documentation. https://help.ubuntu.com/community/EnvironmentVariables Referring to documentation above, I have setup my Android SDK path-tools by:
|
|||||||||
|
|
Put that line in your It gets sourced whenever you open a terminal EDIT: Based on the comments below, for a more general setting that will apply to all shells (including when you hit Alt-F2 in Unity), add the line to your |
|||||||||||||||||||||
|
|
To set it system wide, append the line To add the directory for only the logged-in user, append the same line to |
|||||
|
|
Adding it to .bashrc will work but I think the more traditional way of setting up your path variables is in .bash_profile by adding the following lines.
According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones. |
|||||||||||||||||||||
|
add there
|
|||||||||||||
|
|
In terminal,
This wasn't my idea. I found this way to export path at this blog here. |
|||||
|
|
Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a
It works just about 100% of the time, and leaves me free to change it in a GUI text editor with a quick "Replace all" should I ever decide to move BZT |
|||||
|
|
Open your terminal, type
Close and open terminal, it should be working. |
|||||
|
|
The recommended way to edit your Example output of
For example, to add the new path of
More info can be found here: EnvironmentVariables |
|||||
|
|
https://help.ubuntu.com/community/EnvironmentVariables There is all you need to know. I found out that a lot of the input here was incorrect or at least the method was not suggested. This is a great piece of information that will let you figure out where to modify your environment variable based on the reason you are doing it and exactly how to do it without screwing everything up (like I did following some of the aforementioned bad advice). So long, and thanks for all the fish! |
|||||||||||||
|
|
For Ubuntu edit the
Then edit your .bash_profile as you need..... |
|||||||||
|
|
Put it to your |
||||
|
|
|
Even if system script do not use this,
in any of the cases that one wants to add a path (e.g.,
for appending (instead of
for prepending (instead of This avoids the spurious leading/trailing colon when |
|||
|
|
protected by heemayl Aug 21 '15 at 22:00
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?