How to use YUM to manage packages in CentOS
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 Copy link
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 Copy link
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 httpdWhen asked for confirmation, you should type y (yes) then press Enter to confirm the installation, like this:
Checking for Updates Copy link
Before performing system updates, it's a good practice to check for available updates using the check-update command.
yum check-updateUpdating Packages Copy link
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 updateYou need to confirm the installation like mentioned above:
Removing Packages Copy link
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 httpdA confirmation is needed to remove the package and its dependencies:
Searching for Packages Copy link
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 pythonThis is how it looks:
Listing Installed Packages Copy link
To view a list of all installed packages, you can use the list installed command.
yum list installedCleaning Package Cache Copy link
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 allCentOS Repositories Copy link
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 Copy link
To view a list of enabled and disabled repositories:
yum repolist allThe output looks like this:
Enabling a Repository Copy link
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-utilsTo 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-sourceThen you can check the new status of the repository with grep to filter the results:
yum repolist all | grep baseos-sourceIt shows:
Disabling a Repository Copy link
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-sourceNow, you can check the new status:
Conclusion Copy link
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.
By the way, with Hostman, you can run your workloads on an efficient Amsterdam VPS that support low latency for EU-based users. Check this out, we have plenty of budget VPS hosting options for your projects.