WSL2-Ubuntu22.04下载g++时出现 libc6-dev 软件包linux内核冲突的问题
在WSL2-ubuntu22.04环境下执行
sudo apt-get install g++
出现这样的报错:
the following packages have unmet dependencies:
libc6-dev : depends: libc6 (= 2.31-0ubuntu9.17) but 2.35-0ubuntu3.1 is to be installed
depends: libc-dev-bin (= 2.31-0ubuntu9.17) but it is not going to be installed
问题根源
apt在安装g++时,要从你设定的apt源中获取,然而你设定的源需要执行的ubuntu系统内核版本与当前执行环境的不匹配。
解决方案:
需要根据ubuntu对应的版本进行apt源更换。
查看linux系统的发行版本信息
执行以下命令
lsb_release -a
根据版本对应安装国内镜像源-本文以国内清华源做案例部署
ubuntu22.04
1.备份原先的官方源
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
2.修改sources.list文件内容,先删除文件原来的官方源,添加国内清华源镜像
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-security main restricted universe multiverse
3.执行以下命令更新源即可
sudo apt-get update
sudo apt-get upgrade
4.等待更新完后再安装g++即可
同上,下面给出对应ubuntu版本的国内清华源,按照上面步骤,修改好source.list文件。
ubuntu20.04
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ focal-security main restricted universe multiverse multiverse
ubuntu18.04
# 默认注释了源码镜像以提高 apt update 速度,如有需要可自行取消注释
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-updates main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-backports main restricted universe multiverse
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
# deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-security main restricted universe multiverse
ubuntu24.04
可以查看这篇博客Ubuntu 24.04 抢先体验换国内源 清华源 阿里源 中科大源 163源