Messed up my PATH environment variable and can't login to desktop

8,485

Solution 1

Perform below steps. It will solve your issue permanently.

  1. Press Ctrl + Alt + F3

  2. Enter your username.

  3. Enter your password.

  4. Run these commands.

    echo $PATH
    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/usr/games:/usr/local/games:/snap/bin"
    source ~/.bashrc 
    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/usr/games:/usr/local/games:/snap/bin"
    source ~/.profile
    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/usr/games:/usr/local/games:/snap/bin" 
    sudo nano /etc/environment
    
  5. It will open a file and keep only the first line PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin/usr/games:/usr/local/games:/snap/bin" and remove other path or environment variable if any.

  6. Press Ctrl + X (to save the file).

  7. Press Y (to confirm save changes).

  8. Press Enter to save (to confirm changes in the current file).

  9. Reboot with sudo reboot

Solution 2

Enter this command:

nano /etc/environment

Make the first line read:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:"

Press Ctrl+O to save the file.

Press Ctrl+X to exit.

Type reboot to restart your computer.

Share:
8,485

Related videos on Youtube

So S
Author by

So S

Updated on September 18, 2022

Comments

  • So S
    So S almost 2 years

    To get an maven environment variable to run, I tried several options. Basically, I followed some options from Ubuntu Community Page, such as ~/.pam_environment, /etc/bash.bashrc and I don't really know anymore. Within them I exported sth like export PATH=/opt/apache-maven-3.6.0/bin:$PATH (I'm being so unconcrete because I cannot look it up).

    Afterwards, I did run gnome-session-quit and my machine got stuck.

    So after hard restart I try to login again, but I'm not able to do that: I see my username, enter the password, hit enter, screen turns black and after 2 seconds I'm back at the login screen.

    So, that very strange and worrying. Next step: Login via tty (Strg + ALT + F3). Within there I can login, but can not do much. I thought about sth like removing .Xauthority file. But whatever I do: The command could not be located because '\bin' is not included in the PATH environment variable. I think, altogether thats alarming and I'm getting really nervous.

    Executing export PATH="/usr/bin:$PATH seems to work and echo $PATHgives an output starting with /usr/bin:/usr/bin:/usr/bin:/home/user/Documents/.../esper/examples/transaction/etc:/home/user/anaconda3/bin:/usr/lib/jvm/java-1.8.0-openjdk-amd64/bin:/opt/apache-maven-3.6.0/bin:/opt/apache-maven-3.6.0/bin:/opt/apache-maven-3.6.0/bin but does not really help.

    I'm running an Ubuntu 18.04 on an Lenovo G50-70.

    Can you help me accessing my desktop again and/or fixing my PATH issue?

    • WinEunuuchs2Unix
      WinEunuuchs2Unix over 5 years
      can you update your question with the output from echo $PATH? The snippet you provided is incomplete. Adding /usr/bin to the PATH a second time is futile.
    • So S
      So S over 5 years
      Yeah, of course. See above.
    • WinEunuuchs2Unix
      WinEunuuchs2Unix over 5 years
      Try this: PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin‌​:/bin:/usr/games:/us‌​r/local/games:/snap/‌​bin:$PATH and let me know if you can use the system normally.
    • So S
      So S over 5 years
      That helps. I'm now able to use commands like ll, nano again. That's definitely going in the right direction.
    • WinEunuuchs2Unix
      WinEunuuchs2Unix over 5 years
      Can you run gedit?
    • So S
      So S over 5 years
      geditleads to Unable to init server: Could not connect: Connection refused \n (gedit:2557): Gtk-WARNING **: ...: cannot open display:
    • WinEunuuchs2Unix
      WinEunuuchs2Unix over 5 years
      Are you logged into console / terminal mode then? ie not desktop GUI?
    • So S
      So S over 5 years
    • joeytwiddle
      joeytwiddle over 5 years
      Sometimes when X cannot load my desktop, I find useful error messages in ~/.xsession-errors
  • So S
    So S over 5 years
    I tried this approach. Nevertheless, after reboot I got the same problem. Therefore, I logged in via tty again. Within there I had to run PATH=/usr/... again, to be able to use the terminal. The changes made to /etc/environment are still there.
  • So S
    So S over 5 years
    Okay, I think I fixed the problem. Therefore, I did two things: Removing all previously made changes to any file that stores environment variables. Then I was able to login again ;). During login a message popped up pointing to an error in my /home/user/.profile. Within there I must have somehow uncommented the first line, whích caused the error. Thank you very much @WinEunuuchs2Unic, you have been very helpful at solving this issue!
  • WinEunuuchs2Unix
    WinEunuuchs2Unix over 5 years
    @SoS You're most welcome. I actually screwed up my own /etc/environment during this exercise but was able to rebuild it from our message history. Just now I added it to my daily backup though :)
  • Kulfy
    Kulfy over 3 years
    What is the point of re-sourcing .bashrc and .profile even when no modifications were made? export sets the environment variable for current shell which on termination/closure of shell would vanish. The export PATH.... commands in your answer are identical. If you're modifying /etc/environment, there's no need to export.