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

本文解决Debian和Ubuntu系统下dpkg遇到的警告和错误,提供三种有效方案,包括设置sudo默认安全路径、使用root账户及正确配置PATH环境变量。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 默认安全路径

编辑 /etc/sudoers by running vim /ect/sudoers in your terminal, 保证/ect/sudoers更新为下面:

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 sudo apt-get

就是执行sudo命令前,加上PATH=/usr/local/sbin ... 一堆环境变量路径

<think>我们正在查找两个交叉编译工具链的路径:arm-linux-gnueabihf-gcc 和 arm-none-eabi-gcc。 根据用户提供的命令输出,我们可以总结如下: 1. 对于 arm-linux-gnueabihf-gcc: 用户尝试了以下命令: pkg -L gcc-arm-linux-gnueabihf 2>/dev/null | grep bin/ -> 无输出 dpkg -L gcc-arm-linux-gnueabihf 2>/dev/null | grep bin/ -> 无输出 然后使用find命令查找,找到了一些gcc,但并没有直接找到名为arm-linux-gnueabihf-gcc的可执行文件。 最后使用which命令也没有找到。 2. 对于 arm-none-eabi-gcc: 用户尝试了: dpkg -L gcc-arm-none-eabi 2>/dev/null | grep bin/ -> 无输出 然后使用find命令找到了一些路径,其中包含arm-none-eabi-gcc: /opt/st/stm32mp1/3.1-openstlinux-5.4-dunfell-mp1-20-06-24/sysroots/x86_64-ostl_sdk-linux/usr/share/gcc-arm-none-eabi/bin/arm-none-eabi-gcc /opt/st/fsmp1a/3.1-snapshot/sysroots/x86_64-ostl_sdk-linux/usr/share/gcc-arm-none-eabi/bin/arm-none-eabi-gcc 另外,在用户下载目录中也有一个旧版本(gcc-4.6.4)的交叉编译器,其中包含arm-none-linux-gnueabi-gcc,但不是arm-none-eabi-gcc。 最后使用which命令也没有找到,说明这些路径可能不在环境变量PATH中。 根据引用[3]和[4],我们可以知道,如果工具链是通过解压安装包手动安装的,那么需要将其bin目录添加到PATH环境变量中。 因此,我们可以通过以下步骤来查找: 1. 使用dpkg查询包安装的文件(如果通过apt安装): 对于arm-linux-gnueabihf-gcc: dpkg -L gcc-arm-linux-gnueabihf | grep bin/arm-linux-gnueabihf-gcc 对于arm-none-eabi-gcc: dpkg -L gcc-arm-none-eabi | grep bin/arm-none-eabi-gcc 2. 如果dpkg没有找到,那么可能是手动安装的,我们可以使用find命令在常见目录中搜索: find /usr /opt ~/ -name arm-linux-gnueabihf-gcc 2>/dev/null find /usr /opt ~/ -name arm-none-eabi-gcc 2>/dev/null 注意:用户之前已经运行过类似的find命令(但搜索的是*-gcc),我们现在直接搜索具体的可执行文件名。 3. 如果找到路径,但which命令找不到,说明该路径不在PATH环境变量中,需要手动添加(如引用[3][^3]和引用[4][^4]所述)。 另外,引用[1][^1]提到,如果系统是64位的,而安装的交叉编译器是32位的,则需要安装32位运行库(如lib32z1等)。 现在,我们根据用户之前的操作,重新整理查找方法: 步骤1:使用dpkg查询(如果通过apt安装) 步骤2:使用find命令在特定目录查找 步骤3:如果找到,验证其是否可执行(可能需要32位库) 由于用户之前运行过find命令,并且找到了一些gcc,但没有直接列出arm-linux-gnueabihf-gcc,所以可能没有安装这个工具链,或者安装的位置不在标准路径。 我们重点查找arm-none-eabi-gcc,因为用户已经通过find命令找到了几个,只是没有在PATH中。 因此,我们可以这样回答:</think>### 如何查找 Ubuntu 中 ARM 交叉编译工具链的安装路径 #### 一、查找 `arm-linux-gnueabihf-gcc` 路径 1. **通过包管理器查询** ```bash dpkg -L gcc-arm-linux-gnueabihf 2>/dev/null | grep -E "bin/arm-linux-gnueabihf-gcc$" ``` - 若通过 `apt` 安装,典型路径为:`/usr/bin/arm-linux-gnueabihf-gcc`[^2] 2. **全盘搜索** ```bash sudo find / -name "arm-linux-gnueabihf-gcc" 2>/dev/null ``` 常见位置: - 系统目录:`/usr/bin/` - 手动安装:`/opt/gcc-arm-*/bin/` 或 `~/toolchains/arm-linux-gnueabihf/bin/` - ST官方SDK:`/opt/st/stm32*/sysroots/*/usr/bin/arm-*-linux-gnueabihf-gcc` --- #### 二、查找 `arm-none-eabi-gcc` 路径 1. **通过包管理器查询** ```bash dpkg -L gcc-arm-none-eabi 2>/dev/null | grep -E "bin/arm-none-eabi-gcc$" ``` - 典型路径:`/usr/bin/arm-none-eabi-gcc`[^3] 2. **全盘搜索** ```bash sudo find / -name "arm-none-eabi-gcc" 2>/dev/null ``` 常见位置: - ARM官方工具链:`/opt/gcc-arm-none-eabi-*/bin/` - STM32开发包:`/opt/st/stm32*/sysroots/*/usr/share/gcc-arm-none-eabi/bin/`(如您已找到的路径) - 用户目录:`~/Downloads/gcc-*/bin/` --- ### 关键验证步骤 1. **检查可执行权限** ```bash ls -l /usr/bin/arm-none-eabi-gcc # 查看权限 sudo chmod +x /path/to/compiler # 若无执行权限 ``` 2. **验证32位兼容性**(解决 "not found" 错误)[^1] ```bash file /path/to/arm-none-eabi-gcc # 查看文件类型 ``` - 若显示 `ELF 32-bit`,需安装32位库: ```bash sudo apt install libc6:i386 libstdc++6:i386 ``` 3. **测试编译器** ```bash /path/to/arm-none-eabi-gcc --version ``` 成功输出示例: ``` arm-none-eabi-gcc (GNU Arm Embedded Toolchain 10.3-2021.07) 10.3.1 ``` --- ### 环境变量配置(若路径不在 `PATH` 中) 1. **临时添加** ```bash export PATH=$PATH:/opt/gcc-arm-none-eabi-10.3-2021.07/bin ``` 2. **永久生效**(编辑 `~/.bashrc` 或 `/etc/profile`)[^3][^4] ```bash # 添加以下内容 export PATH=$PATH:/opt/arm-gnu-toolchain-11.3.rel1-x86_64-arm-none-eabi/bin ``` 然后执行: ```bash source ~/.bashrc ``` > **架构选择提示**: > - `arm-linux-gnueabihf`:带硬件浮点的 Cortex-A 系列 Linux 系统[^2] > - `arm-none-eabi`:无操作系统的 Cortex-M/R 微控制器[^3] > - 通过 `file $(which arm-xxx-gcc)` 可验证二进制文件架构
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值