apt-get: Could not resolve 'archive.ubuntu.com'解决方法

解决Ubuntu apt-get 错误
本文介绍了解决Ubuntu系统中使用apt-get时出现Couldnotresolve'archive.ubuntu.com'错误的方法。首先需要修改源地址,添加多个国内镜像源。其次要确保hosts文件中有正确的IP地址映射。

在使用Ubuntu搭建TFTP服务器的时候,新买的Linux服务器主机,在是还用atp-get的时候出现了apt-get: Could not resolve 'archive.ubuntu.com'的错误,一开始按照网上的说法,修改apt-get的源网址,添加了国内的一些网址资源以后还是不行,比如添加了以下的一些资源网址:

deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted
deb http://mirrors.ustc.edu.cn/ubuntu/ precise universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise universe
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates universe
deb http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates multiverse
deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse
deb http://security.ubuntu.com/ubuntu precise-security main restricted
deb-src http://security.ubuntu.com/ubuntu precise-security main restricted
deb http://security.ubuntu.com/ubuntu precise-security universe
deb-src http://security.ubuntu.com/ubuntu precise-security universe
deb http://security.ubuntu.com/ubuntu precise-security multiverse
deb-src http://security.ubuntu.com/ubuntu precise-security multiverse

deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted
deb http://mirrors.sohu.com/ubuntu/ precise universe
deb-src http://mirrors.sohu.com/ubuntu/ precise universe
deb http://mirrors.sohu.com/ubuntu/ precise-updates universe
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates universe
deb http://mirrors.sohu.com/ubuntu/ precise multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-updates multiverse
deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse

deb http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted
deb http://mirrors.163.com/ubuntu/ precise universe
deb-src http://mirrors.163.com/ubuntu/ precise universe
deb http://mirrors.163.com/ubuntu/ precise-updates universe
deb-src http://mirrors.163.com/ubuntu/ precise-updates universe
deb http://mirrors.163.com/ubuntu/ precise multiverse
deb-src http://mirrors.163.com/ubuntu/ precise multiverse
deb http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-updates multiverse
deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse
deb-src http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse

至于怎么修改该文件,可以通过通过SSH Secure File Transfer软件打开目录/etc/apt下面的source.list文件通过记事本进行编辑,也就是将上面的内容添加到文件的后面。编辑如下图所示:

但是添加完以上网址后,还是出现Could not resolve 'archive.ubuntu.com'的错误,这种原因其实是因为还缺少一个步骤,就是讲添加的这几个网址的网址和IP进行映射,修改/etc/目录下的host文件,用记事本打开,如下图所示:

讲host文件中的网址找到其实际的IP地址,至于怎么通过网址找到实际的IP,可以百度一下,或者使用ip.chinaz.com进行查询,修改后的host文件如下图所示:

不同时期的网址和IP对应关系是不一样的,上面的网址与IP对应关系在2016年9月5日的时候有效,如果实现请重新查询网址与IP的对应关系。

设置好以上步骤之后,执行命令sudo apt-get update和命令sudo apt-get upgrade。执行完之后,会更新目录,如下图所示:

执行完上面的更新后,就会解决改问题了。

 

综上,主要就是2点:1、添加资源网站,2讲添加的资源网站和实际的IP做映射。

