Ubuntu – How to remove a path from system path(`$PATH`) using terminal commands

command line

I added a directory path to system path($PATH) by running,

export PATH=$PATH:/home/avinash/Desktop/raj

Now my path look like this,

$ echo $PATH
/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/home/avinash/Desktop/raj

I want to remove /home/avinash/Desktop/raj from system path variable by using command(like export command does on adding path).

Best Answer

Running export PATH=$PATH:/... doesn't set your PATH system-wide. It's just a shell variable. Start a new shell and BOOM, it's gone. Obviously if you've added that to ~/.bashrc (or another environment bootstrap file) you'll have to revert that change but it doesn't sound like your problem here.

If you're desperate not to start a new shell, you could set it by removing it manually, with:

export PATH=/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
Related Question