在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

速度应该会有显著提升!

相关推荐
getapi4 分钟前
Ubuntu 22.04 服务器的系统架构是否为 amd64 x86_64
linux·服务器·ubuntu
消失的旧时光-194320 分钟前
Linux 入门核心命令清单(工程版)
linux·运维·服务器
艾莉丝努力练剑28 分钟前
【Linux:文件】Ext系列文件系统(初阶)
大数据·linux·运维·服务器·c++·人工智能·算法
小天源31 分钟前
Cacti在Debian/Ubuntu中安装及其使用
运维·ubuntu·debian·cacti
项目題供诗36 分钟前
51单片机入门(八)
单片机·嵌入式硬件·51单片机
Trouvaille ~1 小时前
【Linux】TCP Socket编程实战(一):API详解与单连接Echo Server
linux·运维·服务器·网络·c++·tcp/ip·socket
羽获飞1 小时前
从零开始学嵌入式之STM32——9.STM32的时钟系统
stm32·单片机·嵌入式硬件
旖旎夜光2 小时前
Linux(13)(中)
linux·网络
飞睿科技2 小时前
乐鑫智能开关方案解析:基于ESP32-C系列的低功耗、高集成设计
嵌入式硬件·物联网·esp32·智能家居·乐鑫科技
威迪斯特2 小时前
CentOS图形化操作界面:理论解析与实践指南
linux·运维·centos·组件·图形化·桌面·xserver