All Products
Search
Document Center

Elastic Compute Service:Add or repair an Alibaba Cloud software repository for a Linux instance

Last Updated:Oct 16, 2024

In most cases, Linux software packages are stored in software repositories. After you add a software repository, you can use a package management tool provided by Linux to search for, install, or update software in the repository. This way, you can quickly perform system O&M or meet application development requirements. This topic describes how to install, manage, and use software repositories in different Linux distributions. In the following examples, Alibaba Cloud software repositories are used.

Background information

The speed to access a software repository varies based on various factors, such as the region and distance. Equipped with leading cloud infrastructures, the Alibaba Cloud open source image website provides high-speed all-in-one image services for Internet users free of charge, including the software repositories of mainstream Linux distributions such as CentOS, Debian, Ubuntu, Fedora, and openSUSE. All users can use the software repositories on the Alibaba Cloud open source image website free of charge, regardless of whether the users have Alibaba Cloud accounts. For more information, visit the Alibaba Cloud open source image website.

Important
  • The public images provided by Alibaba Cloud automatically replace the software repository addresses of common Linux distributions with the private addresses of the Alibaba Cloud Elastic Compute Service (ECS) software repositories of the Linux distributions. ECS users can use the ECS software repositories without manual configuration. If you want to add or repair the software repository of a Linux distribution, perform the following operations in this topic.

  • In the following examples, the http://mirrors.aliyun.com public repository address is used, which is suitable for Linux servers that can access the Internet. If your servers are Alibaba Cloud ECS instances, we recommend that you use the http://mirrors.cloud.aliyuncs.com repository address, which is the private repository address of ECS, to accelerate the image download speed.

