Removing paths from the PATH environment variable

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:



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?

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.

grep -r '/home/keith/.bin:' /etc


grep -r '/home/keith/.local/bin:' /etc


grep -r '/home/keith/.bin:' /home/keith


grep -r '/home/keith/.local/bin:' /home/keith

FYI, the command is in the format
grep -r ‘pattern_to_match’ directory_to_search

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?