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

你可能感兴趣的:(Ubuntu,ubuntu,linux,运维)