Software packages for Linux are often stored in software repositories. After you add a repository, you can use the package management tool of the Linux system to search, install, and update the software in the repository. This topic uses Alibaba Cloud repositories as an example to describe how to add repositories on different Linux distributions.

Note Both Alibaba Cloud users and non-users have free access to software repositories of Alibaba Cloud. You can visit the Alibaba Open Source Mirror Site to obtain the software repository of the Linux distribution.

Add software repositories on CentOS

To add a software repository on the CentOS 7 operating system, follow these steps. The operations may vary depending on the version of your operating system.

  1. Connect to a Linux instance. For more information, see Connect to a Linux instance.
  2. Run the following command to back up the original software repository.
    sudo mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
  3. Run any of the following commands to add a software repository on CentOS 7.
    sudo wget -O /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    sudo curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
    Note
    • To view the steps of adding Alibaba Cloud repositories on other versions of the CentOS operating system, visit the Alibaba Open Source Mirror Site, find centos, and click Help.
    • To add a software repository that is not from Alibaba Cloud, replace the URL of http://mirrors.aliyun.com/repo/Centos-7.repo in the commands above with the URL of the software repository that you want to add.
  4. Run the following command to generate a local cache for faster searching and installation of software.
    sudo yum clean all && sudo yum makecache
  5. Run the sudo yum repolist command to check whether the software repository is added. You will see the following content after you add a software repository of Alibaba Cloud on the CentOS 7 operating system.

Add software repositories on Ubuntu

To add a software repository on the Ubuntu 18.04 operating system, follow these steps. The operations may vary depending on the version of your operating system.

  1. Connect to a Linux instance. For more information, see Connect to a Linux instance.
  2. Run the following command to back up the original software repository.
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bakup
  3. Run the sudo vim/etc/apt/sources.list command to open the file. Add the following content to the file. For more information, see Use the Vim editor.
    deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main restricted universe multiverse
    deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic main restricted universe multiverse
    deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-security main restricted universe multiverse
    deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-security main restricted universe multiverse
    deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-updates main restricted universe multiverse
    deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-proposed main restricted universe multiverse
    deb http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-backports main restricted universe multiverse
    deb-src http://mirrors.cloud.aliyuncs.com/ubuntu/ bionic-backports main restricted universe multiverse
    Note
    • To view the steps of adding software repositories of Alibaba Cloud on other versions of Ubuntu, visit the Alibaba Open Source Mirror Site, find ubuntu, and click Help. If you want to add a software repository of Alibaba Cloud on an Elastic Computing Service (ECS) instance, replace http://mirrors.aliyun.com/ubuntu/ in the Help page with http://mirrors.cloud.aliyuncs.com/ubuntu. This helps save data transfer costs.
    • To add a software repository that is not from Alibaba Cloud, replace the added content above with the content of the software repository that you want to add.
  4. Run the sudo apt-get update command to update the information about software packages.

Add software repositories on Debian

To add a software repository on the Debian 8.9 operating system, follow these steps. The operations may vary depending on the version of your operating system.

  1. Connect to a Linux instance. For more information, see Connect to a Linux instance.
  2. Run the following command to back up the original software repository.
    sudo cp /etc/apt/sources.list /etc/apt/sources.list.bakup
  3. Run the sudo vim/etc/apt/sources.list command to open the file. Add the following content to the file. For more information about how to add the content, see Use the Vim editor.
    deb http://mirrors.cloud.aliyuncs.com/debian/ jessie main non-free contrib
    deb http://mirrors.cloud.aliyuncs.com/debian/ jessie-proposed-updates main non-free contrib
    deb-src http://mirrors.cloud.aliyuncs.com/debian/ jessie main non-free contrib
    deb-src http://mirrors.cloud.aliyuncs.com/debian/ jessie-proposed-updates main non-free contrib
    Note
    • To view the steps of adding software repositories of Alibaba Cloud on other versions of Debian, visit the Alibaba Open Source Mirror Site, find debian, and click Help. If you want to add a software repository of Alibaba Cloud on an ECS instance, replace http://mirrors.aliyun.com/debian/ in the Help page with http://mirrors.cloud.aliyuncs.com/ubuntu. This helps save data transfer costs.
    • To add a software repository that is not from Alibaba Cloud, replace the added content above with the content of the software repository that you want to add.
  4. Run the sudo apt-get update command to update the information about software packages.

Add software repositories on Fedora

  1. Run the following command to back up the original software repository.
    # sudo mv /etc/yum.repos.d/fedora.repo /etc/yum.repos.d/fedora.repo.backup
    # sudo mv /etc/yum.repos.d/fedora-updates.repo /etc/yum.repos.d/fedora-updates.repo.backup
  2. Run any of the following commands to add software repositories of Alibaba Cloud on Fedora.
    sudo wget -O /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo
    sudo curl -o /etc/yum.repos.d/fedora.repo http://mirrors.aliyun.com/repo/fedora.repo
    Note To add a software repository that is not from Alibaba Cloud on Fedora, replace the URL of http://mirrors.aliyun.com/repo/fedora.repo in the commands with the URL of the software repository that you want add.
  3. Run any of the following commands to add software repositories of Alibaba Cloud on fedora-updates.
    sudo wget -O /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo
    sudo curl -o /etc/yum.repos.d/fedora-updates.repo http://mirrors.aliyun.com/repo/fedora-updates.repo
    Note To add a software repository that is not from Alibaba Cloud on fedora-updates, replace http://mirrors.aliyun.com/repo/fedora-updates.repo in the commands with the URL of the software repository that you want.
  4. Run the following command to generate a local cache.
    sudo yum clean all && sudo yum makecache

Next steps

You can install software packages after you add a software repository. For more information, see Install software packages.