Add an Alibaba Cloud software repository to a Linux instance

  1. Connect to a Linux instance.

    For more information, see Connect to a Linux instance by using a password or key. In the following example, the ecs-user account is used to connect to a Linux instance. You can use another connection method.

  2. Add an Alibaba Cloud software repository.

    Note

    The following section describes how to add Alibaba Cloud software repositories to common Linux distributions. Perform operations based on the Linux distribution that you use. If you want to add Alibaba Cloud software repositories to other Linux distributions, go to the Alibaba Cloud open source image website and click the operating system distribution that you use to view the procedure.

    Alibaba Cloud Linux 2 or Alibaba Cloud Linux 3

    1. Run the following command to back up the original software repository:

      sudo mv /etc/yum.repos.d/AliYun.repo /etc/yum.repos.d/AliYun.repo.backup
    2. Run the following command to add the Alibaba Cloud software repository:

      Alibaba Cloud Linux 3

      sudo rpm -Uvh --reinstall https://mirrors.aliyun.com/alinux/3/updates/x86_64/Packages/alinux-repos-3.2104.10-2.al8.x86_64.rpm

      Alibaba Cloud Linux 2

      sudo rpm -Uvh --reinstall https://mirrors.aliyun.com/alinux/2/updates/x86_64/Packages/alinux-release-2.1903-11.al7.x86_64.rpm
    3. Run the following command to generate a local cache for fast search and installation of software:

      sudo yum clean all && sudo yum makecache

    CentOS 6, CentOS 7, or CentOS 8

    1. 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
    2. Run the following command to add the Alibaba Cloud software repository:

      CentOS 8

      url=https://mirrors.aliyun.com/repo/Centos-vault-8.5.2111.repo;if [ -f /usr/bin/curl ];then sudo curl -sSO $url;else sudo wget -O /etc/yum.repos.d/Centos-vault-8.5.2111.repo $url; fi

      CentOS 7

      url=https://mirrors.aliyun.com/repo/Centos-7.repo;if [ -f /usr/bin/curl ];then sudo curl -sSO $url;else sudo wget -O /etc/yum.repos.d/Centos-7.repo $url; fi

      CentOS 6

      url=https://mirrors.aliyun.com/repo/Centos-vault-6.10.repo;if [ -f /usr/bin/curl ];then sudo curl -sSO $url;else sudo wget -O /etc/yum.repos.d/Centos-vault-6.10.repo $url; fi
    3. Run the following command to generate a local cache for fast search and installation of software:

      sudo yum clean all && sudo yum makecache

    Ubuntu

    1. Run the following command to back up the original software repository:

      sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
    2. Run the following command to create and open a configuration file:

      sudo vim /etc/apt/sources.list
    3. Press the I keyword to enter Insert mode and add the following information to the configuration file:

      Ubuntu 24.04

      deb https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ noble main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ noble-security main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ noble-updates main restricted universe multiverse
      
      # deb https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
      # deb-src https://mirrors.aliyun.com/ubuntu/ noble-proposed main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ noble-backports main restricted universe multiverse

      Ubuntu 23.04

      deb https://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ lunar main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ lunar-security main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ lunar-updates main restricted universe multiverse
      
      # deb https://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse
      # deb-src https://mirrors.aliyun.com/ubuntu/ lunar-proposed main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ lunar-backports main restricted universe multiverse

      Ubuntu 22.04

      deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
      
      # deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
      # deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
      

      Ubuntu 20.04

      deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
      
      # deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
      # deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

      Ubuntu 18.04

      deb https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ bionic main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ bionic-security main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ bionic-updates main restricted universe multiverse
      
      # deb https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
      # deb-src https://mirrors.aliyun.com/ubuntu/ bionic-proposed main restricted universe multiverse
      
      deb https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
      deb-src https://mirrors.aliyun.com/ubuntu/ bionic-backports main restricted universe multiverse
    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

    5. Run the following command to update the software packages in the software repository:

      sudo apt update

    Debian

    1. Run the following command to back up the original software repository:

      sudo mv /etc/apt/sources.list /etc/apt/sources.list.backup
    2. Run the following command to create and open a configuration file:

      sudo vim /etc/apt/sources.list
    3. Press the I key to enter Insert mode and add the following information to the configuration file:

      Debian 11.x

      deb https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
      deb-src https://mirrors.aliyun.com/debian/ bullseye main non-free contrib
      deb https://mirrors.aliyun.com/debian-security/ bullseye-security main
      deb-src https://mirrors.aliyun.com/debian-security/ bullseye-security main
      deb https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
      deb-src https://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib
      deb https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib
      deb-src https://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib

      Debian 10.x

      deb https://mirrors.aliyun.com/debian/ buster main non-free contrib
      deb-src https://mirrors.aliyun.com/debian/ buster main non-free contrib
      deb https://mirrors.aliyun.com/debian-security buster/updates main
      deb-src https://mirrors.aliyun.com/debian-security buster/updates main
      deb https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib
      deb-src https://mirrors.aliyun.com/debian/ buster-updates main non-free contrib

      Debian 9.x

      deb https://mirrors.aliyun.com/debian-archive/debian stretch main contrib non-free
      #deb https://mirrors.aliyun.com/debian-archive/debian stretch-proposed-updates main non-free contrib
      #deb https://mirrors.aliyun.com/debian-archive/debian stretch-backports main non-free contrib
      deb https://mirrors.aliyun.com/debian-archive/debian-security stretch/updates main contrib non-free
      deb-src https://mirrors.aliyun.com/debian-archive/debian stretch main contrib non-free
      #deb-src https://mirrors.aliyun.com/debian-archive/debian stretch-proposed-updates main contrib non-free
      #deb-src https://mirrors.aliyun.com/debian-archive/debian stretch-backports main contrib non-free
      deb-src https://mirrors.aliyun.com/debian-archive/debian-security stretch/updates main contrib non-free

      Debian 8.x

      deb https://mirrors.aliyun.com/debian-archive/debian/ jessie main non-free contrib
      deb-src https://mirrors.aliyun.com/debian-archive/debian/ jessie main non-free contrib
    4. Press the Esc key, enter :wq, and then press the Enter key to save and close the configuration file.

    5. Run the following command to update the software packages in the software repository:

      sudo apt update

    Fedora

    1. Run the following commands to back up the original software repositories:

      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 the following command to add the Fedora software repository of Alibaba Cloud:

      url=http://mirrors.aliyun.com/repo/fedora.repo;if [ -f /usr/bin/curl ];then sudo curl -sSO $url;else sudo wget -O /etc/yum.repos.d//etc/yum.repos.d/fedora.repo $url; fi
    3. Run the following command to add the Fedora-updates software repository of Alibaba Cloud:

      url=http://mirrors.aliyun.com/repo/fedora-updates.repo;if [ -f /usr/bin/curl ];then sudo curl -sSO $url;else sudo wget -O /etc/yum.repos.d//etc/yum.repos.d/fedora-updates.repo $url; fi
    4. Run the following command to generate a local cache:

      sudo yum clean all && sudo yum makecache

    openSUSE 15.6

    1. Run the following command to back up the original software repository:

      sudo rename '.repo' '.repo.backup' /etc/zypp/repos.d/openSUSE*.repo
    2. Run the following commands to add Alibaba Cloud software repositories:

      sudo zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/leap/15.6/repo/oss/ openSUSE-15.6-Oss
      sudo zypper addrepo -f http://mirrors.aliyun.com/opensuse/distribution/leap/15.6/repo/non-oss/ openSUSE-15.6-Non-Oss
      sudo zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/15.6/oss/ openSUSE-15.6-Update-Oss
      sudo zypper addrepo -f http://mirrors.aliyun.com/opensuse/update/leap/15.6/non-oss/ openSUSE-15.6-Update-Non-Oss
    3. Run the following command to generate a local cache:

      sudo zypper ref

