Permanently Remove Item from `$PATH`
Solution 1
The PATH is set up in /etc/environment
file, but if you want to remove some items from it, better to do this in your ~/.bashrc
file. So, if you want to remove /usr/games
and /usr/local/games
directories, set up again the PATH like this:
PATH="/home/blaine/.rvm/gems/ruby-2.0.0-p247/bin:/home/blaine/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/blaine/.rvm/rubies/ruby-2.0.0-p247/bin:/home/blaine/.rvm/bin:/home/blaine/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
Solution 2
Changes to ~/.bashrc
will apply to every new shell.
Edit ~/.bashrc
and add these two lines:
PATH=${PATH/":/usr/games"/""}
PATH=${PATH/":/usr/local/games"/""}
Explanation:
${variable/find/replacement}
In an expression of this kind, the /
separates the variable, the string to find, and the string to use as a replacement. In the actual application the UNIX path separator /
would be interpreted so it is necessary to quote the string ":/usr/games"
to make a literal. The "" is the empty replacement.
Related videos on Youtube
blaineh
Updated on September 18, 2022Comments
-
blaineh over 1 year
I've dug around forums trying to find a way to get rid of some default items in my path, but to no avail. Here is what it gives right now:
/home/blaine/.rvm/gems/ruby-2.0.0-p247/bin:/home/blaine/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/blaine/.rvm/rubies/ruby-2.0.0-p247/bin:/home/blaine/.rvm/bin:/home/blaine/bin:/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
And the offending items are the the two with
games
in them::/usr/games:/usr/local/games
neither of which I use, but that really isn't the core of my question. I want to get rid of these items (and to know how to do similarly in the future), but I can't find where these defaults are being set. There's no mention of
PATH
when I grep these files:/etc/profile /etc/profile.d/* ~/.bashrc ~/.bash_profile
I'm using Ubuntu 13.04
-
H2ONaCl over 8 yearsThey are offending items alright. When Ubuntu installs they should prompt "do you play games?", "do you need folders for pictures and video?" and the answer can be provided by one of two clickables "yes" and "of course not! why on earth?".
-
-
blaineh over 10 yearsI worry about that hard overwrite solution. I feel like that will mess with the system in some difficult to predict way?
-
blaineh over 10 yearsWill changing the
/etc/environment
file mess with the system? -
Radu Rădeanu over 10 years@Blaine Depending on how you edit it, yes, it will affect your system. For this I told you that if you want to change your PATH, set it up in your
~/.bashrc
file. Simple! -
Braiam over 10 years@blaineh also, the change in
/etc/environment
are system wide. If you don't want to mess up with them you better use the~/.bashrc
or~/.profile
. -
Flandraco about 4 yearsWith a bit of syntactic sugar (dropping the replacement for the pattern), this becomes:
PATH=${PATH/':/usr/games'/}
PATH=${PATH/':/usr/local/games'/}