Linux_更换软件安装源

一、更换软件源

1.查看机器版本
  lsb_release -a
  uname -a 
2.安装方式
  1. Ubuntu  基于 Debian                    .deb 软件包和 “apt-get” 软件包管理器  
  2. Centos  基于 Red Hat Linux Enterprise  .rpm 软件包和 “yum” 软件包管理器

二、Ubuntu 更换软件源 --私有仓库

   APT:advance packing tool 
说明:
    私有仓库,IP地址和域名对应起来
       100.100.100.100 test.hero.com
    软件源存放在一个名叫sources.list的文件里面  位置: etc/apt/sources.list
   
步骤:
     0.私有仓库,一般没有DNS服务,所以需要修改host文件,将IP地址和域名对应起来
	 
     1.备份该官方源文件
        cp /etc/apt/sources.list /etc/apt/sources.list.bak  
		
     2.修改
     将下面内容写入 `sources.list`,具体内容视Ubuntu版本而定,主要就是把地址改成私服地址: https://test.hero.com/repository/apt-aliyun/
      ```
      deb https://test.hero.com/repository/apt-aliyun/ bionic main restricted universe multiverse
      deb https://test.hero.com/repository/apt-aliyun/ bionic-security main restricted universe multiverse
      deb https://test.hero.com/repository/apt-aliyun/ bionic-updates main restricted universe multiverse
      deb https://test.hero.com/repository/apt-aliyun/ bionic-proposed main restricted universe multiverse
      deb https://test.hero.com/repository/apt-aliyun/ bionic-backports main restricted universe multiverse
      ```
     
     3.更新
       修改完 sources.list 后执行:`apt-get update`,就可以通过私服安装包了。

三、Centos更换软件源

说明:--在线安装
  01.软件的缓存位置 /var/cache/yum	
  02.通过数字签名检查软件来源
     安装原厂的公钥文件 ll  /etc/pki/rpm-gpg

	 rpm读取签名信息,与本机系统内的签名对比,相同则安装,不同则警告并停止安装
  03.验证RPM包 --机制 /var/lib/rpm中数据库的信息
   命令: rpm
 --更换 yum 源
   其中 baseurl 是软件库的实际地址
        gpgcheck
		gpgkey 是数字签名的公钥文件所在地位置	   
步骤  
1.先备份初始源
    ```shell
    cd /etc/yum.repos.d/
    mkdir bak
    mv *.repo bak/
    ```

2.创建新的源文件
    ```shell
    vim Nex.repo
    ```

3.写入下面内容:
    ```shell
    [base]
    name=Nex
    baseurl=https://test.hero.com/repository/yum-public/$releasever/os/$basearch/
    gpgcheck=1
    gpgkey=https://test.hero.com/repository/yum-public/RPM-GPG-KEY-CentOS-7
    
    [updates]
    name=CentOS-$releasever-Updates-custom
    baseurl=https://test.hero.com/repository/yum-public/$releasever/updates/$basearch/
    gpgcheck=1
    gpgkey=https://test.hero.com/repository/yum-public/RPM-GPG-KEY-CentOS-7
    
    [extras]
    name=CentOS-$releasever-Extras-custom
    baseurl=https://test.hero.com/repository/yum-public/$releasever/extras/$basearch/
    gpgcheck=1
    gpgkey=https://test.hero.com/repository/yum-public/RPM-GPG-KEY-CentOS-7
    
    [centosplus]
    name=CentOS-$releasever-Plus-custom
    baseurl=https://test.hero.com/repository/yum-public/$releasever/centosplus/$basearch/
    gpgcheck=1
    enabled=0
    gpgkey=https://test.hero.com/repository/yum-public/RPM-GPG-KEY-CentOS-7
    ```

4.执行清理缓存:
   ```shell
   yum clean all
   yum makecache
   ```

更换的时候

 注意文件权限问题
原文地址:https://www.cnblogs.com/ytwang/p/14805260.html