My path has a lot of entries that were added long ago by scripts. They are not in my .bashrc
, .bash_profile
, or .bash_login
.
I'm worried that resetting my path in .bashrc
will have undesirable long-term results. Is there a way to find where things have been added to my path and remove them manually? Are things always added by file or is path cached somewhere? If the latter, is it easy to clean that up?
The easiest way to find who modified your PATH is to run:
$ bash --login -i -xv 2>&1 | grep ' \. '
For example I got:
+ . /etc/profile.d/bash_completion.sh . /etc/bash_completion ++ . /etc/bash_completion +++ . /etc/bash_completion.d/abook +++ . /etc/bash_completion.d/ant + . /etc/profile.d/lapack0.sh + . /etc/profile.d/openssl.sh + . /etc/profile.d/qt3-devel.sh + . /etc/profile.d/tetex-profile.sh + . /etc/profile.d/xinit.sh + . /etc/bash.bashrc
...
You shouldn't let some random sysadmin decide what's in your PATH anyway, you should set it to the PATH you need. You begin with
# POSIX way of getting the system's PATH to POSIX tools:
PATH=$(getconf PATH) # Or /usr/bin/getconf PATH.
followed by whatever you require in addition, e.g.
PATH="$PATH:/usr/local/bin"
PATH="$PATH:/usr/local/sbin"
PATH="$PATH:$HOME/bin"
and put this in your shell's .profile
or equivalent. Note that you do not want .
or world-writable directories in your PATH for security reasons.
You're always at liberty to look at the directory contents for each component of $PATH
and decide whether you use the programs therein. If you don't use the programs, the chances are, you won't be hurt by removing the directory from $PATH. If the directory doesn't exist, then you can completely safely remove it.
It is puzzling that the directories show up in your profile and related files. You should check for ~/.profile
too. You should also look at material like /etc/profile
.
Personally, I consider I am in charge of my PATH. I set it from scratch according to my rules, picking the directories I need. You're not obliged to accept what the system admins set for you, though you should not idly remove PATH components that they've added. But their views on what's desirable may be different from yours.
The only long-term undesirable effect might be that some program you use stops working because it relied on something from the old version of $PATH. So, keep a record of what you had before you started messing with PATH - but don't be afraid to adjust PATH to suit yourself.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With