Linux command yum command

Catalog

yum command

Check for updates

See what updates are available for packages installed on your system

yum check-update
~]# yum check-update
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile

GeoIP.x86_64                  1.5.0-14.el7                      base     
NetworkManager.x86_64         1:1.18.4-3.el7                    base         
NetworkManager-libnm.x86_64   1:1.18.4-3.el7                    base         
NetworkManager-team.x86_64    1:1.18.4-3.el7                    base         
NetworkManager-tui.x86_64     1:1.18.4-3.el7                    base         
acl.x86_64                    2.2.51-15.el7                     base         
alsa-lib.x86_64               1.1.8-1.el7                       base
...
  • GeoIP - Name of the package
  • x86_64 - CPU architecture for building packages
  • 1.5.0- The version of the update package to be installed
  • base - The repository where the updated package resides

Update Package

We can update one, more, or all packages at a time, and all dependent packages of this package will be updated as well.

Update individual packages

yum update package_name

Example: Update bash package

~]# yum update bash
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Resolving Dependencies
--> Running transaction check
---> Package bash.x86_64 0:4.2.46-31.el7 will be updated
---> Package bash.x86_64 0:4.2.46-34.el7 will be an update
--> Finished Dependency Resolution

Dependencies Resolved
=========================================================================================
 Package          Arch            Version          Repository         Size
=========================================================================================
Updating:
 bash             x86_64          4.2.46-34.el7     base              1.0 M

Transaction Summary
=========================================================================================
Upgrade  1 Package

Total download size: 1.0 M
Is this ok [y/d/N]: 
  • Loaded plugins - Shows all Yum plugins

  • bash.x86_64 - Indicates the update package to be installed

  • yum runs interactively by default

    • y option, indicating consent to install updates

    • d option, yum downloads packages immediately without installing them.We can use yum localinstall to install these packages, but this command is obsolete and can be installed directly using yum install.

      Downloaded packages are saved by default as/var/cache/yum/\(basearch/\)releasever/packages/

    • N Cancel installation update

Update all packages and their dependent packages

 yum update

Update security-related packages

If packages have security updates available, they can only be updated to their latest version.

yum update --security

Find Packages

 yum search package_name
~]# yum search zsh
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
=================== N/S matched: zsh ==========================
autojump-zsh.noarch : Autojump for zsh
zsh-html.x86_64 : Zsh shell manual in html format
zsh.x86_64 : Powerful interactive shell
zsh-lovers.noarch : A collection of tips, tricks and examples for the Z shell

  Name and summary matches only, use "search all" for everything.
  • By default, yum search returns the name and summary information of the matching package.

List Packages

List all installed and available packages on your system

 yum list all
~]# yum list all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
GeoIP.x86_64                  1.5.0-11.el7     @CentOS7-base
NetworkManager.x86_64         1:1.10.2-13.el7  @CentOS7-base
accountsservice.x86_64        0.6.45-7.el7      CentOS7-base 
accountsservice-devel.i686    0.6.45-7.el7      CentOS7-base 
......   
  • If the package is already installed, there will be a @CentOS7-base flag in front of its corresponding yum repository name, and if not, there will be no CentOS7-base flag.

Lists all packages installed on the system. The rightmost side of the output indicates the yum repository where the packages are located.

yum list installed
~]# yum list installed
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
GeoIP.x86_64             1.5.0-11.el7          @CentOS7-base 
NetworkManager.x86_64    1:1.10.2-13.el7       @CentOS7-base 

List all available packages in all enabled repositories

yum list available
~]# yum list available
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Available Packages
0ad.x86_64               0.0.22-1.el7         fedora-epel-7
0ad-data.noarch          0.0.22-1.el7         fedora-epel-7
0install.x86_64          2.11-1.el7           fedora-epel-7

List all package groups

yum grouplist
[root@node1 ~]# yum groups list
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install
   Compute Node
   Infrastructure Server
   File and Print Server
   Basic Web Server
   Virtualization Host
   Server with GUI
   GNOME Desktop
   KDE Plasma Workspaces
   Development and Creative Workstation
Available Groups:
   Compatibility Libraries
   Console Internet Tools
   Development Tools
   Graphical Administration Tools
   Legacy UNIX Compatibility
   Scientific Support
   Security Tools
   Smart Card Support
   System Administration Tools
   System Management
Done

List group ID s for all package groups

[root@node1 ~]# yum grouplist ids
Loaded plugins: fastestmirror
There is no installed groups file.
Maybe run: yum groups mark convert (see man yum)
Loading mirror speeds from cached hostfile
Available Environment Groups:
   Minimal Install (minimal)
   Compute Node (compute-node-environment)
   Infrastructure Server (infrastructure-server-environment)
   File and Print Server (file-print-server-environment)
   Basic Web Server (web-server-environment)
   Virtualization Host (virtualization-host-environment)
   Server with GUI (graphical-server-environment)
   GNOME Desktop (gnome-desktop-environment)
   KDE Plasma Workspaces (kde-desktop-environment)
   Development and Creative Workstation (developer-workstation-environment)
Available Groups:
   Compatibility Libraries (compat-libraries)
   Console Internet Tools (console-internet)
   Development Tools (development)
   Graphical Administration Tools (graphical-admin-tools)
   Legacy UNIX Compatibility (legacy-unix)
   Scientific Support (scientific)
   Security Tools (security-tools)
   Smart Card Support (smart-card)
   System Administration Tools (system-admin-tools)
   System Management (system-management)
Done

List group IDs and hidden IDs for all packages

[root@node1 ~]# yum grouplist hidden ids

Setup Package Group

There are four ways to install package groups

yum group install "group name"
yum group install groupid
yum install @group
yum install @^group
  • The above four methods are equivalent, which is simple and which is simple.

