fbpx yum Command on Linux: Install and Manage Packages on CentOS, RHEL | Certificação Linux

Linux yum Command: Install, Update, and Remove Packages on CentOS and RHEL

📅 01/01/2019 ⏱ 9 min ✍️ Uira Ribeiro
Linuxcommands
Linux yum Command: Install, Update, and Remove Packages on CentOS and RHEL
Exam Pass App — mais de 7.000 questões LPI, offline, em 5 idiomas, disponível no Android e na App Store
Available on
Google Play
Available on
App Store

Linux distributions based on Red Hat use a package manager called Red Hat Package Manager – RPM to install their software. Among the most famous distributions are Red Hat's own Linux Enterprise, Fedora and CentOS.

RPM is a powerful package manager that allows the administrator to install, remove and obtain information about packages. It is a software distribution method widely used in various Linux distributions, besides Red Hat.

It also allows you to build packages from source files, verify digital signature, simulate an installation, among others. It is as powerful as dpkg and apt-get.

Due to the difficulty of dealing with package management using the rpm command, Linux distributions based on Red Hat use the utility yum.

Yum is an acronym for Yellow dog Updater, Modified. It is a tool used to manage the installation and removal of packages in Linux distributions that use the RPM system.

Yum is a file package manager similar to APT-GET that automatically handles dependencies by computing them and resolving what needs to be done to handle them.

It has a configuration file that specifies which repositories YUM should use to search for and download RPM packages.

Not all RPM-based Linux will have the YUM package manager installed. If you need to install YUM, it can be obtained from the website http://yum.baseurl.org.

The command for installation is:

# rpm -ivh yum.rpm

Some yum commands:

  • yum list: Lists all available packages;
  • yum check-update or yum list updates: Checks if there are packages available for an update;
  • yum update: Updates your system;
  • yum install <package(s)>: Installs a specific package and its dependencies;
  • yum remove <package(s)>: Removes a specific package
  • yum info <package>: Presents basic information about a given package.
  • yum whatprovides file:  Lists all packages that have the file indicated in the search

See the examples:

To install a package:

# yum install postgresql

Resolving Dependencies
Install       2 Package(s)
Is this ok [y/N]: y
 
Package(s) data still to download: 3.0 M
(1/2): postgresql-9.0.4-5.fc15.x86_64.rpm       | 2.8 MB     00:11
(2/2): postgresql-libs-9.0.4-5.fc15.x86_64.rpm  | 203 kB     00:00
------------------------------------------------------------------
Total                                  241 kB/s | 3.0 MB     00:12    
 
Running Transaction
  Installing : postgresql-libs-9.0.4-5.fc15.x86_64        1/2
  Installing : postgresql-9.0.4-5.fc15.x86_64             2/2

One option of Yum is the "-y" flag that installs or updates packages without asking. It is not very recommended for production. 

To update installed packages:

# yum update
   Plugins carregados: priorities, update-motd, upgrade-helper
   amzn-main/latest

   Resolvendo dependências
   ---> Executando verificação da transação
   ---> O pacote aws-cli.noarch 0:1.7.5-1.2.amzn1 será atualizado
   ---> O pacote aws-cli.noarch 0:1.7.12-1.3.amzn1 será uma atualização
   ---> Resolução de dependências finalizada

   Dependências resolvidas
   ===============================================================
   Package    Arq.               Versão              Repo                Tam.
   ===============================================================
   Instalando:
   kernel   x86_64      3.14.34-27.48.amzn1      amzn-updates          16 M

   Atualizando:
   aws-cli   noarch     1.7.12-1.3.amzn1          amzn-updates         604 k
   Resumo da transação
   ===============================================================                               Instalar   1 Package  (+4 Dependent packages)
   Upgrade    1 Package

   Tamanho total do download: 16 M
   Is this ok [y/d/N]:

To remove a package:

# yum remove  postgresql

To search all packages with the word "firefox":

# yum search firefox
Loaded plugins: langpacks, presto, refresh-packagekit
============== N/S Matched: firefox ======================
firefox.x86_64 : Mozilla Firefox Web browser
gnome-do-plugins-firefox.x86_64 : gnome-do-plugins for firefox
mozilla-firetray-firefox.x86_64 : System tray extension for firefox
mozilla-adblockplus.noarch : Adblocking extension for Mozilla Firefox
mozilla-noscript.noarch : JavaScript list extension for Mozilla Firefox

Name and summary matches only, use “search all” for everything.

To obtain information about a specific package:

# yum info mysql
Plugins carregados: priorities, update-motd, upgrade-helper
newrelic                                                                                                                  59/59
Pacotes instalados

Nome           : mysql
Arquitetura    : noarch
Versão         : 5.5
Lançamento     : 1.6.amzn1
Tamanho        : 0.0 
Repo           : installed
Do repositório : amzn-main
Sumário        : MySQL meta package
URL            : http://www.mysql.com
Licença        : GPLv2 with exceptions
Descrição: MySQL is a multi-user, multi-threaded SQL database server. MySQL is a
         : client/server implementation consisting of a server daemon (mysqld)
         : and many different client programs and libraries. The base package
         : contains the standard MySQL client programs and generic MySQL files.

To view all packages available in the yum repository:

# yum list
Pacotes instalados
GeoIP.x86_64                        1.4.8-1.5.amzn1                @amzn-main  
GeoIP-devel.x86_64                  1.4.8-1.5.amzn1                @amzn-main  
PyYAML.x86_64                       3.10-3.6.amzn1                 installed    
acl.x86_64                          2.2.49-6.9.amzn1               installed   
acpid.x86_64                        1.0.10-2.1.6.amzn1             installed   
alsa-lib.x86_64                     1.0.22-3.9.amzn1               installed   
apr.x86_64                          1.5.0-2.11.amzn1               @amzn-updates
(…)

To find out which package a specific file belongs to:

# yum provides /etc/sysconfig/nfs
Plugins carregados: priorities, update-motd, upgrade-helper
1:nfs-utils-1.2.3-39.15.amzn1.x86_64 : NFS utilities and supporting clients and daemons for the kernel NFS server

Repo        : amzn-main
Resultado a partir de:
Nome de arquivo    : /etc/sysconfig/nfs

To find out what are the active repositories in YUM:

# yum repolist
id do repo                         nome do repo       status
amzn-main/latest                  amzn-main-Base     5.019
amzn-updates/latest               amzn-updates-Base  1.085
newrelic/x86_64                   New Relic packages 59

Like apt, YUM also caches downloaded packages in the directory /var/cache/yum. 

Usually after successful package installation, yum automatically cleans the cache directory. This depends on the configuration file /etc/yum.conf, especially the keepcache option.

In any case, you can empty the cache with the command:

# yum clean all

Learn much more about Linux in our online course. You can enroll here. If you already have an account, or want to create one, just log in or create your user here.

Did you like it? Share

Uira Ribeiro

Prof. Uirá Ribeiro

Chair do Board do Linux Professional Institute

After years of watching professionals waste hours on simple tasks because they didn't know the right Linux tools, I decided to teach.
Today I'm the author of most of LPI's official Learning Materials and mentor to over 14,000 certified students.

See my full story →

That was just one piece. The course teaches the whole path — from your first command to exam day.

Certificação Linux — a plataforma líder em certificações Linux no Brasil
WhatsApp