My Linux terminal config files (.bash_profile, .profile, .bashrc) expand $PATH by prepending some custom directories. This only happens once (and I've also included some ENV vairiable based guards to enforce that it can only ever happen once). My .bash_profile
also sources the .rvm script (~/.rvm/scripts/rvm
) which prepends its own custom dirs. These RVM dirs must be first.
Everything's OK as long as I'm in a clean bash session.
If I run tmux
, however, the directory entries from my config files get prepended to PATH doubly (regardless of my ENV variable guards). It seems that tmux has two environments for ENV variables which it then merges.
This is a problem, since entries prepended by the .rvm script get only prepended once, and in the tmux scenario they don't end up first.
How can I prevent this from happening?
Edit—additional info:
All my PATH additions get prepended in .profile
, which I include from .bash_profile
(. ~/.profile
). All my GUI terminals are run "as a login shell".
In each config file, I use guards of the following form to prevent double inclusion:
if [ "$PROFILE_SOURCED" != "true" ]; then
export PROFILE_SOURCED=true
...
fi
By prepending an entry to PATH, I mean export PATH=entry:$PATH
.
Best Answer
Solved by the following:
Placed a guard around my PATH manipulation code in
.profile
Removed file-level guards around
.bash_profile
and.bashrc
IMPORTANT: RESTARTED the
tmux
server. (killall tmux
) -- the manual indicates the server maintains its own environment, which it inherits from its parent shell. If config files change,tmux
needs to start afresh.