在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

速度应该会有显著提升!

相关推荐
HypoxiaDream11 小时前
LINUX-Ext系列⽂件系统
linux·运维·服务器
小毛驴85011 小时前
Linux curl 命令用法
linux·运维·chrome
李斯啦果12 小时前
【Linux】Linux目录配置
linux·运维·服务器
AI+程序员在路上12 小时前
linux下线程中pthread_detach与pthread_join区别
linux·运维·服务器
代码游侠12 小时前
C语言核心概念复习——C语言基础阶段
linux·开发语言·c++·学习
logocode_li12 小时前
说透 Linux Shell:命令与语法的底层执行逻辑
linux·运维·ssh
CHENKONG_CK12 小时前
晨控CK-LR08-E00与汇川H5U系列PLC配置MODBUSTCP通讯连接手册
linux·服务器·网络
LongQ30ZZ12 小时前
Linux-基础IO
linux
来鸟 鸣间12 小时前
Linux下3个so库之间的关系
linux·运维
零一iTEM12 小时前
MAX98357A_音频输出测试
单片机·嵌入式硬件·开源·音视频·硬件工程