Author Topic: Removing paths from the PATH environment variable  (Read 353 times)

0 Members and 1 Guest are viewing this topic.

Offline Keith

  • Hero Member
  • *****
  • Posts: 861
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Removing paths from the PATH environment variable
« on: September 09, 2018, 09:29:11 pm »
Lenovo Thinkpad T500 running Ubuntu 16.04

Many years ago I managed to add two local directories to the PATH variable and I’ve just noticed that these directories are present twice, at the beginning.  Here is $PATH listed to make it easier to read:

/home/keith/.bin:
/home/keith/.local/bin:
/home/keith/.bin:
/home/keith/.local/bin:

/usr/local/sbin:
/usr/local/bin:
/usr/sbin:
/usr/bin:
/sbin:
/bin:
/usr/games:
/usr/local/games:
/snap/bin

The local directories are not set in .bashrc or /etc/profile so I must have defined the PATH variable directly, in a rather permanent fashion. 
I think it would be safest to remove these local paths (and duplicates) and redefine them in .bashrc using “export PATH=/home/keith/.bin:$PATH” for example.  But how can I remove the offending paths safely from the existing, permanent PATH variable? 



Online Mark Greaves (PCNetSpec)

  • Administrator
  • Hero Member
  • *****
  • Posts: 17934
  • Karma: 461
  • Gender: Male
  • "-rw-rw-rw-" .. The Number Of The Beast
    • View Profile
    • PCNetSpec
    • Awards
Re: Removing paths from the PATH environment variable
« Reply #1 on: September 09, 2018, 10:24:05 pm »
Why don't you try searching /etc and /home/keith for files that contain the strings "/home/keith/.bin:" and "/home/keith/.local/bin:" to try discover where you put them.
Code: [Select]
grep -r '/home/keith/.bin:' /etc
and
Code: [Select]
grep -r '/home/keith/.local/bin:' /etc
and
Code: [Select]
grep -r '/home/keith/.bin:' /home/keith
and
Code: [Select]
grep -r '/home/keith/.local/bin:' /home/keith
FYI, the command is in the format
grep -r 'pattern_to_match' directory_to_search
« Last Edit: September 10, 2018, 01:45:36 am by Mark Greaves (PCNetSpec) »
WARNING: You are logged into reality as 'root'
logging in as 'insane' is the only safe option.
pcnetspec.co.uk

Offline Keith

  • Hero Member
  • *****
  • Posts: 861
  • Karma: 11
  • Gender: Male
  • Linux Novice
    • View Profile
    • Awards
Re: Removing paths from the PATH environment variable
« Reply #2 on: September 09, 2018, 10:55:03 pm »
I've used grep often in a pipe as part of other commands, but didn't realise one could do a global search like this.  Very useful!

But nothing was revealed with any of these commands. 
I seem to remember, when I first discovered Linux, messing with the PATH variable directly and getting into a bit of a mess.  Perhaps I edited it somewhere.  Anyway;  it seems that I haven't put the local paths in anywhere like .bashrc.  So the task now is to remove them from $PATH.  Can you advise me on how to do that? 


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal