I am a noobie. I tried searching the duplicates for answers, but none worked. I accidentally altered my $PATH variable in my terminal when trying to install ghc. Every time I open a terminal window I get:

bash: export: `/.cabal/bin:/opt/ghc/7.6.3/bin:': not a valid identifier
bash: warning: here-document at line 120 delimited by end-of-file (wanted 
Command 'cat' is available in '/bin/cat'
The command could not be located because '/bin' is not included in the 
PATH environment variable.
cat: command not found

When I type:

echo $PATH

it gives me the following:


I can fix it by typing:

source /etc/environment

But that's only for the current terminal session. If I close the window and open a new one, it goes back to the wrong $PATH.

How can I permanently reset my $PATH back to the default?

  • 4
    Did you change your PATH environment variable in ~/.profile or ~/.bashrc?
    – edwinksl
    Sep 21, 2016 at 0:40
  • 2
    Please add the contents of ~/.bashrc to your question.
    – Byte Commander
    Sep 21, 2016 at 0:46
  • bashrc, the instructions to set up ghc ended with the following: [CODE] cat >> ~/.bashrc <<EOF export PATH="\$HOME/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3 /bin:\$PATH" EOF export PATH=~/.cabal/bin:/opt/cabal/1.22/bin:/opt/ghc/7.10.3/bin:$PATH [/CODE] Sep 21, 2016 at 0:56
  • If you installed some packages also check /etc/profile.d for files that contain changes to the PATH variable - just grep for PATH.
    – FredFoo
    Sep 21, 2016 at 0:59
  • 2
    Remember you can always copy unmodified ~/.profile and/or ~/.bashrc files from the /etc/skel directory Sep 21, 2016 at 1:05

4 Answers 4


Building on the comments made by steeldriver try the following two simple steps:

1. Backup existing config:

mv -v ~/.bashrc ~/.bashrc_bak && mv -v ~/.profile  ~/.profile_bak

2. Create new, safe copies:

cp -v /etc/skel/{.bashrc,.profile} $HOME

Note: This can all be accomplished with a one-liner, demonstrated on my own system:

andrew@athens:~$ cp -v -S _bak /etc/skel/{.bashrc,.profile} $HOME
'/etc/skel/.bashrc' -> '/home/andrew/.bashrc' (backup: '/home/andrew/.bashrc_bak')
'/etc/skel/.profile' -> '/home/andrew/.profile' (backup: '/home/andrew/.profile_bak')

And finally add any customisations made by yourself previously from the 2 backup files, by 'customisations' I mean such things as:

  1. Alterations to the default $PATH made in these files, I note in your case you have installed to /opt which is not in the default $PATH
  2. Alterations to the default Terminal prompt
  3. Additions to the default aliases

And any other changes that have been made to the safe defaults of both files...

  • Okay, I did both of these commands...required extras? Now my Path seems to be set to the following: /home/smaccom_swivel/bin:/home/smaccom_swivel/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin. So it's fixed, right? It seems to be working, should I be worried about that? The previous bash export error message disappeared... Sep 21, 2016 at 1:27

There are a lot of options. You can give a look here.

Keep in mind that in the link I sent you they mainly suggest how to set the path in the current session.

However if you change the path to the suggested values in ~/.profile or ~/.bashrc (depending which one you modified) you should be fine.

  • I edited the PATH to the correct value in the bash profile, but that didn't solve the issue. But I'm sure it was a necessary fix to make, so I glad I did it. Thanks! The link was an interesting read, being that I'm a noobie. It's good to know that the PATH is so easily modifiable per individual sessions. Sep 21, 2016 at 1:33

I hope this is helpful:

rick@dell:~$ echo "$PATH"

I haven't changed my path (that I can recall) I notice "games" is in there but I don't play games so I assume it's a default. You might want to use this as a starting path to get you started on the right path, so to speak.

I'm using Ubuntu 16.04.

To add paths this link might be helpful: unix-linux-adding-path.

  • I do know the games part of the PATH is part of the default, I am running 16.04 as well. Echo $PATH has definitely helped me figure out whether or not I was on the right track with every attempt I've made, thanks! Sep 21, 2016 at 1:32
  • I don't understand the games reference in my path, the only ones I played were Mass Effect trilogy under Windows 7 in Origin. My Ubuntu 16.04 was converted from 14.04 and it's possible there were games 2 years ago I forgot about, because sometimes you download things on a whim and never really use them. Sep 21, 2016 at 1:42
  • Totally true with unused downloads. As far as the reference to the games directory, I think it's there simply so that you can reference anything in that directory without needing to write out the full PATH. You have immediate access to a far larger amount of your system that way, making the process of issuing commands to your system far more elegant and concise. Characteristics Windows consistently lacks in my experience. Maybe it was set up that way as a dis to corporate OS's? Sep 21, 2016 at 1:51
  • I just checked the /usr/games directory and there are games there like Majohong (sp?) that I've never played before. Ubuntu must install them by default and setup the path. Anyway reinstalling the path has got to be easier than reinstalling Ubuntu. Sep 21, 2016 at 2:25
  • I succeeded in resetting the PATH is definitely easier. MY OS is on an SSD, so I really don't want to reinstall my OS too many tiomes because of that. I was upset I had to do it to fix the black screen issue I was having after my first install. Sep 21, 2016 at 2:27

Follow these step to recover the PATH environment variable :

  • Delete the culprit file from /etc/profile.d/ (if any)
  • Delete the culprit line from /etc/profile or ~/.bashrc (if any)
  • Execute source /etc/environment to start reseting the path environment variable
  • Execute source /etc/profile followed by source /etc/profile.d/*
  • At last source ~/.bashrc

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.