当前位置: 首页 > news >正文

【错误总结】Ubuntu系统中执行 sudo apt-get update报错

Ubuntu系统中执行 sudo apt-get update报错

  • 命令行描述
  • 升级sudo报错并解决
    • 错误描述
    • 错误解决
      • 原因1:系统网络问题
    • 原因2:设置清华源后/etc/apt/sources.list不匹配
    • 原因3:ubuntu自带的源/etc/apt/sources.list有问题
  • apt-get update成功log
  • 参考

在执行 sudo apt-get install 安装新软件包或升级现有软件包之前,通常会建议先运行 sudo apt-get update,以确保你安装的是最新版本。
但是往往敲完sudo apt-get update命令,会出现超时一段时间后报错结束的问题。

命令行描述

  • sudo是 Debian 和 Ubuntu 系统上用于包管理的一个工具,而其他 Linux 发行版可能使用不同的包管理工具(如 yum、zypper等)。
  • update 是同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。

升级sudo报错并解决

输入升级sudo命令后,

sudo apt-get update

错误描述

出现以下错误,
在这里插入图片描述

报错提示:

E: Some index files failed to download. They have been ignored, or old ones used instead.
E:一些索引文件下载失败。他们要么被忽略,要么使用旧的索引文件。

原因分析: 网络原因,主要是底下这两种原因导致的:

  • 系统网络问题;【本问题解决方案】
  • ubuntu18.04 自带的源/etc/apt/sources.list有问题;

错误解决

原因1:系统网络问题

解决方案: 若为系统网络问题,则需检查DNS配置
(1)Ubuntu系统中终端查看DNS命令:

sudo cat /etc/resolv.conf

如下:

# This is /run/systemd/resolve/stub-resolv.conf managed by man:systemd-resolved(8).
# Do not edit.
#
# This file might be symlinked as /etc/resolv.conf. If you're looking at
# /etc/resolv.conf and seeing this text, you have followed the symlink.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "resolvectl status" to see details about the uplink DNS servers
# currently in use.
#
# Third party programs should typically not access this file directly, but only
# through the symlink at /etc/resolv.conf. To manage man:resolv.conf(5) in a
# different way, replace this symlink by a static file or a different symlink.
#
# See man:systemd-resolved.service(8) for details about the supported modes of
# operation for /etc/resolv.conf.nameserver 127.0.0.53
options edns0 trust-ad
search localdomain

在这里插入图片描述
(2)添加Google 提供的公共 DNS 服务器的 IP 地址 8.8.8.8。
两种方式添加:
第一种:直接在 /etc/resolv.conf 文件后面追加命令:

echo "nameserver 8.8.8.8" >> /etc/resolv.conf

第二种:修改文件 sudo vi /etc/resolv.conf,修改后的文件如下:


弹出以下错误:

E325: ATTENTION
Found a swap file by the name "/run/systemd/resolve/.stub-resolv.conf.swp"owned by: root   dated: 二 7月 30 20:34:38 2024file name: /etc/resolv.confmodified: YESuser name: root   host name: test-virtual-machineprocess ID: 10007
While opening file "/etc/resolv.conf"dated: 二 7月 30 20:24:17 2024(1) Another program may be editing the same file.  If this is the case,be careful not to end up with two different instances of the samefile when making changes.  Quit, or continue with caution.
(2) An edit session for this file crashed.If this is the case, use ":recover" or "vim -r /etc/resolv.conf"to recover the changes (see ":help recovery").If you did this already, delete the swap file "/run/systemd/resolve/.stub-re
solv.conf.swp"to avoid this message.
"/etc/resolv.conf" 23 lines, 930 bytes

出现原因为:异常退出终端时,

原因2:设置清华源后/etc/apt/sources.list不匹配

Ubuntu 的软件源配置文件是 /etc/apt/sources.list。将系统自带的该文件做个备份,将该文件替换为下面内容,即可使用 TUNA 的软件源镜像。

1、备份:

sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup

2、替换sources.list内容

sudo gedit /etc/apt/sources.list

打开文件,如下:
在这里插入图片描述
根据 清华大学开源软件镜像站,替换内容:
在这里插入图片描述
更换后,文件内容如下:
在这里插入图片描述

3、更新,输入以下指令

sudo apt-get update

终端界面如下:
在这里插入图片描述
更新出错,界面如下:
在这里插入图片描述

