How do I add a directory to my $PATH in Ubuntu and make the changes permanent?
|
|
||||
|
|
migrated from serverfault.com Sep 6 '11 at 7:35
|
A path set in .bash_profile will only be set in a bash login shell ( For example
Btw, you can check the PATH variable of a process by looking at its environment in |
|||||||||||||||
|
|
Edit
You will need to source your To source your
when in the home directory. |
|||||||||||||||||||||
|
|
I think the better way in idealogy of Ubuntu is:
|
||||
|
|
For complete newbies (like I am) who are more comfortable with GUI:
|
|||||
|
|
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 |
|||||||||||||||||||||
|
|
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 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. |
|||||||||||||||||
|
|
Environment variable settings that should affect just a particular user (rather than the system as a whole) should be set into:
It is not a script file, but rather consists of assignment expressions, one per line.
Note: Using .pam_environment requires a re-login in order to initialize the variables. Restarting just the terminal is not sufficient to be able to use the variables. source: https://help.ubuntu.com/community/EnvironmentVariables#Session-wide_environment_variables |
|||
|
|
|
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:
|
||||
|
|
add there
|
|||||||
|
|
Whenever I "install" my folder of BASH scripts, I follow the pattern of the test for a $HOME/bin folder that's in most .profile files in recent versions of Ubuntu. I set a test that looks like
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 /scripts somewhere closer to my $HOME folder. I haven't done so in 6 Ubuntu installs, but there's "always tomorrow." S BZT |
|||
|
|
|
In terminal,
This wasn't my idea. I found this way to export path at this blog here. |
||||
|
|
|
For Ubuntu edit the
Then edit your .bash_profile as you need..... |
|||||||
|
|
Open your terminal, type
Close and open terminal, it should be working. |
||||
|
|
|
Put it to your ~/.bashrc or whatevershell you use rc (or to beforementioned ~/.profile) AND ~/.xsessionrc so it will also work in X (outside shell). |
|||
|
|


