Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I accidentally unset all the directories of $PATH while trying to add a new one in ~/.bashrc. I opened a new terminal window as I was editing and now $PATH is empty. I'm worried if I boot from another drive to find the $PATH I won't be able to boot into this drive again.

Basically, what is the default result of echo $PATH?

share|improve this question
Comment out or fix that export line and you should e good to go. – bodhi.zazen Mar 16 '12 at 5:28
~/.bashrc is the wrong place to set environment variables though. You should do that in ~/.profile instead. – geirha Mar 16 '12 at 6:38
Yes I figured it out. PATH is still fine in the other terminal window that was open before the new one, so just fixing the export line by adding :$PATH at the end restored the PATH. And yes in ~/.profile there is code to "set PATH so it includes user's private bin if it exists" i.e. $HOME/bin – Cee Mar 16 '12 at 8:24

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:


share|improve this answer
I had trouble using a lot of commands (sed: No such file or directory type of trouble) after accidentally setting my PATH to nothing during a very long running process (i.e., I couldn't restart). I couldn't use getconf. To reset my path, I used $(export $(cat /etc/environment)":/usr/bin/additional:/usr/bin/paths"). For the curious: /etc/environment is where the PATH variable is initially set in many Linux flavours. – Nick Bull Aug 18 '15 at 14:28
That working would surprise me. Perhaps "export" without the surrounding "$(...)" stuff might, but it will be whatever happens to be there. Use "source /etc/..". Anyway, try "/usr/bin/getconf" if you cannot even find "getconf". – Bruce Aug 31 '15 at 21:56
Prefer your final idea using the full path a lot more than mine in hindsight! Thanks for the reply – Nick Bull Sep 1 '15 at 9:05
up vote 1 down vote accepted

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:

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


share|improve this answer

The default path is


Hope this helps you

share|improve this answer
That differs from my default PATH. See below. – Cee Mar 16 '12 at 16:24

You can find it on /etc/environment:

$ cat /etc/environment


So, just source it:

$ source /etc/environment 
$ echo $PATH

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.