W: Failed to fetch https:/ /mirrors. tuna. ts inghua . edu . cn/ubuntu/dists/noble/InRelease Temporary failure resolving ' mirrors. tuna. tsinghua . edu.cn'
W: Failed to fetch https : //mirrors . tuna . tsinghua . edu . cn/ubuntu/dists /noble - updates/InRelease Temporary failure resolving ' mirrors. tuna. tsinghua . edu.cn'
W: Failed to fetch https : //mirrors . tuna . tsinghua . edu . cn/ubuntu/dists /noble - backports/ InRelease Temporary failure resolving ' mirrors. tuna. tsinghua. edu. cn '
W: Failed to fetch http: //security . ubuntu. com/ ubuntu/dists/noble- security/InRelease Temporary failure resolving ' security . ubuntu. com '
W: Some index files failed to download. They have been ignored, or old ones used instead.

原因3:ubuntu自带的源/etc/apt/sources.list有问题

解决方案:替换源/etc/apt/sources.list
(1)备份源列表
Ubuntu配置的默认源并不是国内的服务器,下载更新软件都比较慢。

sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak

(2)打开 /etc/apt/sources.list 文件修改

(3)在上面打开的文件开头添加(阿里源)就行

apt-get update成功log

参考

1、CSDN博客-Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】
2、CSDN博客-ubuntu16.04更新清华源并且sudo apt-get update出错的解决

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 随着人工智能技术的发展,如何确保其决策过程的透明度和可解释性,以避免潜在的不公正和歧视?
  • 入门 PyQt6 看过来(案例)18~ 表格属性
  • 【MATLAB源码】机器视觉与图像识别技术实战示例文档---鱼苗面积预测计数
  • 机器学习模型选择与优化: 打造智能IDS
  • 程序员面试中的“八股文”:敲门砖还是绊脚石?
  • M12电连接器的编码分类及应用领域分析
  • 在Linux上编译软件并且运行的入门示例
  • 同城校园跑腿外卖配送平台源码,这套目前全网还没有人分享过
  • 技术学习笔记2:std::bad_cast 在多态编程中有什么作用,如何避免类型转换失败?
  • 面向未来的S2B2C电商供应链系统发展趋势与创新探索
  • 从零入门 AI for Science(AI+药物) #Datawhale AI 夏令营 Task2
  • 使用mysql 的全文检索
  • react native 和 flutter 区别
  • 汇舟问卷:从了解国外问卷工作室开始!
  • idea-常用插件
  • angular组件开发
  • JavaScript函数式编程(一)
  • js ES6 求数组的交集,并集,还有差集
  • macOS 中 shell 创建文件夹及文件并 VS Code 打开
  • Objective-C 中关联引用的概念
  • PermissionScope Swift4 兼容问题
  • thinkphp5.1 easywechat4 微信第三方开放平台
  • vuex 笔记整理
  • 不用申请服务号就可以开发微信支付/支付宝/QQ钱包支付!附:直接可用的代码+demo...
  • 测试如何在敏捷团队中工作?
  • 多线程 start 和 run 方法到底有什么区别?
  • 前端性能优化--懒加载和预加载
  • 让你的分享飞起来——极光推出社会化分享组件
  • 数据结构java版之冒泡排序及优化
  • 用Visual Studio开发以太坊智能合约
  • ​Linux Ubuntu环境下使用docker构建spark运行环境(超级详细)
  • #大学#套接字
  • #单片机(TB6600驱动42步进电机)
  • #考研#计算机文化知识1(局域网及网络互联)
  • $分析了六十多年间100万字的政府工作报告,我看到了这样的变迁
  • (09)Hive——CTE 公共表达式
  • (C#)获取字符编码的类
  • (delphi11最新学习资料) Object Pascal 学习笔记---第2章第五节(日期和时间)
  • (Oracle)SQL优化基础(三):看懂执行计划顺序
  • (ZT)薛涌:谈贫说富
  • (附源码)基于SSM多源异构数据关联技术构建智能校园-计算机毕设 64366
  • (附源码)计算机毕业设计SSM在线影视购票系统
  • (区间dp) (经典例题) 石子合并
  • (图)IntelliTrace Tools 跟踪云端程序
  • (转)程序员疫苗:代码注入
  • (转)为C# Windows服务添加安装程序
  • (转载)Linux网络编程入门
  • .desktop 桌面快捷_Linux桌面环境那么多,这几款优秀的任你选
  • .Net CoreRabbitMQ消息存储可靠机制
  • .NET:自动将请求参数绑定到ASPX、ASHX和MVC(菜鸟必看)
  • .NET构架之我见
  • /ThinkPHP/Library/Think/Storage/Driver/File.class.php  LINE: 48
  • [<事务专题>]
  • [Android] Android ActivityManager
  • [Bzoj4722]由乃(线段树好题)(倍增处理模数小快速幂)