Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】

04-01 阅读 0评论

文章目录

  • 前言
  • 1、命令简单描述
  • 2、本地问题log
  • 3、原因分析
  • 4、解决方法
    • 4.1、系统网络问题【本问题解决方案】
    • 4.2、ubuntu18.04 自带的源`/etc/apt/sources.list`有问题
        • 4.2.1、解决方案:替换源`/etc/apt/sources.list`
        • 4.2.2、如果替换源`/etc/apt/sources.list`后还是不行
        • 5、apt-get update成功log

          前言

          在执行 sudo apt-get install 安装新软件包或升级现有软件包之前,通常会建议先运行 sudo apt-get update,以确保你安装的是最新版本。

          Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】,Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,管理,第1张
          (图片来源网络,侵删)

          但是往往敲完sudo apt-get update命令,会出现超时一段时间后报错结束的问题。


          1、命令简单描述

          apt-get

          是 Debian 和 Ubuntu 系统上用于包管理的一个工具,而其他 Linux 发行版可能使用不同的包管理工具(如 yum、zypper等)。

          update

          update 是同步 /etc/apt/sources.list 和 /etc/apt/sources.list.d 中列出的源的索引,这样才能获取到最新的软件包。

          upgrade

          Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】,Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,管理,第2张
          (图片来源网络,侵删)

          upgrade 是升级已安装的所有软件包,升级之后的版本就是本地索引里的。 因此,在执行 upgrade 之前一定要执行 update,这样才能是最新的。

          #新添加begin
          nameserver 8.8.8.8
          nameserver 8.8.4.4
          #新添加end
          nameserver 127.0.0.53
          options edns0
          

          Esc取消编辑模式,:wq!保存编辑退出,执行cat命令查看是否编辑成功

          sudo cat /etc/resolv.conf 
          

          之后执行sudo apt-get update就正常了。

          2、本地问题log

          root@ubuntu:~# sudo apt update
          Err:1 http://mirrors.ustc.edu.cn/ubuntu-ports bionic InRelease
            Temporary failure resolving 'mirrors.ustc.edu.cn'
          Err:2 http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates InRelease
            Temporary failure resolving 'mirrors.ustc.edu.cn'
          Err:3 http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports InRelease
            Temporary failure resolving 'mirrors.ustc.edu.cn'
          Err:4 http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security InRelease
            Temporary failure resolving 'mirrors.ustc.edu.cn'
          Reading package lists... Done         
          Building dependency tree       
          Reading state information... Done
          All packages are up to date.
          W: Failed to fetch http://mirrors.ustc.edu.cn/ubuntu-ports/dists/bionic/InRelease  Temporary failure resolving 'mirrors.ustc.edu.cn'
          W: Failed to fetch http://mirrors.ustc.edu.cn/ubuntu-ports/dists/bionic-updates/InRelease  Temporary failure resolving 'mirrors.ustc.edu.cn'
          W: Failed to fetch http://mirrors.ustc.edu.cn/ubuntu-ports/dists/bionic-backports/InRelease  Temporary failure resolving 'mirrors.ustc.edu.cn'
          W: Failed to fetch http://mirrors.ustc.edu.cn/ubuntu-ports/dists/bionic-security/InRelease  Temporary failure resolving 'mirrors.ustc.edu.cn'
          W: Some index files failed to download. They have been ignored, or old ones used instead.
          

          3、原因分析

          报错提示:

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

          可以看出是网络原因。

          主要是底下这两种原因导致的:

          Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】,Ubuntu 18.04系统中执行 sudo apt-get update 报错【总结版】【命令行解决】,词库加载错误:未能找到文件“C:\Users\Administrator\Desktop\火车头9.8破解版\Configuration\Dict_Stopwords.txt”。,使用,安装,管理,第3张
          (图片来源网络,侵删)

          3.1、系统网络问题;【本问题解决方案】

          3.2、ubuntu18.04 自带的源/etc/apt/sources.list有问题;

          4、解决方法

          4.1、系统网络问题【本问题解决方案】

          解决方案:检查DNS配置

          (1)Ubuntu 18.04 查看DNS命令:

          sudo cat /etc/resolv.conf
          
          root@ubuntu:~# cat /etc/resolv.conf
          # This file is managed by man:systemd-resolved(8). Do not edit.
          #
          # 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 "systemd-resolve --status" to see details about the uplink DNS servers
          # currently in use.
          #
          # Third party programs must 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
          

          (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,修改后的文件如下:

          root@ubuntu:~# sudo vi /etc/resolv.conf 
          # This file is managed by man:systemd-resolved(8). Do not edit.
          #
          # 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 "systemd-resolve --status" to see details about the uplink DNS servers
          # currently in use.
          #
          # Third party programs must 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
          nameserver 8.8.8.8
          

          (4)尝试 apt update 一下,速度快多了!

          sudo apt-get update
          

          4.2、ubuntu18.04 自带的源/etc/apt/sources.list有问题

          4.2.1、解决方案:替换源/etc/apt/sources.list

          (1)备份源列表

          Ubuntu配置的默认源并不是国内的服务器,下载更新软件都比较慢。

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

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

          sudo vim /etc/apt/sources.list
          

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

          # 阿里源
          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
          # ubuntu
          deb http://cn.archive.ubuntu.com/ubuntu bionic-security main restricted
          # deb-src http://cn.archive.ubuntu.com/ubuntu bionic-security main restricted
          deb http://cn.archive.ubuntu.com/ubuntu bionic-security universe
          # deb-src http://cn.archive.ubuntu.com/ubuntu bionic-security universe
          deb http://cn.archive.ubuntu.com/ubuntu bionic-security multiverse
          # deb-src http://cn.archive.ubuntu.com/ubuntu bionic-security multiverse
          

          附记:(清华源)

          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
          deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
          deb-src https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ bionic-proposed main restricted universe multiverse
          

          (4)同样的尝试更新一下,速度快多了!

          sudo apt-get update
          
          4.2.2、如果替换源/etc/apt/sources.list后还是不行

          把它们加入到了系统的源列表中后,sudo apt-get update还是不行。但是,所有停止维护的版本都可以使用 old 源。所以在原列表中把原来的地址改为带有 old 源的就可以了。

          直接在前面加old-即可。

          例如:

          deb http://cn.archive.ubuntu.com/ubuntu bionic-security main restricted
          改为
          deb http://old-cn.archive.ubuntu.com/ubuntu bionic-security main restricted
          

          5、apt-get update成功log

          root@ubuntu:~# apt-get update

          Hit:1 http://mirrors.ustc.edu.cn/ubuntu-ports bionic InRelease

          Hit:2 http://mirrors.ustc.edu.cn/ubuntu-ports bionic-updates InRelease

          Hit:3 http://mirrors.ustc.edu.cn/ubuntu-ports bionic-backports InRelease

          Hit:4 http://mirrors.ustc.edu.cn/ubuntu-ports bionic-security InRelease

          Reading package lists… Done

          root@ubuntu:~# apt-get upgrade

          Reading package lists… Done

          Building dependency tree

          Reading state information… Done

          Calculating upgrade… Done

          0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.


          谢谢关注点赞哈!


免责声明
本网站所收集的部分公开资料来源于AI生成和互联网,转载的目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。
文章版权声明:除非注明,否则均为主机测评原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
评论列表 (暂无评论,人围观)

还没有评论,来说两句吧...

目录[+]