Ubuntu – How to log in after wrongly modifying path

environment-variablespathsprofile

I wanted to add a path so that the system could find some manually installed executable. However, instead of typing PATH=xxx:$PATH;export PATH at the end of ~/.profile where xxx is the directory in which the executable lies, I wrongly used PATH=xxx;export PATH.

After I logged out I was unable to log in the usual way. How can I fix this instead of reinstalling?

Best Answer

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

  • Related Question