Whenever I try basic commands in the terminal like sudo or ls, 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

When I type in echo $PATH, it returns

/Downloads/stata installation/stata15:/Downloads/stata

I suspect I messed up the $PATH variable when trying to install Stata.

I've tried export PATH="/usr/bin:$PATH" which fixes the problem temporarily (from this answer). Then when I do echo $PATH, it returns

/usr/bin:/Downloads/stata installation/stata15:/Downloads/stata

But this fix is temporary and when I restart the terminal, I can't use sudo again.

This other answer says that I can make a permanent fix:

First, I did export PATH=$PATH:/usr/bin, and which again fixes the problem temporarily. When I do echo $PATH, it returns

/Downloads/stata installation/stata15:/Downloads/stata:/usr/bin

Then I'm supposed to be able to make it permanent by editing the /etc/environment file with sudo nano /etc/environment and making sure that it is


When I open the /etc/environment file, it already has that exact path, so nothing is changed. So when I restart the terminal, basic commands like sudo still doesn't work and I have to do the temporary fix again.

I suspect that the /etc/environment file is not the issue and there is another file that I need to change. Do you happen to know how to fix it?

  • Thank you, it does look like this is the problem. At the bottom of the /home/$USER/.bashrc file I have export PATH=/Downloads/stata\ installation/stata:/usr/local/sbin:/usr/local/bin:/usr/s$ export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/$ export PATH=/Downloads/stata\ installation/stata15:/Downloads/stata installation/stata$ Should I reduce all 3 lines down to export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/$?
    – R. Siva
    Jul 28, 2019 at 21:53
  • That worked perfectly after I restarted the terminal. I deleted the part about Stata since I don't have it installed properly. Yes, please write a full answer and I will accept it. Thank you so much!
    – R. Siva
    Jul 28, 2019 at 22:10

1 Answer 1


How to permanently change $PATH variable?

A similar question has been answered before at How to add a directory to the PATH?

Where to make the change?

$PATH can be changed at various levels and for various situations. At the global level the $PATH is stored in /etc/environment. Changing this will alter the default $PATH set for all the users of the computer.

Personalized custom changes can be done in three places based on one's need.

  1. To change the path of all login sessions change the path at /home/$USER/.profile.
  2. To change the in bash shell sessions that are opened after login, such as the terminal window, change the path at /home/$USER/.bashrc.
  3. To change the in GUI sessions that may be opened after login, such as a remote GUI shell, change the path at /home/$USER/.xsessionrc.

How to make the change?

Typically you add a new PATH statement or an export command like:



export PATH="/path/to/dir:$PATH"

Note these statements use the $PATH variable on the right hand side. This specific way off adding a new directory to the $PATH adds the new directory at the beginning of the existing $PATH variable.

Specific Case in the Question

Look for the files mentioned above:

  • /etc/environment
  • /home/$USER/.profile
  • /home/$USER/.bashrc
  • /home/$USER/.xsessionrc

to find exactly where the $PATH was modified by the improper installation of the software Stata. In this case modifications where made in /home/$USER/.bashrc.

From the comments, three export statements were added to /home/$USER/.bashrc:

export PATH=/Downloads/stata\ installation/stata:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
export PATH=/Downloads/stata\ installation/stata15:/Downloads/stata installation/stata

The first export statement adds the /Downloads/stata\ installation/stata in the beginning of the default $PATH. The second export statement resets the $PATH to the default set for directories. The second export statement tries set the $PATH to some Stata directories but misses the escape character \ before the space and messes up the /Downloads/stata installation/stata as only /Downloads/stata

Since Stata is not installed in this computer you don't need any of these modifications. You can comment all the export statements as:

#export PATH=/Downloads/stata\ installation/stata:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
#export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games
#export PATH=/Downloads/stata\ installation/stata15:/Downloads/stata installation/stata

Note inserting the # in the beginning of each line marks them as comments. If everything works after commenting these export commands, you may delete them from the .bashrc file.

Commenting out or deleting these three lines will your bash session without these customization of $PATH variables. You will be using the defaults set in /etc/environment.

Hope this helps

  • 1
    Great answer! Thank you very much!
    – R. Siva
    Jul 29, 2019 at 20:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .