我的 PATH 变量有问题:
每次我运行像 pip、bash、mkdir 这样的命令时
例如
The command could not be located because '/bin' is not included in the PATH environment variable.
bash: command not found
其他例子:
dpkg: warning: 'sh' not found in PATH or not executable
dpkg: warning: 'rm' not found in PATH or not executable
dpkg: warning: 'tar' not found in PATH or not executable
dpkg: warning: 'ldconfig' not found in PATH or not executable
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable
dpkg: error: 5 expected programs not found in PATH or not executable
Note: root's PATH should usually contain /usr/local/sbin, /usr/sbin and /sbin
E: Sub-process /usr/bin/dpkg returned an error code (2)
这个命令能解决问题吗?
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
每次我都需要运行此命令,如何解决?
此命令:
/bin/grep PATH ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_login /etc/profile /etc/bash.bashrc /etc/environment
返回:
/root/.bashrc:export PATH="/root/anaconda3/bin"
/bin/grep: /root/.bash_profile: No such file or directory
/bin/grep: /root/.bash_login: No such file or directory
/etc/environment:PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
答案1
问题出在/root/.bashrc
,特别是这一行:
export PATH="/root/anaconda3/bin"
首先,你为什么要把 anaconda 添加到 root 的 PATH 中?你真的不想使用 root 作为主用户!无论如何,那行并不添加 /root/anaconda3/bin
到 root 的 PATH,它取代PATH 中只包含/root/anaconda3/bin
,没有其他内容。因此,root 可以运行的唯一命令是 中的命令/root/anaconda/bin
。您大概想要做的就是添加它。因此,将上面的行更改为:
export PATH="$PATH:/root/anaconda3/bin"
由于您的 PATH 目前已混乱,因此您需要使用相关命令的完整路径。例如,要使用以下命令打开文件nano
:
/bin/nano /root/.bashrc
或者,如果您实际上并未以 root 身份登录(您不应该这样做):
/usr/bin/sudo /bin/nano /root/.bashrc
然后更正该行,打开一个新终端(或注销并重新登录),一切都应该再次正常工作。