How can I reset $PATH to its default value in Ubuntu?

Solution 1:

The answer to your question is:

PATH=$(getconf PATH)

and works on any POSIX compliant system. The selected answer is the correct way to augment the path without obliterating prior existing content. If you use bash, you might consider:

PATH+=:$mynewdir

Solution 2:

You can find it on /etc/environment:

$ /usr/bin/cat /etc/environment

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

So, just source it:

$ source /etc/environment 
$ echo $PATH

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

Solution 3:

Adding :$PATH to the end of the export line fixed the problem e.g. export PATH=<directory to be added>:$PATH

I add this line to the ~/.bash_rc file instead of the ~/.profile file so I can see the effect immediately in a new terminal and for other reasons based on the information here: https://superuser.com/questions/176404/linux-bash-not-loading-profile-in-new-session

For me, the default output of echo $PATH before adding the new directory is:

/usr/lib/lightdm/lightdm:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

Solution 4:

The default path is

/home/_username_/bin:/usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games 

Hope this helps you