Ubuntu – Messed up the PATH environment variable and can’t login to desktop

18.04environment-variablesgnome-session

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?

Best Answer

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.