In most cases, software packages for Linux are stored in software repositories. After you add a software repository, you can use the package management tool provided by Linux to search for, install, and update software applications in the repository. This topic describes how to add software repositories to different Linux distributions. In these examples, Alibaba Cloud software repositories are used.

Background information

All users (even those without Alibaba Cloud accounts) can use Alibaba Cloud software repositories free of charge. You can go to the Alibaba Open Source Image Site to obtain the software repository of your Linux distribution.

Add a software repository to a CentOS instance

In this example, an Elastic Compute Service (ECS) instance that runs a CentOS 7 operating system is used. Operations may vary based on the version of your operating system.
Note CentOS 6 and CentOS 8 have reached their end of life (EOL). In accordance with Linux community rules, all content has been removed from the CentOS 6 and CentOS 8 repository addresses. If you continue to use the default repository address of CentOS 6 or CentOS 8, an error is reported. We recommend that you change the repository address of CentOS 6 or CentOS 8. For more information, see Change the CentOS 6 source address and Change CentOS 8 repository addresses.
  1. Connect to the instance.
    For more information, see Connection methods.
  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 one of the following commands to add the Alibaba Cloud CentOS 7 software repository to the instance:
    • 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 add an Alibaba Cloud software repository to an instance that runs another version of CentOS, go to the Alibaba Open Source Image Site and click centos.
    • To add a software repository that is not from Alibaba Cloud, replace http://mirrors.aliyun.com/repo/Centos-7.repo in the preceding commands with the URL of the software repository that you want to add.
  4. Run the following command to generate a local cache for fast search 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.
    The following command output indicates that the Alibaba Cloud software repository is added to the CentOS 7 instance.

Add a software repository to an Ubuntu instance

In this example, an ECS instance that runs an Ubuntu 18.04 operating system is used. Operations may vary based on the version of your operating system.

  1. Connect to the instance.
    For more information, see Connection methods.
  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 sources.list file and add the following information to the file.
    For information about how to add information to files, 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 add an Alibaba Cloud software repository to an instance that runs another version of Ubuntu, go to the Alibaba Open Source Image Site and click ubuntu. To add an Alibaba Cloud software repository to an ECS instance and reduce data transfer costs, replace http://mirrors.aliyun.com/ubuntu/ on the ubuntu page of the Alibaba Open Source Image Site with http://mirrors.cloud.aliyuncs.com/ubuntu.
    • To add a software repository that is not from Alibaba Cloud, replace the added information with the information of the software repository that you want to add.
  4. Run the sudo apt-get update command to update software package information in the software repository.

Add a software repository to a Debian instance

In this example, an ECS instance that runs a Debian 8.9 operating system is used. Operations may vary based on the version of your operating system.

  1. Connect to the instance.
    For more information, see Connection methods.
  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 sources.list file and add the following information to the file.
    For information about how to add information to files, 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 add an Alibaba Cloud software repository to an instance that runs another version of Debian, go to the Alibaba Open Source Image Site and click debian. To add an Alibaba Cloud software repository to an ECS instance and reduce data transfer costs, replace http://mirrors.aliyun.com/debian/ on the debian page of the Alibaba Open Source Image Site with http://mirrors.cloud.aliyuncs.com/debian/.
    • To add a software repository that is not from Alibaba Cloud, replace the added information with the information of the software repository that you want to add.
  4. Run the sudo apt-get update command to update software package information in the software repository.

Add a software repository to a Fedora instance

  1. Connect to the instance.
    For more information, see Connection methods.
  2. Run the following commands 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
  3. Run one of the following commands to add the Fedora software repository of Alibaba Cloud to the instance:
    • 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 Fedora software repository that is not from Alibaba Cloud, replace http://mirrors.aliyun.com/repo/fedora.repo in the preceding commands with the URL of the software repository that you want to add.
  4. Run one of the following commands to add the fedora-updates software repository of Alibaba Cloud to the instance:
    • 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 fedora-updates software repository that is not from Alibaba Cloud, replace http://mirrors.aliyun.com/repo/fedora-updates.repo in the preceding commands with the URL of the software repository that you want to add.
  5. Run the following command to generate a local cache:
    sudo yum clean all && sudo yum makecache

What to do next

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