优秀的编程知识分享平台

网站首页 > 技术文章 正文

apt install 安装软件常见的问题(apt-get安装软件)

nanyue 2024-10-14 11:42:17 技术文章 19 ℃

一 Ubuntu apt install 下载软件很慢的解决办法

1.打开/etc/apt/sources.list 将内容替换为以下内容(注意把sources.list文件备份一下)

deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse

deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse


2. 最简单的方法:

打开 sources.list 发现地址都是us.archive.ubuntu.com 这样的地址, 将us替换成cn即可

> # vim /etc/apt/sources.list

打开之后依次输入以下命令:

:%s/us.archive/cn.archive/g

回车

:wq

回车(退出vim)

或者替换为 aliyun

> # vim /etc/apt/sources.list

:%s/us.archive.ubuntu.com/mirrors.aliyun.com/g

快捷命令:

sudo sed -i "s@http://.*archive.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list

sudo sed -i "s@http://.*security.ubuntu.com@http://mirrors.aliyun.com@g" /etc/apt/sources.list


更新软件列表

> # apt-get update

注意: aliyun 目前出现问题, 暂时不要使用(20220609)


二 apt install找不到软件的问题

Ubuntu 配置源列表sources.list

在Ubuntu中使用命令下载软件出现sources.list配置错误的问题, 比如执行命令:

sudo apt-get install git

出现错误:

忽略:1 http://mirrors.aliyun.com/ubuntu disco InRelease

忽略:2 http://mirrors.aliyun.com/ubuntu disco-security InRelease

忽略:3 http://mirrors.aliyun.com/ubuntu disco-updates InRelease

忽略:4 http://mirrors.aliyun.com/ubuntu disco-backports InRelease

忽略:5 http://mirrors.aliyun.com/ubuntu disco-proposed InRelease

错误:6 http://mirrors.aliyun.com/ubuntu disco Release

404 Not Found [IP: 117.91.177.241 80]

错误:7 http://mirrors.aliyun.com/ubuntu disco-security Release

404 Not Found [IP: 117.91.177.241 80]

错误:8 http://mirrors.aliyun.com/ubuntu disco-updates Release

404 Not Found [IP: 117.91.177.241 80]

错误:9 http://mirrors.aliyun.com/ubuntu disco-backports Release

404 Not Found [IP: 117.91.177.241 80]

错误:10 http://mirrors.aliyun.com/ubuntu disco-proposed Release

404 Not Found [IP: 117.91.177.241 80]

正在读取软件包列表... 完成

E: 仓库 “http://mirrors.aliyun.com/ubuntu disco Release” 没有 Release 文件。

N: 无法安全地用该源进行更新,所以默认禁用该源。

N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

E: 仓库 “http://mirrors.aliyun.com/ubuntu disco-security Release” 没有 Release 文件。

N: 无法安全地用该源进行更新,所以默认禁用该源。

N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

E: 仓库 “http://mirrors.aliyun.com/ubuntu disco-updates Release” 没有 Release 文件。

N: 无法安全地用该源进行更新,所以默认禁用该源。

N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

E: 仓库 “http://mirrors.aliyun.com/ubuntu disco-backports Release” 没有 Release 文件。

N: 无法安全地用该源进行更新,所以默认禁用该源。

N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

E: 仓库 “http://mirrors.aliyun.com/ubuntu disco-proposed Release” 没有 Release 文件。

N: 无法安全地用该源进行更新,所以默认禁用该源。

N: 参见 apt-secure(8) 手册以了解仓库创建和用户配置方面的细节。

解决方法:更新源列表

1.备份原来的源列表

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

2.获取最新的源列表

下载对应版本最新的源列表:https://mirrors.ustc.edu.cn/repogen/, 比如我的ubuntu20.04

deb https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-updates main restricted universe multiverse

deb https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-backports main restricted universe multiverse

## Not recommended

# deb https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

# deb-src https://mirrors.ustc.edu.cn/ubuntu/ focal-proposed main restricted universe multiverse

3.修改源列表

将上面获取到的源列表复制粘贴到/etc/apt/sources.list。

sudo gedit /etc/apt/sources.list

或者 vim /etc/apt/sources.list

4.更新源列表

sudo apt-get update

5.重新下载

配置完源列表后, 再次重新执行下面的命令即可。

sudo apt-get install git


三 常见的问题: E: Unable to locate package XXX 的解决办法

1.首先尝试update命令

sudo apt-get update

2.如果不行则执行upgrade

sudo apt-get upgrade

上述命令成功以后就能正常使用

sudo apt-get install xxxxx

3.最后上面两项都不行则尝试

sudo apt-get install aptitude

成功以后使用

sudo aptitude install xxxxx


四 为何总是出现 Unable to locate package(无法定位软件包)

> # apt-get install swift swift-proxy python-swiftclient python-keystoneclient python-keystonemiddleware memcached

Reading package lists... Done

Building dependency tree... Done

Reading state information... Done

E: Unable to locate package python-swiftclient

E: Unable to locate package python-keystoneclient

E: Unable to locate package python-keystonemiddleware

为何总是出现 "无法定位软件包"

解决方法: 将 python-* 修改为 python3-*

> # apt-get install swift swift-proxy python3-swiftclient python3-keystoneclient python3-keystonemiddleware memcached

五 > # apt-get install neutron-l3-agent

......

W: Failed to fetch ......

W: Some index files failed to download. They have been ignored, or old ones used instead.

解决方法: 添加DNS

> # vim /etc/resolv.conf

nameserver 8.8.8.8

最近发表
标签列表