在Ubuntu下如何提升下载速度

在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中:

  1. 网络适配器:选择"桥接模式"(Bridged)

  2. 设置:编辑 → 虚拟网络编辑器 → 更改设置 → 还原默认设置

  3. 关闭防火墙测试 (临时):

    bash 复制代码
    sudo 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

推荐解决方案顺序:

  1. 首先更换为阿里云镜像源(95%的问题都能解决)
  2. 如果还慢,检查DNS设置
  3. 对于大文件,使用aria2或axel多线程下载
  4. 虚拟机用户检查网络模式设置

完成第一步后,再试试:

bash 复制代码
sudo apt update
sudo apt install tree

速度应该会有显著提升!

相关推荐
先做个垃圾出来………2 小时前
Linux/Unix系统下的基础文本处理命令
java·linux·unix
风若飞2 小时前
Linux 环境下解决 Tomcat8 与 JDK8 配置问题
java·linux·运维·服务器·tomcat
木卫二号Coding2 小时前
Docker-构建自己的Web-Linux系统-镜像kasmweb/ubuntu-jammy-desktop
linux·ubuntu·docker
俊俊谢2 小时前
HC32F460如何配置GPIO中断
单片机·嵌入式硬件·hc32f460
三佛科技-187366133972 小时前
SLD50N06T美浦森60V,50A N沟道MOS场效应管解析
单片机·嵌入式硬件
加油vekiki2 小时前
linux服务器搭建docker、docker-compose
linux·服务器·docker·容器
草丛中的蝈蝈2 小时前
单片机烧写新程序后,ST-LINK无法发现设备
单片机·嵌入式硬件
鱼香rose__2 小时前
常用文件管理命令
linux
水上冰石2 小时前
测试环境生成https自签名证书tls的步骤
linux·服务器·https