22

I have been using Ubuntu 12.04 for quite a while and have never had a problem come at me out of the blue like this. I'm trying to install python 3.2 on my Ubuntu system and every time I run the code to compile the python source, I get this error:

'Command 'sudo' is available in '/usr/bin/sudo'
The command could not be located because '/usr/bin' is not included in the PATH environment variable.
sudo: command not found'

I've also tried running gksudo command to view what my environment shows but I pretty much get the same error.

5 Answers5

40

As the error say, you should add /usr/bin directory to your PATH environment variable. To do this, run the following command in terminal:

export PATH=$PATH:/usr/bin

After you can use sudo, you can edit /etc/environment file to make the change permanent, so, run in terminal:

sudo nano /etc/environment

to edit the file. Make sure that the path is something like this:

PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

Save and close the file with Ctrl+X and press Y when you are asked.

See also: How to add a directory to the PATH?

Radu Rădeanu
  • 174,089
  • 51
  • 332
  • 407
14

I got the problem and fixed it by editing my .bashrc file

  1. Open up your .bashrc file using nano

    $ nano ~/.bashrc
    
  2. Add the following line to the .bashrc file

    export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:   /usr/local/games"
    
  3. Press Ctrl+X to save the file

  4. It will ask to chnage the file, press y and Enter.

You're done.

Melebius
  • 11,750
1

When you want to add a new value to the PATH system variable, you most likely add a new line to ~/.bashrc or ~/.bash_profile files.

For example, if you want to add /opt/netbeans/bin to PATH, you must add this line to the end of ~/.bashrc file:

export PATH=$PATH:/opt/netbeans/bin

Let's break this line down.

  • export PATH - Here we refer to the PATH variable
  • = - We want to assign it a new value using the = operator (The rest of the string is the value that will be stored in the PATH)
  • $PATH - We assign the variable PATH to the value that was in the variable before the current command
  • : - We add a separator for the new value
  • /opt/netbeans/bin - And add a new value to the PATH

You must see all of your refers to the PATH variable in the ~/.bashrc or ~/.bash_profile files and make sure that you expand -

export PATH=$PATH:/opt/netbeans/bin

and not overwrite like this -

export PATH=/opt/netbeans/bin

the PATH variable

You must make sure, in every reference to the PATH you use $PATH: and your additional value after it


If it doesn't work, you may do something like this:

  • Make sure, there is something like the next variable in /etc/environment file and it never redefined in this file:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
  • Add missing paths from the above PATH variable to your PATH variable located in the /etc/environment

Before testing after each change in files don't remember to update your configs.

For example for ~/.bashrc file:

source `~/.bashrc`
1

This is an old thread but I got here following the same problem. In my case I most likely accidently edited a line in the ~/.bashrc file. By fixing the following line to appear as in the picture it solved my problem: [1]: https://i.sstatic.net/V3vq0.png (mine had the ':' in the wrong place).

I don't think there is a need to add a line, just make sure the line with the PATH is correct(unless you also have your own scripts saved somewhere).

In order to get to the ~/.bashrc you can either use graphical methods (make sure to show hidden files) and go to the home folder. OR - use export PATH=$PATH:/usr/bin to enable some commands temporarily as was suggested here earlier, then open ~/.bashrc using

nano ~./bashrc
0

Your PATH variable has been messed up. You have to add /usr/bin in $PATH. To corect that,run the following command on the terminal.

export PATH="/usr/bin:$PATH

However the command above works only in the current session,when you log off and login bac you will land in the same error. Parmenently set PATH by running the following command

echo "PATH=/usr/bin:$PATH" >> ~/.bash_profile