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 
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值