How can I add a directory to my PATH?
Solution 1
If you're running apps outside the shell command line that will always run with your UID, you can create session-wide environment variables by adding them to ~/.pam_environment
, rather than .bash_aliases
.
If you're running apps outside the shell command line that will not always run with your UID, system-wide environment variables by adding them to /etc/environment
, rather than .bash_aliases
.
However: Creating system-wide environment variables will affect ALL users, including root. If the variable you set overwrites another, bad things will happen. Adding something onto the end of PATH
doesn't seem like it will cause any havoc, but seeing as you don't have root, you would need your sysadmin to do it for you, and s/he can probably advise you as to whether it is safe to add it. Whether s/he actually allows you to do this is something else entirely; anything user-related is best kept within the config files within their home folder, and it is not normally 'done' to have a users configuration affecting the whole system!
Solution 2
The PATH environment variable does not belong in ~/.bash_aliases; a better place is ~/.profile or ~/.pam_environment recently. If you put your path in ~/.profile, it will be available to X and the window managers that use X. Edit ~/.profile. Add to the end of that file:
PATH="$PATH:$HOME/opt/bin"
Maybe you are using Xubuntu? You may need to use ~/.bashrc instead. And ~/.pam_environment:
PATH DEFAULT=${PATH}:~/opt/bin
See help.ubuntu.com on Environment variables.
What does belong in ~/.bash_aliases are command aliases, like this:
alias l=ls
alias ll=ls -l
alias la=la -la
alias x=exit
alias b=my-insanely-long-command-i-never-want-to-type-again
Related videos on Youtube
ayr-ton
Updated on September 18, 2022Comments
-
ayr-ton almost 2 years
Possible Duplicate:
How to add a directory to my path?I created a
.bash_aliases
file with the following contents:PATH=$PATH:$HOME/opt/bin
So it adds
/home/myuser/opt/bin
to$PATH
. I made this because I don't have root access to this machine.When I run apps interactively through the shell command line, they can understand my custom PATH with no problems. But, if I open a app outside the shell command line, for example, choosing from the unity dash, the same apps can't see my custom PATH.
I tried putting
shopt -s expand_aliases
in my.bash_aliases
, but without success.How can I set a PATH for environments other than BASH?
-
ayr-ton over 11 yearsThank you for the Answer. I add the following to my ~/.pam_environment: "PATH DEFAULT=${PATH}:~/opt/bin" And I change the line 50 in /etc/pam.d/login for avoid duplicate my env like this: "session required pam_env.so readenv=1 user_readenv=0"