Installing Software on CentOS Using YUM
-
Overview of YUM ======== YUM, which stands for Yellow dog Updater, Modified, is an RPM package manager. It automatically downloads and installs RPM packages from specified servers, handles dependencies between packages, and installs all required packages in one go without the need for manual downloads and installations.
-
Types of YUM ======== YUM Server: The server hosts various RPM packages and is referred to as a YUM repository or source. YUM repositories can be either network-based or local. Network repositories require internet access to use YUM commands, while local repositories do not.
YUM Client: Clients only need simple configuration to use YUM commands for installing software. YUM configuration files include global and repository-specific configurations.
- Configuring YUM Repositories ================ Repository configuration files are located in the /etc/yum.repos.d directory. These files describe the basic information of each repository. A single configuration file can contain multiple repositories, but the repository ID [repositoryid] must be unique.
3.1 Configuring YUM Sources
By default, the configuration files in /etc/yum.repos.d point to official YUM repositories. However, downloading packages from the official repository may be slow. Therefore, it is recommended to create new configuration files pointing to non-official repositories and replace the existing CentOS-Base.repo file. Typically, back up the original official repository configuration file CentOS-Base.repo as CentOS-Base.repo.bak before replacing it.
Method One: Manual add a repository configuration file, for example: vim locate.repo
[repo id] The repository ID, which must be enclosed in brackets (required, usually base)
repo name The repository name, optional
mirrorlist Mirror site, optional
baseurl YUM repository address. For example: https://mirrors.aliyun.com/centos/6.9/os/x86_64/
enabled If enabled=1 or not set, the repository is active, enabled=0 means it is inactive (default is 1)
gpgcheck If 1, the RPM digital certificate is valid, if 0, it is not
gpgkey Digital certificate public key location, no need to handle
enablegroups={1|0} enable groups
failovermethod={roundrobin|priority}
roundrobin: randomly select by default
priority: Repository priority, smaller numbers mean higher priority, default is 99 when not set
cost= default is 1000
Method Two: Directly download the repository configuration file
http://mirrors.aliyun.com/repo/ Use the command wget http://mirrors.aliyun.com/repo/Centos-6.repo to download the repository configuration file corresponding to the system version and replace the existing CentOS-Base.repo file.
wget http://mirrors.aliyun.com/repo/Centos-6.repo
mv CentOS-Base.repo CentOS-Base.repo.bak
mv Centos-6.repo CentOS-Base.repo
3.2 Rules for Activating Multiple Repositories
-
All .repo files in /etc/yum.repos.d are loaded regardless of their names.
-
Each repository is controlled by enabled=1 (enabled) or enabled=0 (disabled).
-
If multiple repository files define the same repository ID (e.g., [base]), the configuration loaded latter will override the previous one based on the alphabetical order of the filenames.
-
When multiple repositories provide the same software package, YUM defaults to selecting the repository with the highest priority, i.e., the one with the smallest priority value.
-
Common YUM Commands ========== 4.1 Commands Related to Repositories
-
Enable and disable repositories Enable repository: yum-config-manager --enable "repo id" Disable repository: yum-config-manager --disable "repo id"
-
Display list of repositories yum repolist
-
Display all software lists in the repository yum list
4.2 Installation, Removal, and Updates of Software
Install: yum -y install package1, adding the parameter y allows automatic installation of all dependencies. Reinstall: yum reinstall package Remove: yum remove package Update: yum update package Check if a package is installed: yum search package Downgrade: yum downgrage package Check available updates: yum check-update Check dependencies of a package: yum deplist package1
4.3 Cache Commands
Clear cache: yum clean all Build cache: yum makecache