How to log in after wrongly modifying path

In addition to @João Pinto's answer, you cannot use text editors like gedit or Kate. For the terminal or console, use text-based editors like nano.

The full steps needed to make changes to the ~/.profile file:

  1. Press Ctrl + Alt + F1 to switch to a text console
  2. Login with your username or password
  3. Restore your $PATH variable by restoring the environment so you can run nano without specifying the full path:

    . /etc/environment
    
  4. Edit the ~/.profile file by running:

    nano ~/.profile
    

    Use Arrow keys, Page up or Page down to move the cursor. As with text editors like Kate, you can use Backspace or Delete to delete text before or after the cursor and insert text by typing it.

  5. After making the changes, save the changes and quit the nano editor by pressing Ctrl + X, followed by Y to answer yes on saving changes. Finally, press Enter to confirm the filename.
  6. You can now logout from the console by pressing Ctrl + D (or by executing exit)
  7. Switch back to the graphical login by pressing Ctrl + Alt + F7 or Ctrl + Alt + F8 if F7 did not work.

If this does not work out-of-the-box for whatever reason, then we can always revert to karthick87's answer which Jasper added as an answer below: using a LiveCD to make changes.


Changing the profile with PATH=xxx;export PATH will not prevent you from loggin in, at least not from the console. Switch to the text console with: CTL-ALT-F1, login, edit the file with your prefered text editor.


Boot from a live CD and open your filesystem from Nautilus (not file system of live session). Search for the home directory, use Ctrl+H to view hidden files and then edit ~/.profile. After that remove the live CD and log in as usual.

This is essentially karthick87's comment but I could not get him to add his comment as an answer, so I am putting this answer down for other users.


To recover from this issue due to messed up values in /etc/environment follow the below steps.

  1. export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"

  2. remove the contents you added earlier in /etc/environment file as a root user.

Now everything will work fine. I had the same issue and recovered using the above steps.