Messed up my PATH environment variable and can't login to desktop
Solution 1
Perform below steps. It will solve your issue permanently.
Press Ctrl + Alt + F3
Enter your username.
Enter your password.
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
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.Press Ctrl + X (to save the file).
Press Y (to confirm save changes).
Press Enter to save (to confirm changes in the current file).
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.
Related videos on Youtube
So S
Updated on September 18, 2022Comments
-
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 likeexport 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 andecho $PATH
gives 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 over 5 yearscan 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 over 5 yearsYeah, of course. See above.
-
WinEunuuchs2Unix over 5 yearsTry this:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin:$PATH
and let me know if you can use the system normally. -
So S over 5 yearsThat helps. I'm now able to use commands like
ll
,nano
again. That's definitely going in the right direction. -
WinEunuuchs2Unix over 5 yearsCan you run
gedit
? -
So S over 5 years
gedit
leads toUnable to init server: Could not connect: Connection refused \n (gedit:2557): Gtk-WARNING **: ...: cannot open display:
-
WinEunuuchs2Unix over 5 yearsAre you logged into console / terminal mode then? ie not desktop GUI?
-
So S over 5 yearsLet us continue this discussion in chat.
-
joeytwiddle over 5 yearsSometimes when X cannot load my desktop, I find useful error messages in
~/.xsession-errors
-
-
So S over 5 yearsI 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 over 5 yearsOkay, 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 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 over 3 yearsWhat 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. Theexport PATH....
commands in your answer are identical. If you're modifying/etc/environment
, there's no need toexport
.