I just made a mistake when adding a directory to path, and executed

$ PATH=/path/to/my/directory/

instead of

$ PATH=/path/to/my/directory/:$PATH

Consequently, my $PATH variable now contains only my own directory, which is of course a problem. I don't know exactly what was in the path before, but if I can reset to factory default I can start from there and add things as I need them.

Is there an easy way to accomplish this?


If you can, just log out and relog in.

Otherwise, you can start with


and add missing entries.

| improve this answer | |
  • What about /bin? – Majenko Apr 27 '11 at 13:56
  • This only works assuming that the contents you describe are in fact the default PATH value for the OP's login shell; this might not be the case depending on his/her setup (especially if the OP is not the admin on the system and is using, for example, a login shell on an ISP-provided terminal account). – Viktor Haag Apr 27 '11 at 13:59
  • @Matt seems that (almost) everything already is in /usr/bin – slhck Apr 27 '11 at 14:00
  • @Matt, I trimmed /usr/games out of my path and cut one item too many. /bin is the fallback folder in tha path. Thx. I've corrected. @Viktor, Agreed, I actually assumed a standard Ubuntu 10.10 installation from the tag and the level of difficulty of the question. – Alain Pannetier Apr 27 '11 at 14:05

From the bash(1) man page:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

So, on your system, it's most likely that you just need to look at what the default PATH value is in /etc/profile, set that, and then build up based on what your own login/profile bash scripts do to PATH.

If you're not using bash(1) but some other shell, then use "man thatShellName" to find out what it's invocation behaviour is, and perform similar steps.

As a quick short-cut, in your current shell, (again, assuming you're using bash(1)), type "bash --login" to get a new, login shell process; then, save the value of path with

echo $PATH > /tmp/myPath.txt

then "exit" out of the login shell and type

export PATH=`cat /tmp/myPath.txt`

(note the use of back-ticks in that last expression).

Or if you're a terminal app that has copy/paste abilities, you can just "bash --login", and copy the PATH value to the clipboard, exit, and then "export PATH" and paste in the PATH value.

| improve this answer | |
  • I believe Ubuntu comes with PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games" inside /etc/environment. I probably need to check that however ;-). But I agree it's a more complex topic than it appears, with different circumstances having different answers. – Alain Pannetier Apr 27 '11 at 14:21
  • @Alain, yes, thanks very much for the clarification; I'm working with another *nix distribution here, so I tried to be as portable as possible. Every *nix installation seems to have a slightly different way of setting up login shell characteristics. Typically, using the man pages for the shell you're using is the best way to start, but not always because local distributions might not take the time to provide localized versions of the man pages. 8( – Viktor Haag Apr 27 '11 at 14:56

You could also create a new user and copy the $PATH entries from there.

Apart from that, on a Ubuntu server I found:

| improve this answer | |
  • Creating a new user would only work if the default shell for a new user is the same shell as the one the OP is using. Also, it has the overhead of creating a user, which the OP might not have permissions to do. – Viktor Haag Apr 27 '11 at 13:57
  • @Viktor, Agreed with all of this, but as there were no further informations given, I assumed a "normal" installation without modifications. – slhck Apr 27 '11 at 14:09

in terminal open the bashrc file

gedit ~/.bashrc

At the last line add

PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:$PATH export PATH

Then save the file.

To verify, open a new terminal and type:


| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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