Debian系列Linux系统下使用apt-fast代替apt-get

 

Debian系列Linux系统常见的有Debian,Ubuntu,Kali等,默认的在线deb包管理工具apt-get(新版本为apt)默认是间线程的,Linux下有个命令axel支持多线程下载,可以写一个脚本apt-fast:

vim /usr/bin/apt-fast
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# !/bin/sh

[ "`whoami`" = root ] || exec sudo "$0" "$@"

if [ ! -x /usr/bin/axel ]
then echo "axel is not installed, perform this?(y/n)"
read ops
case $ops in
y) if apt-get install axel -y --force-yes
then echo "axel installed"
else echo "unable to install the axel. you are using sudo?" ; exit
fi ;;
n) echo "not possible usage apt-fast" ; exit ;;
esac
fi

if echo "$@" | grep -q "upgrade\|install\|dist-upgrade"; then
echo "Working...";

cd /var/cache/apt/archives/;

apt-get -y --print-uris $@ | egrep -o -e "(ht|f)tp://[^\']+" > apt-fast.list && cat apt-fast.list | xargs -l1 axel -a

apt-get $@;

echo -e "\nDone! Verify that all packages were installed successfully. If errors are found, run apt-get clean as root and try again using apt-get directly.\n";

else
apt-get $@;
fi
chmod +x /usr/bin/apt-fast

源地址在http://www.mattparnell.com/linux/apt-fast/apt-fast.sh

下载的则执行

1
2
mv apt-fast.sh /usr/bin/apt-fast
chmod +x /usr/bin/apt-fast

配置apt-fast

可以在/etc/axelrc中指定线程数量

num_connections = 4

使用apt-fast

apt-fast 使用与apt-get完全相同,只是支持多线程。