Example: Take Development Tools as an example to show four installation methods

 ~]# yum group install "Development Tools"
 ~]# yum group install development
 ~]# yum install @"Development Tools"
 ~]# yum install @development
  • Individuals like the fourth because they can type less.

Unload Package Group

yum group remove "group name"
yum group remove groupid
yum remove @group
yum remove @^group

Example: Take Development Tools as an example to show four ways to uninstall package groups

 ~]# yum group remove "Development Tools"
 ~]# yum group remove development
 ~]# yum remove @"Development Tools"
 ~]# yum remove @development

View package information

View information about one or more packages

~]#yum info package_name1 [package_name2] [...]

Example: View information about an httpd package.

~]# yum info httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Installed Packages
Name         : httpd
Arch         : x86_64
Version      : 2.4.6
Release      : 80.el7.centos
Size         : 9.4 M
Repo         : installed
From repo    : CentOS7-base
Summary      : Apache HTTP Server
URL          : http://httpd.apache.org/
License      : ASL 2.0
Description  : The Apache HTTP Server is a powerful, 
             : efficient, and extensible web server.

Installation Package

The yum command automatically resolves dependencies when installing packages, installing packages and all their uninstalled dependent packages.

Install a single package

~]# yum install package_name

Install multiple packages

When installing multiple packages, you can install multiple package names separated by spaces.

~]# yum install package_name1 [package_name2] [...]

The latest version of the default installation package, which requires a version number to be specified when installing older versions.

Example: Install multiple packages at the same time.

~]# yum install httpd mysql

If we only know the name of the binary file to install and not its package name, we can provide the path name for the yum install.

~]# yum install /usr/bin/passwd

At this point, yum searches the package list, retrieves which package provides / usr/bin/passwd, and provides us with the installation if any.

See which package provided the specified file

yum provides "filename" 

When we know only one command, such as ls, but are not sure whether it is installed in the / bin or / sbin / directory, and which package the LS command is installed from, we can use the yum provides command.

# yum provides "*bin/ls"
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
coreutils-8.22-21.el7.x86_64 : A set of basic GNU tools
commonly used in shell scripts
Repo: CentOS7-base
Matched from:
Filename: /bin/ls
Filename: /usr/bin/ls

coreutils-8.22-21.el7.x86_64 : A set of basic GNU tools 
commonly used in shell scripts
Repo: @CentOS7-base
Matched from:
Filename: /bin/ls
Filename: /usr/bin/ls

Reinstall Package

~]# yum reinstall httpd

Uninstall Package

To uninstall a specific package and any packages that depend on it

yum remove package_name...

Example: Uninstall the httpd package

~]# yum remove httpd

Uninstall multiple packages

~]# yum remove package_name1 [package_name2] [...]

List yum repositories

Lists the warehouse ID, name, and number of packages for each warehouse enabled on the system.

~]# yum repolist 
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                repo name          status
CentOS7-base           CentOS7-base        9,911
docker-ce-7            docker-ce-7           156
fedora-epel-7          fedora-epel-7      12,661

yum repolist only displays warehouse information with enabled status.Use the yum repoinfo command to list more information about the warehouse, but this command is not available on CentOS6 systems.

List warehouses that have been enabled and disabled

yum repolist all
 ~]# yum repolist all
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
repo id                repo name                status
C7.0.1406-base/x86_64  CentOS-7.0.1406 - Base   disabled
CentOS7-base           CentOS7-base             enabled:  9,911
fedora-epel-7          fedora-epel-7            enabled: 12,661
  • The status column status of the rightmost output lists the enabled and disabled states of the warehouse in question.

Add Yum Repository

Usually we manage it in/etc/yum.repos.d/Add files with a.repo suffix to the directory instead of / etc/Yum.confAdd to the file.

Yum Repositories on the Internet usually provide their own.repo files, which we only need to add using the following commands.

yum-config-manager --add-repo repository_url
  • Where repository_The URL is a link to the.repo file.

Example: Add NetEase's entOS source to the current system.

~]# yum-config-manager --add-repo http://mirrors.163.com/.help/CentOS7-Base-163.repo

Enable Yum repository

yum-config-manager --enable repositoryID
  • repositoryID is the unique ID of the repository (use yum repolist all to list the available repository IDs)

Enable all repositories

~]# yum-config-manager --enable \*

Disable Yum Repository

yum-config-manager --disable repositoryID
  • repositoryID is the unique ID of the repository (use yum repolist all to list the available repository IDs)

Disable all repositories

~]  yum-config-manager --disable \*

Problems encountered in adding Yum repository

[root@node1 ~]# yum-config-manager --add-repo https://mirrors.163.com/.help/CentOS7-Base-163.repo
Loaded plugins: fastestmirror
adding repo from: https://mirrors.163.com/.help/CentOS7-Base-163.repo
grabbing file https://mirrors.163.com/.help/CentOS7-Base-163.repo to /etc/yum.repos.d/CentOS7-Base-163.repo
Could not fetch/save url https://mirrors.163.com/.help/CentOS7-Base-163.repo to file /etc/yum.repos.d/CentOS7-Base-163.repo: [Errno 14] curl#60 - "Peer's Certificate has expired."

The cause of the problem is that the time of the current system is not consistent with that of the yum source.

Solution:

[root@node1 ~]# yum -y install ntp
[root@node1 ~]# ntpdate time.windows.com

Update security-related packages

List all security related updates

 yum --security check-update 

Update packages to the latest version if they have security updates available

 yum --security update 

Install only the safest security updates, ignoring all packages that may contain unsafe new features

yum --security update-minimal

Tags: Linux yum Fedora EPEL shell

Posted on Tue, 19 May 2020 13:02:01 -0400 by AMV