一、更新為本地源
備份
備份/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
最后執(zhí)行如下命令更新源
##更新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.
分析:
更換源之后需要添加公鑰,執(zhí)行以下命令:
注意:這里的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
即執(zhí)行如下操作:gpg --keyserver keyserver.ubuntu.com --recv-keys 公鑰
gpg --export --armor 公鑰 | sudo apt-key add -
針對本文問題,則執(zhí)行: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
// 修復(fù)安裝apt-get build-dep packagename
// 安裝相關(guān)的編譯環(huán)境apt-get source packagename
// 下載該包的源代碼apt-get dist-upgrade
// 升級系統(tǒng)apt-get dselect-upgrade
// 使用 dselect 升級
查詢 & 顯示apt-cache search packagename
// 查詢指定的包 apt-cache show packagename
// 顯示包的相關(guān)信息,如說明、大小、版本等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:文章來源:http://www.zghlxwxcb.cn/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.`
以上問題,經(jīng)調(diào)查,是因為/etc/apt/sources.list中設(shè)定的源和Ubuntu的版本不對應(yīng)導(dǎo)致的。解決辦法如下:
ubuntu的版本源是有規(guī)律的。要查版本號可以通過lsb_release -a查看自己系統(tǒng)上的版本號。
然后可判斷出上面的阿里源配置的是Ubuntu 18.04。而Ubuntu 22.04的代號是jammy。將/etc/apt/sources.list文件中的“bionic”替換成“jammy”即可。文章來源地址http://www.zghlxwxcb.cn/news/detail-491204.html
到了這里,關(guān)于ubuntu設(shè)定apt-get源的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!