Messed up PATH environment variable in Ubuntu 16.0

2019-03-04 01:40发布

I tried installing Anaconda to get many python packages at once but had some issues with python IDLE where it said No package found so had to manually set the path in ~/.bashrc.

Once I set the path in ~/.bashrc the IMPORT ERROR in python IDLE was solved but I'm unable to use commands on terminal now.

I'm getting this error all the time.

sid@sids-ubuntu:~$ ls
Command 'ls' is available in '/bin/ls'
The command could not be located because '/bin' is not included in the PATH environment variable.
ls: command not found
sid@sids-ubuntu:~$ sudo
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
sid@sids-ubuntu:~$ mkdir aa
Command 'mkdir' is available in '/bin/mkdir'
The command could not be located because '/bin' is not included in the PATH environment variable.
mkdir: command not found

I did export PATH=/usr/bin:/bin to find out my $PATH and content of /etc/environment. It seems both are different.

sid@sids-ubuntu:~$ export PATH=/usr/bin:/bin
sid@sids-ubuntu:~$ echo $PATH
/usr/bin:/bin
sid@sids-ubuntu:~$ cat /etc/environment 
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"

Doesn't Ubuntu look for $PATH in /etc/environment? If yes, what could be the reason my $PATH is different from /etc/environment? and please help me fix it! If not, where does Ubuntu look for $PATH? please help me fix it!

3条回答
Bombasti
2楼-- · 2019-03-04 01:49

When adding some directory to PATH it's good idea not to overwrite previous value, just append desired directory (e.g. $HOME/bin), in your ~/.bashrc add at the end line (and remove any previous tampering with PATH)

export PATH="$PATH:$HOME/bin"

and run:

source ~/.bashrc

(or just open new session of terminal).

查看更多
狗以群分
3楼-- · 2019-03-04 02:03

Be aware that your /etc/environment is only re-read at reboot.

When you want to change your path, be sure to include the existing part as well. To do that, add $PATH in the new path definition.

export PATH="$PATH:/usr/bin"

Looking at your problems, adding the $PATH in your ~/.bashrc should do the trick. If not, open a new terminal and show us the output of

echo $PATH
查看更多
We Are One
4楼-- · 2019-03-04 02:07

PATH is an environment variable, and therefore it is not looked up in any file.

There are several files which are sourced when bash is invoked (see the section named INVOCATION in the bash man page), and while sourcing these files, the environment variable PATH can be set, respectively manipulated. Note that .bashrc is not always processed; please read the bash man-page carefully to understand, which files are included under which condition.

查看更多
登录 后发表回答