【Ubuntu】搭建环境安装软件前apt-get update失败,怎么办?

xiaoxiao2021-02-27  663

**我一般更新或安装软件使用的都是root权限,自己的测试虚拟机无所谓,如果你使用服务器请慎用root权限。**

命令行下输入

sudo apt-get update

报了一堆错误: Err http://cn.archive.ubuntu.com trusty InRelease Err http://cn.archive.ubuntu.com trusty-updates InRelease Err http://cn.archive.ubuntu.com trusty-backports InRelease Err http://cn.archive.ubuntu.com trusty Release.gpg W: Failed to fetch http://cn.archive.ubuntu.com/ubuntu/dists/trusty/InRelease

根据提示的错误显示,可能是资源有问题,应该是访问被阻止,没有梯子。

推荐几个方案:

方案一:修改Ubuntu中/etc/hosts文件,添加可翻墙hosts(资源可以google或百度一下,这就不介绍了)

方案二:修改/etc/apt/source.list文件。将源改成163的或者阿里的:备份系统中的源列表,打开终端,输入:

sudo cp /etc/apt/sources.list /etc/apt/sources.list_backup /etc/apt/source.list文件中添加,下面内容,但别着急先看后面

deb http://mirrors.163.com/ubuntu/ vivid main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ vivid-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ vivid-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ vivid-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ vivid-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ vivid main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ vivid-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ vivid-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ vivid-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ vivid-backports main restricted universe multiverse 可是这个source.list文件是只读权限,无法进行修改。

(1.桌面版sudo gedit /etc/apt/source.list修改,但是gedit 指令没有装,使用sudo apt-get install gedit又安装不了。

 2.服务器版vim /etc/apt/source.list修改,又没有权限

方案三:修改DNS(可行)

首先查看/etc/resolv.conf

cat /etc/resolv.conf

随后命令行执行:

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

在里面插入(如果使用终端,可以直接复制粘贴):

nameserver 8.8.8.8 nameserver 8.8.4.4 修改好,【!wq】退出保存, 然后执行: sudo resolvconf -u 执行结束后,查看/etc/resolv.conf文件,最下面就多了2行: cat /etc/resolv.conf 结果显示: #这块显示原来的信息 nameserver 8.8.8.8 nameserver 8.8.4.4 此时执行: sudo apt-get update

可以运行,然后可以使用sudo apt-get install **指令了。

=================================================================

问题又来了:下载仓库信息失败

实际上,有两种类型的下载仓库信息失败错误。如果你的错误是这样的:

W:Failed to fetch bzip2:/var/lib/apt/lists/partial/in.archive.ubuntu.comubuntudistsoneiricrestrictedbinary-i386Packages Hash Sum mismatch, W:Failed to fetch bzip2:/var/lib/apt/lists/partial/in.archive.ubuntu.comubuntudistsoneiricmultiversebinary-i386Packages Hash Sum mismatch, E:Some index files failed to download. They have been ignored, or old ones used instead 那么,你可以用以下命令修复: sudo rm -rf /var/lib/apt/lists/* sudo apt-get update

=====================================================================

问题又来了:部分更新错误 在终端中运行更新会出现部分更新错误:

Not all updates can be installed Run a partial upgrade, to install as many updates as possible 在终端中运行以下命令来修复该错误: sudo apt-get install -f

=====================================================================

同方案三:

当运行apt-get update后出现如下错误时:  出现了某些故障(-5 - 没有与主机名关联的地址) 

E: Some index files failed to download, they have been ignored, or old ones used instead. 可以将目录下/var/lib/apt/lists/partial/所有的文件清掉(感觉不靠谱),再次运行apt-get update即可!

  如果还有问题,请检查resolvconf服务的配置文件: 

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

很可能是DNS的问题,可以使用公共的dns地址(操作参考方案三):  nameserver 8.8.8.8  nameserver 4.2.2.2 Ubuntu12.04自带源在大陆不好。可以更换其他源:  如果是其它ubuntu版本,只需把precise改为相应的版本的名字。hardy(8.04),lucid(10.04),maverick(10.10),oneiric(11.10),quantal(12.10),precise(12.04) trusty(14.04) 

在/etc/apt/sources.list添加的内容有以下几种: 163

deb http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse deb http://mirrors.163.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-security main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-updates main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/ precise-proposed main restricted universe multiverse deb-src http://mirrors.163.com/ubuntu/precise-backports main restricted universe multiverse sohu deb http://mirrors.sohu.com/ubuntu/ precise main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ precise-security main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ precise-updates main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ precise-proposed main restricted universe multiverse deb http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ precise main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ precisec-security main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ precise-updates main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ precise-proposed main restricted universe multiverse deb-src http://mirrors.sohu.com/ubuntu/ precise-backports main restricted universe multiverse ustc deb http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse deb http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-security main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-updates main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-proposed main restricted universe multiverse deb-src http://mirrors.ustc.edu.cn/ubuntu/ precise-backports main restricted universe multiverse 备注:文中方案一、三,尝试过可行,解决方案来自网络。

转载请注明原文地址: https://www.6miu.com/read-484.html

最新回复(0)