一、更新为本地源
备份
备份/etc/apt/sources.list
cp /etc/apt/sources.list /etc/apt/sources.list.bak
在/etc/apt/sources.list文件前面添加如下条目#添加阿里源 deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
最后执行如下命令更新源
##更新sudo apt-get update
sudo apt-get upgrade
二、sudo apt-get update报错
Get:1 http://mirrors.aliyun.com/ubuntu bionic InRelease [242 kB] Get:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease [88.7 kB] Get:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease [88.7 kB] Err:1 http://mirrors.aliyun.com/ubuntu bionic InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 Get:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease [242 kB] Get:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease [83.3 kB] Err:2 http://mirrors.aliyun.com/ubuntu bionic-security InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 Err:3 http://mirrors.aliyun.com/ubuntu bionic-updates InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 Err:4 http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 Err:5 http://mirrors.aliyun.com/ubuntu bionic-backports InRelease The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 Reading package lists... Done W: GPG error: http://mirrors.aliyun.com/ubuntu bionic InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 E: The repository 'http://mirrors.aliyun.com/ubuntu bionic InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: http://mirrors.aliyun.com/ubuntu bionic-security InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 E: The repository 'http://mirrors.aliyun.com/ubuntu bionic-security InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: http://mirrors.aliyun.com/ubuntu bionic-updates InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 E: The repository 'http://mirrors.aliyun.com/ubuntu bionic-updates InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 E: The repository 'http://mirrors.aliyun.com/ubuntu bionic-proposed InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details. W: GPG error: http://mirrors.aliyun.com/ubuntu bionic-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32 E: The repository 'http://mirrors.aliyun.com/ubuntu bionic-backports InRelease' is not signed. N: Updating from such a repository can't be done securely, and is therefore disabled by default. N: See apt-secure(8) manpage for repository creation and user configuration details.
分析:
更换源之后需要添加公钥,执行以下命令:
注意:这里的recv-keys就是报错中的key,粘贴过来即可W: GPG error: http://mirrors.aliyun.com/ubuntu bionic-backports InRelease: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 3B4FE6ACC0B21F32
即执行如下操作:gpg --keyserver keyserver.ubuntu.com --recv-keys 公钥
gpg --export --armor 公钥 | sudo apt-key add -
针对本文问题,则执行:gpg --keyserver keyserver.ubuntu.com --recv-keys 3B4FE6ACC0B21F32
gpg --export --armor 3B4FE6ACC0B21F32 | sudo apt-key add -
三、更新
升级 & 安装apt-get update
// 更新源文件,并不会做任何安装升级操作apt-get upgrade
// 升级所有已安装的包apt-get install packagename
// 安装指定的包apt-get install packagename --only-upgrade
// 仅升级指定的包apt-get install packagename --reinstall
// 重新安装包apt-get -f install
// 修复安装apt-get build-dep packagename
// 安装相关的编译环境apt-get source packagename
// 下载该包的源代码apt-get dist-upgrade
// 升级系统apt-get dselect-upgrade
// 使用 dselect 升级
查询 & 显示apt-cache search packagename
// 查询指定的包 apt-cache show packagename
// 显示包的相关信息,如说明、大小、版本等apt-cache depends packagename
// 了解使用该包依赖哪些包apt-cache rdepends packagename
// 查看该包被哪些包依赖
删除apt-get remove packagename
// 删除包 apt-get remove packagename -- purge
// 删除包,包括删除配置文件等apt-get autoremove packagename --purge
// 删除包及其依赖的软件包+配置文件等(只对6.10有效,推荐使用)
清理和检查apt-get clean
// 清理无用的包apt-get autoclean
// 清理无用的包apt-get check
// 检查是否有损坏的依赖
三、安装g++问题
`fresher@DESKTOP-EIF33SC:~$ sudo apt install g++
Reading package lists… Done
Building dependency tree… Done
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:文章来源:https://www.toymoban.com/news/detail-491204.html
The following packages have unmet dependencies:
libc6-dev : Depends: libc6 (= 2.27-3ubuntu1.6) but 2.35-0ubuntu3.1 is to be installed
Depends: libc-dev-bin (= 2.27-3ubuntu1.6) but it is not going to be installed
E: Unable to correct problems, you have held broken packages.`
以上问题,经调查,是因为/etc/apt/sources.list中设定的源和Ubuntu的版本不对应导致的。解决办法如下:
ubuntu的版本源是有规律的。要查版本号可以通过lsb_release -a查看自己系统上的版本号。
然后可判断出上面的阿里源配置的是Ubuntu 18.04。而Ubuntu 22.04的代号是jammy。将/etc/apt/sources.list文件中的“bionic”替换成“jammy”即可。文章来源地址https://www.toymoban.com/news/detail-491204.html
到了这里,关于ubuntu设定apt-get源的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!