Bug修复:dpkg cannot find ldconfig/start-stop-daemon

Debian或者Ubuntu操作系统下,安装软件时,出现如下报错

Preconfiguring packages ...
dpkg: warning: 'ldconfig' not found in PATH or not executable.
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.
dpkg: error: 2 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)
PS:简单来说,解决办法就是:在用户~/.bash_rc中,PATH路径设置一下即可 或者 在/ect/sudoers设置sudo的安全路径即可

问题重点:

dpkg: warning: 'ldconfig' not found in PATH or not executable.
dpkg: warning: 'start-stop-daemon' not found in PATH or not executable.
These errors have been reported several times by Debian and Ubuntu
users (you can actually Google them for more information). It seems
like the PATH variable isn't correctly set when the user tries to
execute a command through sudo, which is probably what you are trying
to do.

这里有三种解决方案:

Solution 1: 设置 sudo 默认安全路径
Open /etc/sudoers by running visudo in your terminal, and make sure the file includes the following line:

Defaults env_reset
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"

Solution 2: 直接使用root账户,记住使用root账户,/root/.bashrc中的PATH设置为

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

不要使用sudo,只需切换root到运行命令。运行以下命令之一来执行此操作:

$ sudo -i
$ su 

以root身份登录后,只需apt-get再次运行命令:

# apt-get ...

您可能必须首先设置root PATH。编辑/root/.bashrc(当然使用root权限),并添加以下行:

export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

Solution 3: 在执行sudo时,传递PATH变量给sudo。

只需在sudo调用前加上PATH变量的重新定义:

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

你可能感兴趣的:(debian,unix,ubuntu)