2016-08-07 08:40:43 +08:00
|
|
|
|
如何在 Ubuntu Linux 16.04 LTS 中使用多个连接加速 apt-get/apt
|
|
|
|
|
=================================================
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
我该如何加速在 Ubuntu Linux 16.04 或者 14.04 LTS 上从多个仓库中下载包的 apt-get 或者 apt 命令?
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
你需要使用到 apt-fast 这个 shell 封装器。它会通过多个连接同时下载一个包来加速 apt-get/apt 和 aptitude 命令。所有的包都会同时下载。它使用 aria2c 作为默认的下载加速器。
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
### 安装 apt-fast 工具
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
在 Ubuntu Linux 14.04 或者之后的版本尝试下面的命令:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo add-apt-repository ppa:saiarcot895/myppa
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
示例输出:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
![](http://s0.cyberciti.org/uploads/faq/2016/07/install-apt-fast-repo.jpg)
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
更新你的仓库:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-get update
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
或者
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt update
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
![](http://s0.cyberciti.org/uploads/faq/2016/07/install-apt-fast-command.jpg)
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
安装 apt-fast:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-get -y install apt-fast
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
或者
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt -y install apt-fast
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
示例输出:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
Reading package lists... Done
|
|
|
|
|
Building dependency tree
|
|
|
|
|
Reading state information... Done
|
|
|
|
|
The following additional packages will be installed:
|
|
|
|
|
aria2 libc-ares2 libssh2-1
|
|
|
|
|
Suggested packages:
|
|
|
|
|
aptitude
|
|
|
|
|
The following NEW packages will be installed:
|
|
|
|
|
apt-fast aria2 libc-ares2 libssh2-1
|
|
|
|
|
0 upgraded, 4 newly installed, 0 to remove and 0 not upgraded.
|
|
|
|
|
Need to get 1,282 kB of archives.
|
|
|
|
|
After this operation, 4,786 kB of additional disk space will be used.
|
|
|
|
|
Do you want to continue? [Y/n] y
|
|
|
|
|
Get:1 http://01.archive.ubuntu.com/ubuntu xenial/universe amd64 libssh2-1 amd64 1.5.0-2 [70.3 kB]
|
|
|
|
|
Get:2 http://ppa.launchpad.net/saiarcot895/myppa/ubuntu xenial/main amd64 apt-fast all 1.8.3~137+git7b72bb7-0ubuntu1~ppa3~xenial1 [34.4 kB]
|
|
|
|
|
Get:3 http://01.archive.ubuntu.com/ubuntu xenial/main amd64 libc-ares2 amd64 1.10.0-3 [33.9 kB]
|
|
|
|
|
Get:4 http://01.archive.ubuntu.com/ubuntu xenial/universe amd64 aria2 amd64 1.19.0-1build1 [1,143 kB]
|
|
|
|
|
54% [4 aria2 486 kB/1,143 kB 42%] 20.4 kB/s 32s
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
### 配置 apt-fast
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
你将会得到下面的提示(必须输入一个5到16的数值):
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
![](http://s0.cyberciti.org/uploads/faq/2016/07/max-connection-10.jpg)
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
并且
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
![](http://s0.cyberciti.org/uploads/faq/2016/07/apt-fast-confirmation-box.jpg)
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
你也可以直接编辑设置:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo vi /etc/apt-fast.conf
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
> **请注意这个工具并不是给慢速网络连接的,它是给快速网络连接的。如果你的网速慢,那么你将无法从这个工具中得到好处。**
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
### 我该怎么使用 apt-fast 命令?
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
语法是:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
apt-fast command
|
|
|
|
|
apt-fast [options] command
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
#### 使用 apt-fast 取回新的包列表
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt-fast update
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
#### 使用 apt-fast 执行升级
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt-fast upgrade
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 执行发行版升级(发布或者强制内核升级),输入:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast dist-upgrade
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 安装新的包
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
语法是:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
sudo apt-fast install pkg
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
比如要安装 nginx,输入:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast install nginx
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
示例输出:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
![](http://s0.cyberciti.org/uploads/faq/2016/07/sudo-apt-fast-install.jpg)
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 删除包
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast remove pkg
|
|
|
|
|
$ sudo apt-fast remove nginx
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 删除包和它的配置文件
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast purge pkg
|
|
|
|
|
$ sudo apt-fast purge nginx
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 删除所有未使用的包
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast autoremove
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 下载源码包
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast source pkgNameHere
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 清理下载的文件
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast clean
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 清理旧的下载文件
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast autoclean
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 验证没有破坏的依赖
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast check
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
#### 下载二进制包到当前目录
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast download pkgNameHere
|
|
|
|
|
$ sudo apt-fast download nginx
|
|
|
|
|
```
|
|
|
|
|
|
2016-07-30 06:32:57 +08:00
|
|
|
|
示例输出:
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
[#7bee0c 0B/0B CN:1 DL:0B]
|
|
|
|
|
07/26 15:35:42 [NOTICE] Verification finished successfully. file=/home/vivek/nginx_1.10.0-0ubuntu0.16.04.2_all.deb
|
|
|
|
|
07/26 15:35:42 [NOTICE] Download complete: /home/vivek/nginx_1.10.0-0ubuntu0.16.04.2_all.deb
|
|
|
|
|
Download Results:
|
|
|
|
|
gid |stat|avg speed |path/URI
|
|
|
|
|
======+====+===========+=======================================================
|
|
|
|
|
7bee0c|OK | n/a|/home/vivek/nginx_1.10.0-0ubuntu0.16.04.2_all.deb
|
|
|
|
|
Status Legend:
|
|
|
|
|
(OK):download completed.
|
|
|
|
|
```
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
#### 下载并显示指定包的 changelog
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
```
|
|
|
|
|
$ sudo apt-fast changelog pkgNameHere
|
|
|
|
|
$ sudo apt-fast changelog nginx
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
--------------------------------------------------------------------------------
|
|
|
|
|
|
2016-08-07 08:40:43 +08:00
|
|
|
|
via: http://www.cyberciti.biz/faq/how-to-speed-up-apt-get-apt-command-ubuntu-linux/
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
作者:[VIVEK GITE][a]
|
2016-07-30 06:32:57 +08:00
|
|
|
|
译者:[geekpi](https://github.com/geekpi)
|
2016-08-07 08:40:43 +08:00
|
|
|
|
校对:[wxy](https://github.com/wxy)
|
2016-07-29 14:15:33 +08:00
|
|
|
|
|
|
|
|
|
本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译,[Linux中国](https://linux.cn/) 荣誉推出
|
|
|
|
|
|
|
|
|
|
[a]: http://www.cyberciti.biz/tips/about-us
|