Ubuntu系统如何配置apt远程源

  • 查看Unbuntu版本和Codename:

    复制代码
    qv123@localhost:~$ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 22.04.3 LTS
    Release:    22.04
    Codename:   jammy              # 不同的版本apt源语句中就换不同的关键字
  • 备份文件:

    复制代码
    cp /etc/apt/sources.list /opt/sources.list.bak
  • 编辑 /etc/apt/sources.list 文件:(root用户才可以使用哦eof)

    复制代码
    # Unbuntu20.4版本,20.4版本在安装的时候指定好Mirrors addresses再重启网络并且执行sudo apt-get clean && sudo apt-get upgrade && sudo apt-get update命令就可以正常使用apt命令,不必再配置yum源
    #添加阿里源
    cat << eof > /etc/apt/sources.list
    deb http://mirrors.aliyun.com/ubuntu focal main restricted
    deb http://mirrors.aliyun.com/ubuntu focal-updates main restricted
    deb http://mirrors.aliyun.com/ubuntu focal universe
    deb http://mirrors.aliyun.com/ubuntu focal-updates universe
    deb http://mirrors.aliyun.com/ubuntu focal multiverse
    deb http://mirrors.aliyun.com/ubuntu focal-updates multiverse
    deb http://mirrors.aliyun.com/ubuntu focal-backports main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu focal-security main restricted
    deb http://mirrors.aliyun.com/ubuntu focal-security universe
    deb http://mirrors.aliyun.com/ubuntu focal-security multiverse
    eof
    
    # Unbuntu22.4版,22.4版本在安装的时候指定好Mirrors addresses再重启网络并且执行sudo apt-get clean && sudo apt-get upgrade && sudo apt-get update命令就可以正常使用apt命令,不必再配置yum源
    #添加阿里源
    cat << eof > /etc/apt/sources.list
    deb http://mirrors.aliyun.com/ubuntu jammy main restricted
    deb http://mirrors.aliyun.com/ubuntu jammy-updates main restricted
    deb http://mirrors.aliyun.com/ubuntu jammy universe
    deb http://mirrors.aliyun.com/ubuntu jammy-updates universe
    deb http://mirrors.aliyun.com/ubuntu jammy multiverse
    deb http://mirrors.aliyun.com/ubuntu jammy-updates multiverse
    deb http://mirrors.aliyun.com/ubuntu jammy-backports main restricted universe multiverse
    deb http://mirrors.aliyun.com/ubuntu jammy-security main restricted
    deb http://mirrors.aliyun.com/ubuntu jammy-security universe
    deb http://mirrors.aliyun.com/ubuntu jammy-security multiverse
    eof
  • 重启网络:

    复制代码
    sudo systemctl restart systemd-networkd
  • 更新软件包列表:在终端中运行以下命令以使更改生效:

    复制代码
    sudo apt-get clean && sudo apt-get upgrade && sudo apt-get update
  • 测试:

    复制代码
    sudo apt install -y nginx
相关推荐
Lsir10110_2 分钟前
【Linux】序列化与反序列化——网络计算器的实现
linux·运维·网络
脆皮的饭桶20 分钟前
给负载均衡做高可用的工具Keepalived
运维·服务器·负载均衡
坚果派·白晓明24 分钟前
在 Ubuntu 中搭建鸿蒙 PC 三方库交叉编译构建开发环境
ubuntu·华为·harmonyos
袁小皮皮不皮26 分钟前
【HCIA】第三章TCP/IP协议栈中其他主要协议
运维·服务器·网络·网络协议·tcp/ip
阿梦Anmory31 分钟前
保姆级教程:Flask应用实现后台常驻运行(Linux服务器)
linux·服务器·flask
夏日听雨眠31 分钟前
Linux学习1
linux·服务器·学习
小生不才yz32 分钟前
【Makefile 专家之路 | 函数篇】10. 逻辑增强:逻辑函数(if/and/or)与环境断言(info/error)
linux
tonyhi633 分钟前
Ubuntu DeepSeek R1本地化部署 Ollama+Docker+OpenWebUI
java·ubuntu·docker
头孢头孢37 分钟前
效率提升 10 倍!我用 OpenClaw 实现了工作自动化
运维·自动化
Agent产品评测局37 分钟前
中国龙虾ai软件有哪些选择?2026自动化选型指南
运维·人工智能·ai·chatgpt·自动化