sudo apt install openssh-server在虚拟机终端运行显示Err:1 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssh-client amd64 1:7.6p1-4ubuntu0.7 Could not resolve 'us.archive.ubuntu.com' Ign:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04.1 Err:3 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssh-sftp-server amd64 1:7.6p1-4ubuntu0.7 Could not resolve 'us.archive.ubuntu.com' Err:4 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 openssh-server amd64 1:7.6p1-4ubuntu0.7 Could not resolve 'us.archive.ubuntu.com' Ign:5 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ssh-import-id all 5.7-0ubuntu1.1 Ign:2 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04.1 Err:5 http://us.archive.ubuntu.com/ubuntu bionic-updates/main amd64 ssh-import-id all 5.7-0ubuntu1.1 Could not resolve 'us.archive.ubuntu.com' Ign:2 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04.1 Err:2 http://security.ubuntu.com/ubuntu bionic-updates/main amd64 ncurses-term all 6.1-1ubuntu1.18.04.1 Could not resolve 'us.archive.ubuntu.com' E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh-client_7.6p1-4ubuntu0.7_amd64.deb Could not resolve 'us.archive.ubuntu.com' E: Failed to fetch http://security.ubuntu.com/ubuntu/pool/main/n/ncurses/ncurses-term_6.1-1ubuntu1.18.04.1_all.deb Could not resolve 'us.archive.ubuntu.com' E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh-sftp-server_7.6p1-4ubuntu0.7_amd64.deb Could not resolve 'us.archive.ubuntu.com' E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/o/openssh/openssh-server_7.6p1-4ubuntu0.7_amd64.deb Could not resolve 'us.archive.ubuntu.com' E: Failed to fetch http://us.archive.ubuntu.com/ubuntu/pool/main/s/ssh-import-id/ssh-import-id_5.7-0ubuntu1.1_all.deb Could not resolve 'us.archive.ubuntu.com' E: Unable to fetch some archives, maybe run apt-get update or try with --fix-missing?
09-11
Updating certificates in /etc/ssl/certs... 0 added, 0 removed; done. Running hooks in /etc/ca-certificates/update.d... done. Removing intermediate container abb03a1cb27a ---> 003b73213073 Step 9/23 : RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y --no-install-recommends nodejs ---> Running in b2b9be787ba2 2025-11-07 04:46:56 - =============================================================================== DEPRECATION WARNING =============================================================================== Node.js 18.x is no longer actively supported! You will not receive security or critical stability updates for this version. You should migrate to a supported version of Node.js as soon as possible. Please see https://nodesource.com/products/distributions for details about which version may be appropriate for you. The NodeSource Node.js distributions site contains information both about supported versions of Node.js and N|Solid supported Linux distributions. To learn more about usage, see: https://nodesource.com/products/distributions =============================================================================== Continuing in 10 seconds ... 2025-11-07 04:47:06 - Installing pre-requisites WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Hit:1 http://archive.ubuntu.com/ubuntu bionic InRelease Hit:2 http://security.ubuntu.com/ubuntu bionic-security InRelease Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease Reading package lists... Building dependency tree... Reading state information... 1 package can be upgraded. Run 'apt list --upgradable' to see it. WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Reading package lists... Building dependency tree... Reading state information... ca-certificates is already the newest version (20230311ubuntu0.18.04.1). curl is already the newest version (7.58.0-2ubuntu3.24). The following additional packages will be installed: gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgsm pinentry-curses Suggested packages: parcimonie xloadimage dbus-user-session libpam-systemd pinentry-gnome3 scdaemon pinentry-doc The following NEW packages will be installed: apt-transport-https gnupg gnupg-l10n gnupg-utils gpg gpg-agent gpg-wks-client gpg-wks-server gpgsm pinentry-curses 0 upgraded, 10 newly installed, 0 to remove and 1 not upgraded. Need to get 1552 kB of archives. After this operation, 4525 kB of additional disk space will be used. Get:1 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 apt-transport-https all 1.6.17 [1692 B] Get:2 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gnupg-l10n all 2.2.4-1ubuntu1.6 [50.1 kB] Get:3 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gnupg-utils amd64 2.2.4-1ubuntu1.6 [128 kB] Get:4 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg amd64 2.2.4-1ubuntu1.6 [468 kB] Get:5 http://archive.ubuntu.com/ubuntu bionic/main amd64 pinentry-curses amd64 1.1.0-1 [35.8 kB] Get:6 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-agent amd64 2.2.4-1ubuntu1.6 [227 kB] Get:7 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-wks-client amd64 2.2.4-1ubuntu1.6 [91.8 kB] Get:8 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpg-wks-server amd64 2.2.4-1ubuntu1.6 [85.0 kB] Get:9 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gpgsm amd64 2.2.4-1ubuntu1.6 [215 kB] Get:10 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 gnupg amd64 2.2.4-1ubuntu1.6 [249 kB] debconf: delaying package configuration, since apt-utils is not installed Fetched 1552 kB in 3s (472 kB/s) Selecting previously unselected package apt-transport-https. (Reading database ... 26040 files and directories currently installed.) Preparing to unpack .../0-apt-transport-https_1.6.17_all.deb ... Unpacking apt-transport-https (1.6.17) ... Selecting previously unselected package gnupg-l10n. Preparing to unpack .../1-gnupg-l10n_2.2.4-1ubuntu1.6_all.deb ... Unpacking gnupg-l10n (2.2.4-1ubuntu1.6) ... Selecting previously unselected package gnupg-utils. Preparing to unpack .../2-gnupg-utils_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gnupg-utils (2.2.4-1ubuntu1.6) ... Selecting previously unselected package gpg. Preparing to unpack .../3-gpg_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gpg (2.2.4-1ubuntu1.6) ... Selecting previously unselected package pinentry-curses. Preparing to unpack .../4-pinentry-curses_1.1.0-1_amd64.deb ... Unpacking pinentry-curses (1.1.0-1) ... Selecting previously unselected package gpg-agent. Preparing to unpack .../5-gpg-agent_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gpg-agent (2.2.4-1ubuntu1.6) ... Selecting previously unselected package gpg-wks-client. Preparing to unpack .../6-gpg-wks-client_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gpg-wks-client (2.2.4-1ubuntu1.6) ... Selecting previously unselected package gpg-wks-server. Preparing to unpack .../7-gpg-wks-server_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gpg-wks-server (2.2.4-1ubuntu1.6) ... Selecting previously unselected package gpgsm. Preparing to unpack .../8-gpgsm_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gpgsm (2.2.4-1ubuntu1.6) ... Selecting previously unselected package gnupg. Preparing to unpack .../9-gnupg_2.2.4-1ubuntu1.6_amd64.deb ... Unpacking gnupg (2.2.4-1ubuntu1.6) ... Setting up apt-transport-https (1.6.17) ... Setting up gnupg-l10n (2.2.4-1ubuntu1.6) ... Setting up gpgsm (2.2.4-1ubuntu1.6) ... Setting up gnupg-utils (2.2.4-1ubuntu1.6) ... Setting up pinentry-curses (1.1.0-1) ... Setting up gpg (2.2.4-1ubuntu1.6) ... Setting up gpg-agent (2.2.4-1ubuntu1.6) ... Setting up gpg-wks-server (2.2.4-1ubuntu1.6) ... Setting up gpg-wks-client (2.2.4-1ubuntu1.6) ... Setting up gnupg (2.2.4-1ubuntu1.6) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ... WARNING: apt does not have a stable CLI interface. Use with caution in scripts. Hit:1 http://security.ubuntu.com/ubuntu bionic-security InRelease Hit:2 http://archive.ubuntu.com/ubuntu bionic InRelease Hit:3 http://archive.ubuntu.com/ubuntu bionic-updates InRelease Hit:4 http://archive.ubuntu.com/ubuntu bionic-backports InRelease Get:5 https://deb.nodesource.com/node_18.x nodistro InRelease [12.1 kB] Get:6 https://deb.nodesource.com/node_18.x nodistro/main amd64 Packages [11.7 kB] Fetched 23.9 kB in 2s (13.3 kB/s) Reading package lists... Building dependency tree... Reading state information... 1 package can be upgraded. Run 'apt list --upgradable' to see it. 2025-11-07 04:47:18 - Repository configured successfully. 2025-11-07 04:47:18 - To install Node.js, run: apt install nodejs -y 2025-11-07 04:47:18 - You can use N|solid Runtime as a node.js alternative 2025-11-07 04:47:18 - To install N|solid Runtime, run: apt install nsolid -y Reading package lists... Building dependency tree... Reading state information... 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: nodejs : Depends: libc6 (>= 2.28) but 2.27-3ubuntu1.6 is to be installed E: Unable to correct problems, you have held broken packages. The command '/bin/sh -c curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && apt-get install -y --no-install-recommends nodejs' returned a non-zero code: 100
最新发布
11-08
Get:1 http://security.ubuntu.com/ubuntu bionic-security InRelease [102 kB] Get:2 http://archive.ubuntu.com/ubuntu bionic InRelease [242 kB] Get:3 http://security.ubuntu.com/ubuntu bionic-security/main amd64 Packages [3373 kB] Get:4 http://archive.ubuntu.com/ubuntu bionic-updates InRelease [102 kB] Get:5 http://archive.ubuntu.com/ubuntu bionic-backports InRelease [102 kB] Get:6 http://archive.ubuntu.com/ubuntu bionic/restricted amd64 Packages [13.5 kB] Get:7 http://archive.ubuntu.com/ubuntu bionic/multiverse amd64 Packages [186 kB] Get:8 http://archive.ubuntu.com/ubuntu bionic/main amd64 Packages [1344 kB] Get:9 http://archive.ubuntu.com/ubuntu bionic/universe amd64 Packages [11.3 MB] Get:10 http://security.ubuntu.com/ubuntu bionic-security/universe amd64 Packages [1637 kB] Get:11 http://archive.ubuntu.com/ubuntu bionic-updates/universe amd64 Packages [2411 kB] Get:12 http://archive.ubuntu.com/ubuntu bionic-updates/main amd64 Packages [3786 kB] Get:13 http://security.ubuntu.com/ubuntu bionic-security/restricted amd64 Packages [1688 kB] Get:14 http://archive.ubuntu.com/ubuntu bionic-updates/multiverse amd64 Packages [30.8 kB] Get:15 http://archive.ubuntu.com/ubuntu bionic-updates/restricted amd64 Packages [1728 kB] Get:16 http://archive.ubuntu.com/ubuntu bionic-backports/universe amd64 Packages [20.6 kB] Get:17 http://archive.ubuntu.com/ubuntu bionic-backports/main amd64 Packages [64.0 kB] Get:18 http://security.ubuntu.com/ubuntu bionic-security/multiverse amd64 Packages [23.8 kB] Fetched 28.2 MB in 6s (4979 kB/s) Reading package lists... Reading package lists... Building dependency tree... Reading state information... 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: npm : Depends: node-gyp (>= 0.10.9) but it is not going to be installed E: Unable to correct problems, you have held broken packages. The command '/bin/sh -c apt-get clean && apt-get update && apt-get install --yes --no-install-recommends --no-install-suggests build-essential net-tools inetutils-ping libncurses5-dev libdigest-crc-perl libpopt-dev xxd liblzo2-dev zlib1g-dev lib32z1 libssl-dev libglib2.0-dev libreadline-dev libjson-c-dev libxml2-dev libsqlite3-dev sqlite3 libuv1-dev libxslt1-dev libfcgi-dev libevent-dev libyajl-dev liburiparser-dev libwebsockets-dev locales lua5.1 liblua5.1-dev python python3 python3-dev python3-pip git git-lfs subversion autoconf automake pkg-config ccache cmake ninja-build clang-tools-6.0 bison flex gettext ca-certificates libtool patch vim unzip uuid-dev wget curl cpio bc gawk gdb valgrind diffstat chrpath texinfo ssh openssh-client openssh-server netbase quilt protobuf-c-compiler dropbear-bin openvswitch-switch tmux dirmngr lighttpd alien mlocate iproute2 dos2unix lsb-release rsync gdisk man pax moreutils npm sudo' returned a non-zero code: 100
11-08
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值