我使用的是 Ubuntu 12.04。
最近不小心删除了python
,导致大量的包被卸载。我重新安装了它们,但现在遇到了问题。
$ echo $PATH
/home/paul/bin:/usr/local/bin:/usr/bin:/bin:/usr/games:/home/paul/.rvm/bin
Run Code Online (Sandbox Code Playgroud)
请注意,没有/sbin
或/usr/local/sbin
!
我不知道那是怎么发生的!
因此,
$ sudo apt-get autoremove -y
...
dpkg: warning: 'ldconfig' not found in PATH or not executable
...
$ sudo shutdown now
sudo: shutdown: command not found.
Run Code Online (Sandbox Code Playgroud)
我去找找了 /etc/environment
(我没有碰过)有
$ cat /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games"
Run Code Online (Sandbox Code Playgroud)
我已经重新启动(几次)。为什么我的路径没有/sbin
?
更新
我尝试创建一个新用户
$ sudo adduser paul-test
$ su -- paul-test
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Run Code Online (Sandbox Code Playgroud)
还,
$ sudo su
$ echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
Run Code Online (Sandbox Code Playgroud)
所以有些东西/sbin
对我来说是致命的。
我查过了.bashrc
。
PATH=$PATH:$HOME/.rvm/bin # Add RVM to PATH for scripting
Run Code Online (Sandbox Code Playgroud)
和.profile
PATH="$HOME/bin:$PATH"
Run Code Online (Sandbox Code Playgroud)
没有~/.bash_profile
或~/.bash_login
。
供参考
他们治疗不工作的症状apt-get
,而不是纠正不工作的真正问题/sbin
。
PATH 可以设置为任何
~/.bashrc
~/.profile
~/.bash_profile
~/.bash_login
/etc/profile
/etc/environment
/etc/bash.bashrc
读取哪些内容取决于您正在运行的 bash 会话的类型。您想要做的是在所有这些文件中 grep 查找 PATH。
$ grep PATH ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_login \
/etc/profile /etc/environment /etc/bash.bashrc
Run Code Online (Sandbox Code Playgroud)
我有一个漂亮的小 bash 函数来解决这类问题:
grep_bash(){
for f in ~/.bashrc ~/.profile ~/.bash_profile ~/.bash_login \
/etc/profile /etc/environment /etc/bash.bashrc;
do
[ -e $f ] && grep -H "$@" $f;
done
}
Run Code Online (Sandbox Code Playgroud)
我有这个,.bashrc
所以每当发生奇怪的事情时,我都会用它在所有可能的配置文件中查找相关字符串。例如:
$ grep_bash PATH
Run Code Online (Sandbox Code Playgroud)
附带说明一下,在普通用户的 PATH 中没有/sbin
和是大多数发行版的标准做法。/usr/sbin
普通用户没有理由在其路径中包含这些目录。我刚刚检查了 Debian、Ubuntu Server 和 SuSe 机器,只有 Ubuntu 似乎添加/sbin
到普通用户的路径,并且它在/etc/environment
. 其他两个仅在用户是 root 时添加它。
归档时间: |
|
查看次数: |
14363 次 |
最近记录: |