在Ubuntu中提升下载速度有多种方法,接下来就给大家逐步列举、详细介绍:
1. 更换软件源(最有效的方法)
bash
# 备份原配置
sudo cp /etc/apt/sources.list /etc/apt/sources.list.backup
# 编辑源列表
sudo nano /etc/apt/sources.list
推荐使用阿里云镜像源(国内最快之一):
将文件内容替换为:
bash
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-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
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
保存后执行:
bash
sudo apt update
其他国内镜像源:
- 清华大学 :
mirrors.tuna.tsinghua.edu.cn - 华为云 :
repo.huaweicloud.com - 网易 :
mirrors.163.com - 中科大 :
mirrors.ustc.edu.cn【好用,推荐】
2. 使用图形界面更换源(更简单)
bash
# 打开软件和更新
sudo software-properties-gtk
# 或在设置中:
# 1. 点击左下角"显示应用程序"
# 2. 搜索"软件和更新"
# 3. 选择"下载自" → 选择"中国"的服务器
3. 使用apt-fast工具(多线程下载)
bash
# 安装
sudo add-apt-repository ppa:apt-fast/stable
sudo apt update
sudo apt install apt-fast
# 使用(替代apt)
sudo apt-fast install tree
4. 配置apt参数优化
bash
# 编辑apt配置文件
sudo nano /etc/apt/apt.conf.d/99custom
添加以下内容:
bash
# 使用IPv4(避免IPv6问题)
Acquire::ForceIPv4 "true";
# 设置超时时间
Acquire::http::Timeout "10";
Acquire::ftp::Timeout "10";
# 设置重试次数
Acquire::Retries "3";
# 禁用管道(某些服务器不支持)
Acquire::http::Pipeline-Depth "0";
# 禁用压缩(高速网络时可启用)
# Acquire::CompressionTypes::Order:: "gz";
5. 对于特定软件下载慢的解决方法
wget/curl下载提速:
bash
# 使用axel(多线程下载工具)
sudo apt install axel
# 多线程下载
axel -n 10 http://example.com/file.tar.gz
# 或aria2(更强大)
sudo apt install aria2
aria2c -x 16 -s 16 http://example.com/file.tar.gz
git clone提速:
bash
# 深度克隆(只下载最近版本)
git clone --depth=1 https://github.com/user/repo.git
# 或者使用国内镜像
# 例如对于GitHub,可以使用:
git clone https://github.com.cnpmjs.org/user/repo.git
6. 网络配置优化
设置DNS(推荐使用阿里DNS或腾讯DNS):
bash
sudo nano /etc/resolv.conf
添加:
bash
nameserver 223.5.5.5 # 阿里DNS
nameserver 119.29.29.29 # 腾讯DNS
nameserver 8.8.8.8 # Google DNS(备选)
永久修改DNS:
bash
sudo nano /etc/systemd/resolved.conf
修改:
bash
[Resolve]
DNS=223.5.5.5 119.29.29.29
FallbackDNS=8.8.8.8
7. 虚拟机网络设置优化
在VMware中:
-
网络适配器:选择"桥接模式"(Bridged)
-
设置:编辑 → 虚拟网络编辑器 → 更改设置 → 还原默认设置
-
关闭防火墙测试 (临时):
bashsudo ufw disable # 测试后记得开启 sudo ufw enable
8. 针对tree软件包的快速下载
bash
# 方法1:直接下载deb包(绕过apt)
wget http://mirrors.aliyun.com/ubuntu/pool/universe/t/tree/tree_1.8.0-1_amd64.deb
sudo dpkg -i tree_1.8.0-1_amd64.deb
# 方法2:使用apt-get的下载选项
apt-get download tree # 只下载不安装
sudo dpkg -i tree*.deb
9. 临时使用代理(如果你有)
bash
# 设置代理(如果需要)
export http_proxy=http://your-proxy:port
export https_proxy=http://your-proxy:port
# 或在apt中设置
sudo nano /etc/apt/apt.conf.d/proxy.conf
添加:
bash
Acquire::http::Proxy "http://your-proxy:port";
Acquire::https::Proxy "http://your-proxy:port";
10. 检查并修复网络问题
bash
# 测试网络连接
ping -c 4 mirrors.aliyun.com
# 测试下载速度
wget --output-document=/dev/null http://speedtest.ftp.otenet.gr/files/test100Mb.db
# 查看下载进度(找出瓶颈)
sudo apt -o Debug::Acquire::http=true update
推荐解决方案顺序:
- 首先更换为阿里云镜像源(95%的问题都能解决)
- 如果还慢,检查DNS设置
- 对于大文件,使用aria2或axel多线程下载
- 虚拟机用户检查网络模式设置
完成第一步后,再试试:
bash
sudo apt update
sudo apt install tree
速度应该会有显著提升!