Reputation: 1048
I have a program, let's call it exampleProg, in my /opt directory, and I want to run it from any directory, rather than just:
/opt/radFolder/exampleProg
This should be a simple task, I've done it several times before on different computers. I've searched around, and found instructions ranging from:
with PATH="$HOME/bin:$PATH:/opt/radFolder/:"
or just adding the /opt/radFolder
bit.
Yet none of them seem to work. The problem that I'm running into is that there doesn't seem to be a yet there doesn't seem to be a universally agreed-upon solution. I've tried so many that I think one of my changes has prevented the appropriate one from taking effect. Would someone help me put this to rest once and for all? Many thanks in advance.
I'm running ubuntu 14.04 LTS x64.
Upvotes: 0
Views: 299
Reputation: 11567
First, understand that writing things to those files does not mean everything is instantaneously, and globally, changed. In fact, nothing is changed until the file is sourced (via .
or source
), and even then, the environment changes apply only to the current shell (and subsequent created children, if export
is used).
INVOCATION, near the top of man bash
, spells out which files are automatically sourced when. To summarize:
~/.bashrc
is read for new non-login, interactive shells, e.g., when you open a GUI terminal. On many systems, this file by default in turn sources /etc/bashrc
.
/etc/profile
, ~/.bash_profile
, and ~/.profile
are read by interactive login shells.
Adding to ~/.bashrc
should be effective, but it will only work for subsequently invoked, interactive, non-login shells (and their children, if $PATH
is exported). However, since it's prone to being sourced repeatedly, using it to add to an existing variable (as with $PATH
) can produce repeated concatenations (see here).
An issue with the second category, .profile
, is that if you use a GUI login, the display manager may not source it, but it logs you in, meaning, you never invoke a login shell and hence none of those is ever sourced. If this is the case, sourcing them from ~/.xsession
should work (this has a system wide correlate in /etc/X11
).
Upvotes: 1