ubuntu设定apt-get源

这篇具有很好参考价值的文章主要介绍了ubuntu设定apt-get源。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、更新为本地源

备份
备份/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:

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设定apt-get源
然后可判断出上面的阿里源配置的是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模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • Ubuntu软件包管理:apt-get remove 与 apt-get purge的区别与注意事项

    本文解释了在Ubuntu中使用apt-get remove和apt-get purge命令卸载软件包的区别,以及使用purge命令时的注意事项,以避免配置文件残留导致重新安装失败的问题。

    2023年04月25日
    浏览(32)
  • Ubuntu中,snap、apt和apt-get的区别

    实际上,apt和apt-get没有什么区别,只是apt比apt-get更高级一点 apt支持进度条显示 apt支持颜色输出,但是apt-get的颜色就极为单调 apt加入了apt update指令,它会自动更新apt中的软件包的版本 apt支持自动清理已卸载的软件包 apt支持列出软件包的详细信息 所以, 不管从哪方面说,

    2024年02月12日
    浏览(49)
  • PVE使用apt-get update更新出现401的解决办法

    PVE安装完毕后,会自动添加一个企业存储库的订阅,但如果您是免费用户,在使用 apt-get update 更新软件的时候会出现401错误,错误内容如下: 解决办法 备份原有的存储库: 然后修改 /etc/apt/sources.list 在末尾添加免费的存储库: 最后再更新即可: apt-get update 此文部分内容参

    2024年02月13日
    浏览(59)
  • 【问题整理】Ubuntu 执行 apt-get install xxx 报错

    一、问题描述: 执行apt-get install fcitx时,报如下错误 二、解决方法: 尝试修复依赖问题: 这个命令会尝试修复系统中的依赖问题,这可能会解决安装过程中的错误。 清理残留文件: 这些命令将重新配置未完成的安装,并清理不再需要的文件。 重新配置 GRUB: 如果您正在安装

    2024年02月13日
    浏览(34)
  • Ubuntu之apt-get系列--安装JDK8--方法/教程

    原文网址:Ubuntu之apt-get--安装JDK8--方法/教程_IT利刃出鞘的博客 本文介绍如何在Ubuntu下安装JDK8。 可以通过如下命令判断系统是否已安装jdk: 命令 结果 如上所示,表示还没有安装。 结果: 本处我安装openjdk-8-jdk 可以通过apt安装,命令如下: 命令 结果 如上则表示安装成功,

    2024年02月10日
    浏览(38)
  • ubuntu下获取apt-get离线安装包的通用方法

    背景 ubuntu下,使用apt-get在线安装某些模块十分的简单,与之相对,想要离线安装某一些功能包往往会产生很多问题,包括并不限于依赖等,同时也有安装包获取困难,版本不对等问题,这里提供一个通用解决方案。 1,准备 准备一台与想要离线安装的系统完全相同的可联网

    2024年02月16日
    浏览(48)
  • RabbitMQ | 在ubuntu中使用apt-get安装高版本RabbitMQ

    目录 一、官方脚本 二、彻底卸载 三、重新安装 1.安装高版本Erlang 2.安装RabbitMQ 直接使用apt安装的rabbitmq版本较低,甚至可能无法使用死信队列等插件。首先提供一个 官方 的安装脚本: 但是这个办法对我这里的情况不奏效。解决方法往下看。 1.安装高版本Erlang 下载 Erlang S

    2024年02月10日
    浏览(32)
  • Ubuntu离线安装Openssh,完美解决没有网络无法直接apt-get

           缺省情况下,我们在部署好ubuntu后,ubuntu是不允许我们直接SSH的,需要我们去下载,但是在机房这样的内网环境下,就显得格外困难,因为无法直接apt-get。所有我们可以通关上传openssh软件包进行安装,来解决这个问题!   openssh-client  SSH客户端 openssh-server  SSH远程

    2024年02月09日
    浏览(39)
  • sudo apt-get update时遇到 无法安全地用该源进行更新,所以默认禁用该源

    重新安装ca-certificates 安装地址 http://ports.ubuntu.com/pool/main/c/ca-certificates/ 选最新更新的 我是ubuntu 18.04,其他版本对应选择 或者用命令行 将文件下载到本地后使用以下命令 至此问题解决

    2024年02月13日
    浏览(38)
  • 解决Ubuntu 或Debian apt-get IPv6问题:如何设置仅使用IPv4

    解决Ubuntu 或Debian apt-get IPv6问题:如何设置仅使用IPv4 背景 : 在Ubuntu 22.04(包括 20.04 18.04 等版本) 或 Debian (10、11、12)系统中,当你使用 apt update 或 apt install 命令时,系统默认会优先使用IPv6网络。但有些时候,尽管系统开启了IPv6,但实际上IPv6网络并不可用,这就导致了apt命令

    2024年02月10日
    浏览(50)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包