[Linux] Automating Software Installation, Updates, and Deletion with the yum Command

目次

Overview

The yum command is used in Red Hat-based distributions (such as RHEL and CentOS) to download, install, and update software (RPM packages) from internet repositories.

Its most important feature is automatic dependency resolution. If a program requires specific libraries to run, yum automatically finds and installs them. This prevents errors that often occur when using the rpm command manually.

Specifications (Arguments and Options)

Syntax

yum [options] [command] [package_name]

Main Options

OptionDescription
-yAutomatically answers “Yes” to all confirmation prompts (essential for automation).
-qQuiet mode. Minimizes the output displayed on the screen.
-vVerbose mode. Displays detailed information during execution.
-CUses only the local cache and does not perform network communication.
–enablerepo=[ID]Temporarily enables a repository that is currently disabled.
–disablerepo=[ID]Temporarily disables a repository that is currently enabled.
–downloadonlyDownloads the RPM files without performing the installation.

Main Commands (Operations)

CommandDescription
installInstalls a new package.
updateUpdates installed packages to the latest version.
remove / eraseUninstalls (deletes) a package.
searchSearches for packages by keywords in the name or description.
infoDisplays detailed information (version, license, description, etc.) about a package.
listLists packages (can be filtered by installed, available, updates, etc.).
check-updateChecks if updates are available without actually performing them.
cleanDeletes cached data (metadata and packages).
groupsOperates on “Groups,” which are collections of multiple related packages.

Subcommands for the list Command

SubcommandDescription
installedDisplays only the packages that are already installed.
availableDisplays all packages available in the repositories for installation.
updatesDisplays only the packages that have a newer version available.
allDisplays all packages.

Basic Usage

This is a basic flow where you search for a package (nginx in this example), check its details, and then install it.

# 1. Search for a package
yum search nginx

# 2. Check details
yum info nginx

# 3. Execute installation (with confirmation prompt)
sudo yum install nginx

Example output during installation:

Resolving Dependencies
--> Running transaction check
---> Package nginx.x86_64 1:1.20.1-1.el7 will be installed
--> Finished Dependency Resolution

Total download size: 2.8 M
Is this ok [y/d/N]: y
Downloading packages:
nginx-1.20.1-1.el7.x86_64.rpm          | 2.8 MB  00:01
Running transaction
  Installing : 1:nginx-1.20.1-1.el7.x86_64          1/1 
  Verifying  : 1:nginx-1.20.1-1.el7.x86_64          1/1 

Installed:
  nginx.x86_64 1:1.20.1-1.el7

Complete!

Practical Commands

Searching Packages Quietly

Search for packages containing the keyword “gimp” without displaying unnecessary header information.

yum search gimp -q

Checking for Update Candidates

List only the packages that have updates available without changing the system. This is useful for monitoring scripts.

yum check-update -q

Automating Full System Updates

Update all available packages and skip all confirmation prompts.

sudo yum update -y

Installing a Specific Tool Instantly

Install tcpdump immediately without showing a confirmation screen.

sudo yum install tcpdump -y

Removing a Package

Uninstall tcpdump when it is no longer needed.

sudo yum remove tcpdump

Utilizing Package Groups

Manage sets of tools, such as development environments, all at once.

# Display the list of groups quietly
yum groups list -q

# Check information about the "Development Tools" group
yum groups info "Development Tools" -q

# Install all tools within the group at once
sudo yum groups install "Development Tools"

Customization Points

Temporarily Switching Repositories (–enablerepo)

Use this when you want to install a tool from a repository (e.g., epel) that is usually disabled.

yum install --enablerepo=epel htop

Clearing the Cache (clean all)

If you encounter “Repository Errors” or “Metadata Mismatches,” delete the cache to force a fresh download.

yum clean all

Important Notes

Kernel Updates

The yum update command includes the kernel in its update targets. A new kernel will not become active until the system is rebooted. If you want to keep the kernel version fixed in a production environment, add exclude=kernel* to /etc/yum.conf or add --exclude=kernel* to the command during execution.

Root Privileges

Administrator privileges (sudo) are required to install, update, or remove packages. Commands like search or info can be executed by general users.

Relationship with DNF

In RHEL 8, CentOS 8, and later versions, the internal engine has been replaced by dnf. While the yum command still works and uses dnf in the background, compatibility with yum options is maintained.

Advanced Applications

Installing Local RPM Files with Dependency Resolution

When installing a standalone .rpm file downloaded from the internet, using yum install instead of rpm -ivh is better. yum will automatically fetch any missing dependencies from the repositories.

# Install a local chrome.rpm (resolving dependencies automatically)
sudo yum install ./google-chrome-stable_current_x86_64.rpm

Downloading RPM Files Without Installing

Secure package files for a server that cannot connect to the internet. (Note: This may require the yum-plugin-downloadonly plugin depending on your environment).

# Save the httpd package to /tmp/packages
yum install --downloadonly --downloaddir=/tmp/packages httpd

Summary

yum acts like an “App Store” for Linux server management. Unlike rpm, which requires manual file management, yum handles complex dependency issues for you. You can make environment setup more efficient by using techniques such as -y for automation, groups for bulk management, and check-update for monitoring.

よかったらシェアしてね!
  • URLをコピーしました!
  • URLをコピーしました!

この記事を書いた人

私が勉強したこと、実践したこと、してることを書いているブログです。
主に資産運用について書いていたのですが、
最近はプログラミングに興味があるので、今はそればっかりです。

目次