YUM is the primary package management tool for installing, updating, removing, and managing software packages in Red Hat Enterprise Linux. YUM performs dependency resolution when installing, updating, and removing software packages.
RPM is a popular package management tool in Red Hat Enterprise Linux-based distros. Using RPM, you can install, uninstall, and query individual software packages. Still, it cannot manage dependency resolution like YUM. RPM does provide you useful output, including a list of required packages. An RPM package consists of an archive of files and metadata. Metadata includes helper scripts, file attributes, and information about packages.
Yum
Yum is much more useful than rpm as it resolves dependencies of the package and installs them all!, First yum download meta data of packages from enalbed repo, rpm is downloaded only when it’s installing. any another command like search, list only check the meta data.
# show all repos, disabled and enabled $ yum repolist all
# yum cache $ yum clean all $ yum makecache
# show packages from local cache, no auto cache update $ yum list # installed and not $ yum list libvirt # installed and not of given package $ yum list installed # installed only $ yum list installed libvirt # installed only of given package # shell-style glob $ yum list mysql* # installed and not pkg with prefix mysql
$ yum install yum-utils # can trigger cache update
# show latest version of ipvsadm(will trigger cache update) of repo $ repoquery ipvsadm
# show files of given pkg from local cache and will trigger cache update # bash can be installed or not(list files of given packages) $ repoquery --list bash /etc/skel/.bash_logout /etc/skel/.bash_profile /etc/skel/.bashrc /usr/bin/alias /usr/bin/bash /usr/bin/bashbug ...
mysql++.x86_64 3.1.0-12.el7 epel # not install available from epel repo ipvsadm.x86_64 1.27-8.el7 @base # installed from base repo: @ indicate installed
# check all packages contains ipvs in its name(package name) $ yum search ipvs # wildcard searching
$ yum info ipvsadm # show basic info of a package installed or not, no auto cache update $ yum provides /etc/fstab # show which package(installed or not) has such file from local cache, no auto cache update $ yum provides rm# show which package(installed or not) has rm binary from local cache, no auto cache update
$ yum grouplist $ yum groupinfo "Development tools"# show what packages in this group $ yum groupinstall -y "Development Tools"# install group of packages $ yum groupremove
######################## Download file of given rpm ######################### $ yumdownloader ipvsadm # save at current dir(no matter it's installed or not)
$ yum install --downloadonly ipvsadm # saved at /var/cache/yum/x86_64/ $ yum install --downloadonly --downloaddir=/tmp ipvsadm # if packet is already installed $ yum reinstall --downloadonly --downloaddir=/tmp ipvsadm
$ yumdownloader --source ipvsadm # download ipvsadm-xxx-src.rpm ######################## Download file of given rpm #########################
$ yum history# show what operations happened $ yum history undo <id> # undo an operation
#####################upgrade and downgrade#################################### # list all possible version of given packet from local cache $ yum provides ipvsadm
# check current installed version $ rpm -qa | grep ipvsadm
# upgrade to latest or specific version # NOTE for upgrade, package must be installed before!!! $ yum upgrade libvirt Package(s) libvirt available, but not installed.
# upgrade does not run daemon-reload and service restart!!! $ yum upgrade -y ipvsadm # can trigger local cache update $ yum upgrade -y ipvsadm-1.27-7.el7.x86_64 # can trigger local cache update
# yum upgrade return 0 (OK) !!! # if packet does not exist # or upgrade to specific version or latest
$ yum upgrade -y no-exist-package Loaded plugins: fastestmirror, langpacks, priorities Loading mirror speeds from cached hostfile 47 packages excluded due to repository priority protections No Match for argument: no-exist-package No package no-exist-package available. No packages marked for update $ echo $?
# downgrade to previous version or specific version # NOTE for upgrade, package must be installed before!!! $ yum downgrade ipvsadm $ yum downgrade ipvsadm-1.27-7.el7.x86_64 #####################upgrade and downgrade####################################
RPM
Name Format of RPM name-version-release.os.arch., example: bash-4.3.2-5.el6.x86_64.rpm
name: package name
version: package version
release: identifier of RPM itself, not related to package
# rebuild xx.rpm from source, then install it $ rpm -rebuild *.src.rpm $ rpm -ivh /usr/src/dist/RPMS/xx.rpm
# Query $ rpm -qa # check all installed packages $ rpm -q ipvsadm # check if ipvsadm installed or not
$ rpm -qi ipvsadm # check basic info of this installed rpm
# show files of given pkg, NOTE this requires ipvsadm must be installed!!! $ rpm -qlv ipvsadm # check all installed files of given installed rpm # show files of given local rpm $ rpm -qlp ./ipvsadm.x86_64 0:1.27-8.el7
# preinstall scriptlet – this will run before a package is installed # postinstall scriptlet – this will run after a package is installed # preuninstall scriptlet – this will run before a package is uninstalled # postuninstall scriptlet – this will run after a package is uninstalled
# check scripts of the installed rpm, post/pre etc $ rpm -q --scripts libvirt preinstall scriptlet (using /bin/sh): # 'libvirt' group is just to allow password-less polkit access to # libvirtd. The uid number is irrelevant, so we use dynamic allocation # described at the above link. getent group libvirt >/dev/null || groupadd -r libvirt
exit 0 postinstall scriptlet (using /bin/sh):
if [ $1 -eq 1 ] ; then # Initial installation systemctl preset virtlockd.socket virtlogd.socket libvirtd.service >/dev/null 2>&1 || : fi
# In upgrade scenario we must explicitly enable virtlockd/virtlogd # sockets, if libvirtd is already enabled and start them if # libvirtd is running, otherwise you'll get failures to start # guests
$ rpm -qf /usr/sbin/ipvsadm # check which rpm this file belongs to
############################ For uninstalled package ########################################################### # -p, --package PACKAGE_FILE # Query an (uninstalled) package PACKAGE_FILE. The PACKAGE_FILE may be specified as an ftp or http style URL ############################ For uninstalled package ########################################################### # show files of given rpm $ rpm -qlp ./ipvsadm.x86_64 0:1.27-8.el7
# Rebuild rpm from installed files then deploy it with rebuild rpm # edit some conf files then rebuild it $ rpmrebuild ipvsadm
# with editing ipvsadm.spec prompt, then rebuild $ rpmrebuild -e ipvsadm
When scriptlets are called, they will be supplied with an argument. This argument, accessed via $1 (for shell scripts) is the number of packages of this name which will be left on the system when the action completes. So for the common case of install, upgrade, and uninstall we have:
install
upgrade
uninstall
%pretrans
$1 == 1
$1 == 2
(N/A)
%pre
$1 == 1
$1 == 2
(N/A)
%post
$1 == 1
$1 == 2
(N/A)
%preun
(N/A)
$1 == 1
$1 == 0
%postun
(N/A)
$1 == 1
$1 == 0
%posttrans
$1 == 1
$1 == 1
(N/A)
Note: even some scripts in rpm(built-in, no such files after installation) come from .spec, there is NO spec file in xxx.rpm but xxx.src.rpm.
It depends on the xx.rpm, as RPM allows to add scripts, hence you can do this there, but most of time, service is not started automatically after installation.
show all services with systemctl
1 2 3 4 5 6 7 8
# show all active systemd service $ systemctl --type=service
# show all active/inactive systemd service $ systemctl --type=service --all # enable means start at boot time
$ systemctl enable htg
yum upgrade vs yum install
yum upgrade needs the package installed before
yum upgrade does NOT touch conf file, it remains what changed, actually, this depends on rpm.spec file