Lets get this out of the way, I did something stupid. Yes, stupid. Very stupid. I am well aware of how stupid this is. I am embarrassed and I regret doing it. Please help. I was installing a program, while also watching TV, and somehow managed to remove /usr/bin from path. NOOOOOO.

I'm using ubuntu 16.04. I added the new program bin to path by typing:

sudo nano ~/.bashrc

The new path was added, but then I tried to update using sudo and I got this error:

The command could not be located because '/usr/bin' is not included in the PATH environment variable.

However, the bin still exists:

 Command 'sudo' is available in '/usr/bin/sudo'

nano in available, ls is available - its all available - but not in path. So, simply trying:

sudo nano ~/.bashrc

and trying to add /usr/bin to path is not an option. Without sudo I dont have permission to open bashrc. I can cd into /usr/bin, but I cant ls anything, and I have no idea how to access sudo or nano once I'm in there. ./sudo, sudo.sh ./sudo.sh all returns "command not found".

How do I add /usr/bin to path in the event I remove it?


I found the solution here: I think I accidently deleted the PATH variable

I replaced the PATH with the path of the program I added to my path. So, typing this into a terminal gave me access to sudo and nano again:

export PATH=$PATH:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
  • 1
    Try /usr/bin/sudo su.
    – N0rbert
    Oct 6, 2018 at 20:52
  • @N0rbert, I found the answer, please see my edit. I gotta turn the TV off is the real solution.
    – Phil_T
    Oct 6, 2018 at 20:56
  • 2
    FWIW you really shouldn't be using sudo to modify files in your own home directory Oct 6, 2018 at 21:45
  • @steeldriver, what is the preferred method for permanently adding variables to path?
    – Phil_T
    Oct 6, 2018 at 21:55
  • 1
    @Phil_T it's fine to modify ~/.bashrc ... just don't do so using sudo Oct 6, 2018 at 22:43

1 Answer 1


You can prefix the commands with the path:

/bin/nano ~/.bashrc

or (for files that need superuser privilege to edit)

/usr/bin/sudo nano /etc/bash.bashrc
  • Yeah, that works too. Thanks. My heart dropped for second when sudo stopped working.
    – Phil_T
    Oct 6, 2018 at 20:59
  • @N0rbert Sorry I didn't notice any comments when I started writing the answer. It could be we were writing at same time? Also since the user is owner of ~/.bashrc using sudo isn't necessary. Oct 6, 2018 at 21:03

Not the answer you're looking for? Browse other questions tagged or ask your own question.