How to reset my $PATH environment variable back to default?

29,075

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:

  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...

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.

Share:
29,075

Related videos on Youtube

A. Bergeron
Author by

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, 2022

Comments

  • A. Bergeron
    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
      edwinksl almost 8 years
      Did you change your PATH environment variable in ~/.profile or ~/.bashrc?
    • Byte Commander
      Byte Commander almost 8 years
      Please add the contents of ~/.bashrc to your question.
    • A. Bergeron
      A. Bergeron almost 8 years
      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:$P‌​ATH [/CODE]
    • FredFoo
      FredFoo almost 8 years
      If you installed some packages also check /etc/profile.d for files that contain changes to the PATH variable - just grep for PATH.
    • steeldriver
      steeldriver almost 8 years
      Remember you can always copy unmodified ~/.profile and/or ~/.bashrc files from the /etc/skel directory
    • A. Bergeron
      A. Bergeron almost 8 years
      The 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
      A. Bergeron almost 8 years
      This 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
      edwinksl almost 8 years
      @A.Bergeron Calm down. The solution to your problem is straightforward.
    • A. Bergeron
      A. Bergeron almost 8 years
      You'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
      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
      A. Bergeron almost 8 years
      I'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
    A. Bergeron almost 8 years
    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:/us‌​r/local/sbin:/usr/lo‌​cal/bin:/usr/sbin:/u‌​sr/bin:/sbin:/bin:/u‌​sr/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
    A. Bergeron almost 8 years
    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!
  • A. Bergeron
    A. Bergeron almost 8 years
    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.
  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 8 years
    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.
  • A. Bergeron
    A. Bergeron almost 8 years
    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?
  • WinEunuuchs2Unix
    WinEunuuchs2Unix almost 8 years
    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.
  • A. Bergeron
    A. Bergeron almost 8 years
    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.
  • WinEunuuchs2Unix
    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
    WinEunuuchs2Unix almost 8 years
    BSOD 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
    A. Bergeron almost 8 years
    I 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
    WinEunuuchs2Unix almost 8 years
    I 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
    A. Bergeron almost 8 years
    Tried to forget out of paranoia? I don't understand. That's an impressive series of languages though!