A path set in .bash_profile will only be set in a bash login shell (bash -l).
If you put your path in .profile it will be available to your complete desktop session. That means even metacity will use it.
For example ~/.profile:
if [ -d "$HOME/bin" ] ; then
PATH="$PATH:$HOME/bin"
fi
Btw, you can check the PATH variable of a process by looking at its environment in /proc/[pid]/environ (replace [pid] with the number from ps axf). E.g. use grep -z "^PATH" /proc/[pid]/environ
Note:
bash as a login shell doesn't parse .profile if either .bash_profile or .bash_login exists. From man bash :
it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that
order, and reads and executes commands from the first one that exists
and is readable.
See the answers below for information about .pam_environment, or .bashrc for interactive non-login shells, or set the value globally for all users by putting a script into /etc/profile.d/ or use /etc/X11/Xsession.d/ to affect the display managers session.
The recommended place to define permanent, system-wide environment variables applying to all users is in:
/etc/environment
(which is where the default PATH is defined)
This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)
To edit, open the terminal and type:
sudoedit /etc/environment
(or open the file using sudo in your favorite text editor)
To make it work without rebooting, run . /etc/environment or source /etc/environment. Since this file is just a simple script it will run and assign the new path to the PATH environment variable. To check run env and see the PATH value in the listing.
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 ~/.profile file. Probably shouldn't do both however, as the path will be added twice to your PATH environment if you open a terminal.
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.
PATH=$PATH:/my/path/foo
export PATH
According to this thread it appears as though Ubuntu's behavior is slightly different than RedHat and clones.
Using ~/.profile to set $PATH
A path set in
.bash_profile
will only be set in a bash login shell (bash -l
). If you put your path in.profile
it will be available to your complete desktop session. That means even metacity will use it.For example
~/.profile
:Btw, you can check the PATH variable of a process by looking at its environment in
/proc/[pid]/environ
(replace [pid] with the number fromps axf
). E.g. usegrep -z "^PATH" /proc/[pid]/environ
Note:
bash
as a login shell doesn't parse.profile
if either.bash_profile
or.bash_login
exists. Fromman bash
:See the answers below for information about
.pam_environment
, or.bashrc
for interactive non-login shells, or set the value globally for all users by putting a script into/etc/profile.d/
or use/etc/X11/Xsession.d/
to affect the display managers session.Edit
.bashrc
in your home directory and add the following line:You will need to source your
.bashrc
or logout/login (or restart the terminal) for the changes to take effect. To source your.bashrc
, simply typeThe recommended place to define permanent, system-wide environment variables applying to all users is in:
(which is where the default
PATH
is defined)This will work in desktop or console, gnome-terminal or TTY, rain or shine ;)
To edit, open the terminal and type:
(or open the file using
sudo
in your favorite text editor)To make it work without rebooting, run
. /etc/environment
orsource /etc/environment
. Since this file is just a simple script it will run and assign the new path to thePATH
environment variable. To check runenv
and see thePATH
value in the listing.Related:
I think the canonical way in Ubuntu is:
create a new file under
/etc/profile.d/
add there:
and give it execute permission
For complete newbies (like I am) who are more comfortable with GUI:
$HOME
folder..profile
and click on Open With Text Editor.PATH="$PATH:/my/path/foo"
..profile
).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:
~/.pam_environment
file in home directory.PATH DEFAULT=${PATH}:~/android-sdk-linux/tools
.Put that line in your
~/.bashrc
file.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
~/.profile
file. Probably shouldn't do both however, as the path will be added twice to yourPATH
environment if you open a terminal.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.
To set it system wide, append the line
export PATH=/path/you're/adding:$PATH
to the end of/etc/profile
.To add the directory for only the logged-in user, append the same line to
~/.bash_profile
.In terminal,
cd
tothe_directory_you_want_to_add_in_the_path
This wasn't my idea. I found this way to export path at this blog here.