Ubuntu 使用 apt-get命令失效,Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/precise/InRelease

楼主的是Ubuntu14.04版本,其它版本应该也适用,在使用apt-get update时出现以下错误:

Err http://mirrors.aliyun.com trusty InRelease
  
Err http://mirrors.aliyun.com trusty-updates InRelease
  
Err http://mirrors.aliyun.com trusty-backports InRelease
  
Err http://mirrors.aliyun.com trusty-security InRelease
  
Err http://mirrors.aliyun.com trusty Release.gpg
  Could not resolve 'mirrors.aliyun.com'
Err http://mirrors.aliyun.com trusty-updates Release.gpg
  Could not resolve 'mirrors.aliyun.com'
Err http://mirrors.aliyun.com trusty-backports Release.gpg
  Could not resolve 'mirrors.aliyun.com'
Err http://mirrors.aliyun.com trusty-security Release.gpg
  Could not resolve 'mirrors.aliyun.com'
Reading package lists... Done
W: Failed to fetch http://mirrors.aliyun.com/ubuntu/dists/trusty/InRelease

网上说更换源就好了(sources.list文件),但楼主几乎试了所有的源……依旧不好使。

后来看了一篇博客,有了方向,原来我们需要更新DNS,步骤如下:

sudo vi /etc/resolvconf/resolv.conf.d/base

在里面插入:
nameserver 8.8.8.8
nameserver 8.8.4.4

保存退出

然后执行

sudo resolvconf -u

再看/etc/resolv.conf:

cat /etc/resolv.conf

可以看见最下面就多了2行:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4

此时,执行apt-get update命令成功。

如果更换源后没有成功的小伙伴们可以试试上面这个方法~

 

  • 14
    点赞
  • 39
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
这个问题通常是由于网络连接问题导致的。以下是一些可能的解决方案: 1. 检查网络连接状态:确保你的机器已经连接到了互联网,并且网络连接是正常的。你可以尝试使用ping命令来测试网络连接状态,例如: ``` ping google.com ``` 如果无法ping通,那么可能是你的网络连接有问题。 2. 更改apt源:尝试更改apt源,使用以下命令备份现有的sources.list文件: ``` sudo cp /etc/apt/sources.list /etc/apt/sources.list.bak ``` 然后使用以下命令编辑sources.list文件: ``` sudo nano /etc/apt/sources.list ``` 将其中的内容替换为以下内容: ``` deb http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse deb http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse deb-src http://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse ``` 保存更改并退出编辑器。然后使用以下命令更新apt源: ``` sudo apt-get update ``` 现在你应该可以成功更新apt源了。如果仍然无法解决问题,请尝试使用其他的apt源。 希望这些解决方案可以帮助到你。
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值