How to reset my $PATH environment variable back to default?
Solution 1
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')
andrew@athens:~$
And finally add any customisations made by yourself previously from the 2 backup files, by 'customisations' I mean such things as:
- 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
- Alterations to the default Terminal prompt
- Additions to the default aliases
And any other changes that have been made to the safe defaults of both files...
Solution 2
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.
Related videos on Youtube
A. Bergeron
BY DAY, I work in a kitchen. At night I like to tinker around with my computer, dreaming up all the games I could make...if only I had coding skills and the proper equipment and network. So here I am, trying to run a Linux, in order to force myself into learning more about how to run and maintain computers!
Updated on September 18, 2022Comments
-
A. Bergeron almost 2 years
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 EOF') 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:
/.cabal/bin:/opt/cabal/1.16/bin:/opt/ghc/7.6.3/bin:
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?-
edwinksl almost 8 yearsDid you change your
PATH
environment variable in~/.profile
or~/.bashrc
? -
Byte Commander almost 8 yearsPlease add the contents of
~/.bashrc
to your question. -
A. Bergeron almost 8 yearsbashrc, 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]
-
FredFoo almost 8 yearsIf you installed some packages also check /etc/profile.d for files that contain changes to the PATH variable - just grep for PATH.
-
steeldriver almost 8 yearsRemember you can always copy unmodified
~/.profile
and/or~/.bashrc
files from the/etc/skel
directory -
A. Bergeron almost 8 yearsThe contents of ~/.bashrc appears to be nothing. I'm still not sure how to check for changes to the PATH variable? It looks 100% correct within the /etc/environment directory as well as in the profile.
-
A. Bergeron almost 8 yearsThis is absurd, I don't even know how to enter these directories to see what they contain, nevermind copy their contents into other directories so I don't have PATH issues in my terminal.
-
edwinksl almost 8 years@A.Bergeron Calm down. The solution to your problem is straightforward.
-
A. Bergeron almost 8 yearsYou're right, I lose patience with learning way too fast. This wasn't even that big of an issue. I think the comments from andrew.46 and steeldriver have fixed the issue completely. LE SIGH!!! :)
-
andrew.46 almost 8 years@A.Bergeron Good to hear :). I have also installed ghc 7.10.3:
sudo apt-get install ghc
and I note that no changes are required in the$PATH
to get everything working. I see you have installed a more recent version to opt and this is where you have come unstuck as opt is not in the default$PATH
. -
A. Bergeron almost 8 yearsI'm trying to figure out how to make sure I've installed GHC correctly so I can layer Leksah, or another haskell-based IDE, on top of it. I'm very glad to be rid of the altered PATH, which I'm glad to hear is unnecessary. When I try to launch ghc in the terminal, it tells me there are no input files.
-
-
A. Bergeron almost 8 yearsOkay, 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...
-
A. Bergeron almost 8 yearsI 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!
-
A. Bergeron almost 8 yearsI 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.
-
WinEunuuchs2Unix almost 8 yearsI 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.
-
A. Bergeron almost 8 yearsTotally 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?
-
WinEunuuchs2Unix almost 8 yearsI 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.
-
A. Bergeron almost 8 yearsI 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.
-
WinEunuuchs2Unix almost 8 years@A.Bergeron Just read your profile that you want to write games after you graduate from the Kitchen and wanted you to know I didn't know this when I posted previous games messages. Just a coincidence. No Paranoia intentionally injected.
-
WinEunuuchs2Unix almost 8 yearsBSOD used to mean "Blue Screen of Death" in Windows but someone coined the new term "Black Screen of Death" after Unbuntu 16.04 was prematurely released without proper QA testing and many suffered that.
-
A. Bergeron almost 8 yearsI don't know how I'm going to get there though. I only just started to learn how to code for real this year! Paranoia runs in my family, so I'll just try to ignore your obviously sharp mind reading abilities as to my my sense of self. I'm totally not looking up defense tactics against telekinesis right now...really. I'm practicing code like a good student!
-
WinEunuuchs2Unix almost 8 yearsI learned how to code code in Assembler, COBOL, BACIC, RPG, FORTAN and later C 30 years ago but spent the last 20 years trying to forget it over paranoia. But as Brittany Spears or someone once joked just because you think you are paranoid doesn't mean people aren't staring at you.
-
A. Bergeron almost 8 yearsTried to forget out of paranoia? I don't understand. That's an impressive series of languages though!