小白近日安装完Ubuntu 22.04LTS后,记不清是不是用了Software Updater还是自己手动upgrade了包,导致在配置编译工具build-essential
(输入sudo apt install build-essential
)时出现如下报错:
Reading package lists... DoneBuilding dependency tree... DoneReading state information... DoneSome packages could not be installed. This may mean that you haverequested an impossible situation or if you are using the unstabledistribution that some required packages have not yet been createdor been moved out of Incoming.The following information may help to resolve the situation:The following packages have unmet dependencies:libc6-dev : Depends: libc6 (= 2.35-0ubuntu3) but 2.35-0ubuntu3.1 is to be installedE: Unable to correct problems, you have held broken packages.
分析报错信息,得知包libc6的版本过高。网上查到的很多关于依赖问题的解决方法是换源,但是换源很可能不能解决问题,比如我尝试了从ustc到aliyun。那么考虑降级操作。考虑到libc6
可能有小白不明确的复杂依赖关系,小白就不敢直接sudo apt install libc6=2.35-0ubuntu3
,这里就借用 Ubuntu解决依赖关系问题的正确姿势一文中提到的包管理工具aptitude
来帮助处理依赖关系
安装aptitude
sudo apt install aptitude
利用aptitude
来安装build-essential
sudo aptitude install build-essential
运行命令后
The following NEW packages will be installed:binutils{a} binutils-common{a} binutils-x86-64-linux-gnu{a} build-essential{b} dpkg-dev{a} fakeroot{a} gcc{a} gcc-11{a} libalgorithm-diff-perl{a} libalgorithm-diff-xs-perl{a} libalgorithm-merge-perl{a} libasan6{a} libbinutils{a} libcc1-0{a} libctf-nobfd0{a} libctf0{a} libfakeroot{a} libgcc-11-dev{a} libitm1{a} liblsan0{a} libquadmath0{a} libtsan0{a} libubsan1{a} lto-disabled-list{a} make{a} The following packages will be REMOVED:systemd-hwe-hwdb{u} 0 packages upgraded, 25 newly installed, 1 to remove and 0 not upgraded.Need to get 34.1 MB of archives. After unpacking 108 MB will be used.The following packages have unmet dependencies:build-essential : Depends: libc6-dev but it is not installable orlibc-dev which is a virtual package, provided by:- libc6-dev (2.35-0ubuntu3), but it is not installableDepends: g++ (>= 4:10.2) but it is not installableThe following actions will resolve these dependencies:Keep the following packages at their current version:1)build-essential [Not Installed]Leave the following dependencies unresolved: 2)dpkg-dev recommends build-essentialAccept this solution? [Y/n/q/?]
显然此时方案并不是我们想要的,输入n
来获得其方案。
The following actions will resolve these dependencies:Install the following packages: 1)g++ [4:11.2.0-1ubuntu1 (jammy)] 2)g++-11 [11.3.0-1ubuntu1~22.04 (jammy-security)]3)gcc-12-base:i386 [12.1.0-2ubuntu1~22.04 (jammy-security)]4)krb5-locales [1.19.2-2 (jammy)] 5)libbrotli1:i386 [1.0.9-2build6 (jammy)] 6)libbsd0:i386 [0.11.5-1 (jammy)] 7)libc-dev-bin [2.35-0ubuntu3 (jammy)]8)libc-devtools:i386 [2.35-0ubuntu3 (jammy)]9)libc6:i386 [2.35-0ubuntu3 (jammy)] 10)libc6-dev [2.35-0ubuntu3 (jammy)] 11)libcom-err2:i386 [1.46.5-2ubuntu1.1 (jammy-security)] 12)libcrypt-dev [1:4.4.27-1 (jammy)] 13)libcrypt1:i386 [1:4.4.27-1 (jammy)] 14)libdeflate0:i386 [1.10-2 (jammy)] 15)libexpat1:i386 [2.4.7-1ubuntu0.2 (jammy-security)] 16)libfontconfig1:i386 [2.13.1-4.2ubuntu5 (jammy)]17)libfreetype6:i386 [2.11.1+dfsg-1build1 (jammy)]18)libgcc-s1:i386 [12.1.0-2ubuntu1~22.04 (jammy-security)] 19)libgd3:i386 [2.3.0-2ubuntu2 (jammy)]20)libgssapi-krb5-2:i386 [1.19.2-2 (jammy)] 21)libidn2-0:i386 [2.3.2-2build1 (jammy)] 22)libjbig0:i386 [2.1-3.1ubuntu0.22.04.1 (jammy-security)] 23)libjpeg-turbo8:i386 [2.1.2-0ubuntu1 (jammy)] 24)libjpeg8:i386 [8c-2ubuntu10 (jammy)]25)libk5crypto3:i386 [1.19.2-2 (jammy)]26)libkeyutils1:i386 [1.6.1-2ubuntu3 (jammy)]27)libkrb5-3:i386 [1.19.2-2 (jammy)] 28)libkrb5support0:i386 [1.19.2-2 (jammy)] 29)liblzma5:i386 [5.2.5-2ubuntu1 (jammy)] 30)libmd0:i386 [1.0.4-1build1 (jammy)] 31)libnsl-dev [1.3.0-2build2 (jammy)] 32)libnsl2:i386 [1.3.0-2build2 (jammy)]33)libnss-nis:i386 [3.1-0ubuntu6 (jammy)] 34)libnss-nisplus:i386 [1.3-0ubuntu6 (jammy)]35)libpng16-16:i386 [1.6.37-3build5 (jammy)] 36)libssl3:i386 [3.0.2-0ubuntu1.7 (jammy-security)] 37)libstdc++-11-dev [11.3.0-1ubuntu1~22.04 (jammy-security)]38)libtiff5:i386 [4.3.0-6ubuntu0.2 (jammy-security)] 39)libtirpc-dev [1.3.2-2ubuntu0.1 (jammy-security)] 40)libtirpc3:i386 [1.3.2-2ubuntu0.1 (jammy-security)] 41)libunistring2:i386 [1.0-1 (jammy)] 42)libuuid1:i386 [2.37.2-4ubuntu3 (jammy)] 43)libwebp7:i386 [1.2.2-2 (jammy)] 44)libx11-6:i386 [2:1.7.5-1 (jammy)] 45)libxau6:i386 [1:1.0.9-1build5 (jammy)] 46)libxcb1:i386 [1.14-3ubuntu3 (jammy)]47)libxdmcp6:i386 [1:1.1.3-0ubuntu5 (jammy)] 48)libxpm4:i386 [1:3.5.12-1build2 (jammy)] 49)libzstd1:i386 [1.4.8+dfsg-3build1 (jammy)]50)linux-libc-dev [5.15.0-53.59 (jammy-security)]51)manpages-dev [5.10-1ubuntu1 (jammy)]52)rpcsvc-proto [1.4.2-0ubuntu6 (jammy)]53)zlib1g:i386 [1:1.2.11.dfsg-2ubuntu9.2 (jammy-security)] Downgrade the following packages: 54)libc6 [2.35-0ubuntu3.1 (now) -> 2.35-0ubuntu3 (jammy)] 55)libc6-dbg [2.35-0ubuntu3.1 (now) -> 2.35-0ubuntu3 (jammy)] 56)libfreetype6 [2.11.1+dfsg-1ubuntu0.1 (jammy-security, now) -> 2.11.1+dfsAccept this solution? [Y/n/q/?]
此时给出了降级方案,选择y
来接受。
最后我们再次运行sudo apt install build-essential
检查,包已经安装完成了。
Reading package lists... DoneBuilding dependency tree... DoneReading state information... Donebuild-essential is already the newest version (12.9ubuntu3).0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
小白,欢迎大佬们讨论指正。