Use software management tools to manage software

In Linux operating systems, you can use package management tools to manage software in software repositories. Common package management tools include Yellowdog Updater Modified (YUM), Dandified YUM (DNF), Advanced Packaging Tool (APT), and Zypper. This topic describes how to search for, install, update, and remove software by using package management tools in different operating system distributions. Replace the software package names in the following examples with the actual names based on your business requirements.

Note

Software packages in Linux distributions are continuously updated to add new features, fix bugs, and provide security updates. You can update software packages to the latest versions based on your business requirements.

Alibaba Cloud Linux, CentOS, or Fedora

  • Search for a software package

    Run the following command to use the YUM package management tool to search for a software package:

    sudo yum search <Search keyword>

    For example, run the following command to search for software packages whose names contain the nginx keyword:

    sudo yum search nginx
  • Install a software package

    Run the following command to use the YUM package management tool to install a software package:

    sudo yum install <Software package name>

    For example, run the following command to install the nginx software package:

    sudo yum install nginx
  • Update a software package

    Run the following command to use the YUM package management tool to update a software package:

    sudo yum update <Software package name>

    For example, run the following command to update the nginx software package:

    sudo yum update nginx
  • Remove a software package

    Run the following command to use the YUM package management tool to remove a software package:

    sudo yum remove <Software package name>

    For example, run the following command to remove the nginx software package:

    sudo yum remove nginx

Ubuntu or Debian

  • Search for a software package

    Run the following command to use the APT package management tool to search for a software package:

    sudo apt search <Search keyword>

    For example, run the following command to search for software packages whose names contain the nginx keyword:

    sudo apt search nginx
  • Install a software package

    Run the following command to use the APT package management tool to install a software package:

    sudo apt install <Software package name>

    For example, run the following command to install the nginx software package:

    sudo apt install nginx
  • Update a software package

    Run the following command to use the APT package management tool to update a software package:

    sudo apt upgrade <Software package name>

    For example, run the following command to update the nginx software package:

    sudo apt upgrade nginx
  • Remove a software package

    Run the following command to use the APT package management tool to remove a software package:

    sudo apt remove <Software package name>

    For example, run the following command to remove the nginx software package:

    sudo apt remove nginx

openSUSE

  • Search for a software package

    Run the following command to use the Zypper package management tool to search for a software package:

    sudo zypper search <Search keyword>

    For example, run the following command to search for software packages whose names contain the nginx keyword:

    sudo zypper search nginx
  • Install a software package

    Run the following command to use the Zypper package management tool to install a software package:

    sudo zypper install <Software package name>

    For example, run the following command to install the nginx software package:

    sudo zypper install nginx
  • Update a software package

    Run the following command to use the Zypper package management tool to update a software package:

    sudo zypper update <Software package name>

    For example, run the following command to update the nginx software package:

    sudo zypper update nginx
  • Remove a software package

    Run the following command to use the Zypper package management tool to remove a software package:

    sudo zypper remove <Software package name>

    For example, run the following command to remove the nginx software package:

    sudo zypper remove nginx