欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  科技

linux在下软件太卡?手把手教你配置国内镜像源

程序员文章站 2022-10-28 21:19:24
ubuntu18.04 配置国内镜像源 修改配置文件 1. 手动更改 用你熟悉的编辑器打开 ,例如 以 为例把下列内容复制替换 中的全部内容( "使用阿里云镜像" ): 2. 一键更改 通过 获取配置文件(前提你的电脑得有wget,没有的话运行 ),例如获取ubuntu18.04的配置文件为例( " ......

ubuntu18.04 配置国内镜像源

修改配置文件

  1. 手动更改

    • 用你熟悉的编辑器打开/etc/apt/sources.list ,例如 vi /etc/apt/sources.list
    • ubuntu 18.04(bionic) 为例把下列内容复制替换sources.list中的全部内容(使用阿里云镜像):
    deb http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
    
    deb http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    
    
  2. 一键更改

    通过wget获取配置文件(前提你的电脑得有wget,没有的话运行sudo apt-get install wget ),例如获取ubuntu18.04的配置文件为例(),阿里云镜像没有找到现成的配置文件,用腾讯云代替

    wget -o /etc/apt/sources.list http://mirrors.cloud.tencent.com/repo/ubuntu18_sources.list
    

其他版本可在阿里云或者腾讯云镜像查看即可。

更新缓存

apt-get clean all
apt-get update

centos7 配置国内镜像源

和ubuntu基本类似,只是文件路径稍有不同

  1. 下载新的centos-base.repo文件到 /etc/yum.repos.d/例如:

    wget -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/repo/centos-7.repo

    或者

    curl -o /etc/yum.repos.d/centos-base.repo http://mirrors.aliyun.com/repo/centos-7.repo

  2. 或者使用 vi /etc/yum.repos.d/centos-base.repo替换成一下内容

    # centos-base.repo
    #
    # the mirror system uses the connecting ip address of the client and the
    # update status of each mirror to pick mirrors that are updated to and
    # geographically close to the client.  you should use this for centos updates
    # unless you are manually picking other mirrors.
    #
    # if the mirrorlist= does not work for you, as a fall back you can try the 
    # remarked out baseurl= line instead.
    #
    #
     
    [base]
    name=centos-$releasever - base - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/os/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/os/$basearch/
            http://mirrors.cloud.aliyuncs.com/centos/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
     
    #released updates 
    [updates]
    name=centos-$releasever - updates - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/updates/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/updates/$basearch/
            http://mirrors.cloud.aliyuncs.com/centos/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
     
    #additional packages that may be useful
    [extras]
    name=centos-$releasever - extras - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/extras/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/extras/$basearch/
            http://mirrors.cloud.aliyuncs.com/centos/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
     
    #additional packages that extend functionality of existing packages
    [centosplus]
    name=centos-$releasever - plus - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/centosplus/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/centosplus/$basearch/
            http://mirrors.cloud.aliyuncs.com/centos/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
     
    #contrib - packages by centos users
    [contrib]
    name=centos-$releasever - contrib - mirrors.aliyun.com
    failovermethod=priority
    baseurl=http://mirrors.aliyun.com/centos/$releasever/contrib/$basearch/
            http://mirrors.aliyuncs.com/centos/$releasever/contrib/$basearch/
            http://mirrors.cloud.aliyuncs.com/centos/$releasever/contrib/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=http://mirrors.aliyun.com/centos/rpm-gpg-key-centos-7
    
    
    
  3. 最后运行更新缓存

    yum clean all
    yum makecache
    

详细参考阿里云镜像站