Sign In
Sign In

How to use YUM to manage packages in CentOS

How to use YUM to manage packages in CentOS
Adnene Mabrouk
Technical writer
CentOS
15.04.2024
Reading time: 3 min

yum is a package manager used in some Linux distributions like CentOS, Fedora and RedHat.

It’s a tool used in the command line that simplifies the process of installing, updating, and removing software packages, but also to upgrade the distribution. 

In this article, we'll delve into some of the main Yum commands along with code snippets to illustrate their usage.

Prerequisites

You can deploy a cloud server on systems such as CentOS/RHEL 7, Fedora 21, or earlier versions of these distributions. Other Linux distributions that use the YUM package manager are also supported. Use Hostman services to create your cloud server.

Installing Packages

Installing software packages is a breeze with yum. The install command fetches and installs the specified package along with its dependencies.

sudo yum install <package>

For example, to install the Apache web server:

sudo yum install httpd

When asked for confirmation, you should type y (yes) then press Enter to confirm the installation, like this:

Image3

Checking for Updates

Before performing system updates, it's a good practice to check for available updates using the check-update command.

yum check-update

Updating Packages

Keeping your system up to date is crucial for security and performance. The update command updates all installed packages to their latest versions.

sudo yum update

You need to confirm the installation like mentioned above:

Image5

Removing Packages

When a package is no longer needed, you can easily remove it using the remove command.

sudo yum remove <package>

For instance, to remove the Apache web server:

sudo yum remove httpd

A confirmation is needed to remove the package and its dependencies:

Image4

Searching for Packages

The search command allows you to search for packages based on keywords.

yum search <package>

For example, to search for packages related to Python:

yum search python

This is how it looks:

Image7

Listing Installed Packages

To view a list of all installed packages, you can use the list installed command.

yum list installed

Cleaning Package Cache

Over time, the package cache can consume a significant amount of disk space. You can clean up the cache using the clean command.

sudo yum clean all

CentOS Repositories

CentOS repositories are collections of software packages specifically curated for the CentOS Linux distribution. These repositories contain a wide range of software applications, libraries, and tools that users can easily install and manage using yum.

Listing Repositories

To view a list of enabled and disabled repositories:

yum repolist all

The output looks like this:

Image6

Enabling a Repository

To be able to use the commands below with yum-config-manager, you need to install yum-utils. (In some CentOS versions, it is installed by default.)

sudo yum install yum-utils

To enable a repository:

sudo yum-config-manager --enable <repositoryName>

For example, here the baseos-source repo is disabled, you can enable it like this:

sudo yum-config-manager --enable baseos-source

Then you can check the new status of the repository with grep to filter the results:

yum repolist all | grep baseos-source

It shows:

Image2

Disabling a Repository

To disable a repository:

sudo yum-config-manager --disable <repositoryName>

For example, the baseos-source repo was enabled, and we need to disable it:

sudo yum-config-manager --disable baseos-source

Now, you can check the new status:

Image1

Conclusion

yum is a powerful package management utility that simplifies software management on CentOS systems. By mastering these essential commands, you can efficiently install, update, and manage software packages, ensuring the stability and security of your CentOS environment. Whether you're a system administrator, developer, or Linux enthusiast, understanding yum commands is indispensable for effective system administration and software development on CentOS.

CentOS
15.04.2024
Reading time: 3 min

Do you have questions,
comments, or concerns?

Our professionals are available to assist you at any moment,
whether you need help or are just unsure of where to start
Email us