Ubuntu: Permanently Remove Item from `$PATH`



Question:

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


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.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »