Modern days sysadmins (System Administrator) has multiple jobs to perform daily or when required. One of the most important jobs is the installation, configuration, and management of software or app.
Software installation and configuration requirements may come from users, apply updates to fix security problems, and supervise software and system up-gradation.
Generally, sysadmins perform all the following tasks:
- Automating mass installations of operating systems
- Maintaining custom OS configurations
- Keeping systems and applications patched and up to date
- Tracking software licenses
- Managing add-on software packages
RPM and YUM are the two utilities used to manage software installation on CENTOS / RHEL.
Installing and Managing Software with rpm
When packages are installed through yum, the “Yum Database” is updated first, then the updated information is sync to the “RPM Database”. But when the “rpm command” is used to install packages, the update is written to the rpm database only, which is an important reason not to use the rpm command anymore to install
Metadata information for the installed package files is stored in the /var/lib/rpm directory.
Package management tools retrieve information about ownerships, permissions, timestamps, and file sizes from this directory location referred to as the package database.
The package database also contains information on package dependencies.
Understanding RPM Filenames
Generally RPM files delivered in a single file, normally with a filename in the format:
–.src.rpm for source packages, or
–..rpm for binaries.
For example, in the package filename autofs-5.0.7-40.el7.x86_64.rpm, the is autofs, the is 5.0.7, the is 40.el7, and the is x86_64. The associated source package would be named autofs-5.0.7-40.el7.x86_64.src.rpm
The extension “noarch.rpm” has been given to the RPMS that do not depend on a particular CPU architecture. For example, these RPMs may contain graphics and text for other programs to use. They may also contain shell scripts or programs written in other interpreted programming languages such as Python.
Each RPM package is a special archive made up of three components:
- Installed package File.
- Metadata Information about the package, such as the name/version/release/arch; a summary and description of the package; packages dependencies; licensing; a package changelog; and other details.
- Scripts that may run when this package is installed, updated, or removed, or which are triggered when other packages are installed, updated, or removed.
Enough of the theories, let’s explore the rpm command utility:
To list all software that is installed
$sudo rpm -qa
To install or update package
$sudo rpm -F OR -i OR -U OR -force OR -replacepkgs
- F = Upgrades an existing package.
- i = Installs a package.
- U = Upgrades an existing package or installs it if not already installed.
- h = Shows installation progress.
- force = Installs a package even if the same version already exists.
- replacepkgs = Overwrites existing packages.
To remove package
$sudo rpm -e [Package Name]
To get a description of the package
# rpm -qi nmap
To list all files that are in the package
# rpm -ql nmap
To list all document that are in the package
# rpm -qd nmap
To list all configuration file that are in the package
# rpm -qc nmap
To find the name of the RPM the ls command comes from
# rpm -qf /bin/ls
Shows dependencies for a specific package
# rpm -qR nmap
To see which parts of the package have been changed since installation
# rpm -V
To Verifies all installed packages and show which parts of the package have been changed since installation.
# rpm -Va
Extracting files from RPM packages
# rpm2cpio wonderwidgets-1.0-4.x86_64.rpm I cpio -id “*txt “
It will extract the package in its current location
Installing and Managing Software with yum
The yum command (yellowdog updater, modified) is a metapackage manager based on RPM and is the preferred tool for package management. It is very similar to APT package manager but cleaner and smarter.
This utility requires that the system has access to a software repository, local or remote. The main benefit of using um is that it automatically resolves dependencies by downloading and installing any additional required packages in order to successfully install the specified package.
Specifying Which Repository to Use
Create a file with a name that ends in .repo. In that file you need the following contents:
- [label] The .repo file can contain different repositories, each section starting with a label that identifies the specific repository.
- name= Use this to specify the name of the repository you want to use.
- baseurl= Contains the URL that points to the specific repository location.
Key Options in .repo Files
|[label]||The label used as an identifier in the repository file.|
|name=||The name of the repository.|
Refers to a URL where information about mirror servers for this server can be
obtained. Typically used for big online repositories only.
|baseurl=||The base URL where to go to find the RPM packages|
|gpgcheck=||Set to 1 if a GPG integrity check needs to be performed on the packages. If set to 1, a gpgkey is required.|
|gpgkey=||Specifies the location of the GPG key that is used to check package integrity.|
When creating a repository file, the baseurl parameter is the most important because it tells your server where to find the files that are to be installed.
This will often be an HTTP or FTP URL, but it can be a file-based URL as well.
Yum Log FILE : /var/log/yum.log
Creating Your Own Repository
- Insert the installation disk in your virtual machine. This mounts it on the directory /run/media/user/CentOS 7 x86_64. Alternatively, you can manually mount the ISO on the /mnt directory, using mount -o loop /path/to/centos.iso /mnt .
- Type mkdir /repo to create a directory /repo that can be used as repository.
- If you want to create a complete repository, containing all the required files, type cp $MOUNTPATH/Packages/* repo. (Replace $MOUNTPATH with the name of the directory on which the installation disk is mounted.) If you do not need a complete repository, you can copy just a few files from the installation disk to the /repo directory.
- Type yum install -y createrepo to ensure that the createrepo RPM package is Installed.
- Type createrepo /repo . This generates the repository metadata, which allows you to use your own repository.
- Now that you have created your own repository, you might as well start using it. In the /etc/yum.repos.d directory, create a file with the name my.repo. Make sure this file has the following contents:
- Type yum repolist to verify the availability of the newly created repository. It should show the name of the myrepo repository, including the number of packages that are offered through this repository.
Using yum Command
Using yum to Find Software Packages
To install packages with yum, you first need to know the exact name of the package. The yum search command can help you with that.
# yum search user
Because the yum search command looks in the package name and summary only, it often does not show what you need. You often need to look for packages containing a specific file.
The yum whatprovides or yum provides command will help.
# yum whatprovides */semanage
Getting More Information About Packages
# yum info httpd
To list yum repo on system
# yum repolist
Installing and Removing Software Packages
# yum install nmap
# yum remove nmap
Showing Lists of Packages
# yum list
It shows a list of all software packages that are available, including the repository they were installed from.
To show installed package
# yum list installed
To show installed package
# yum list packagename
# yum update (to update all)
# yum update httpd
Working with yum Package Groups
# yum groups list
It will list group by name
To show hidden groups
# yum groups list hidden
To get information about packages available in a group,
# yum groups info
# yum groups info “Basic Web Server”
Using yum History
# yum history list
Undoing Yum Action
# yum history undo 14
To list Kernel
# yum list kernel
Enabling yum Software Repositories
Enable and disable repositories with yum-config-manager. This will change the enabled parameter in the /etc/yum.repos.d/redhat.repo file.
To enable repo
# yum-config-manager –enable rhel-7-public-beta-debug-rpms
Though yum install and yum update also allow you to download packages, you can use another tool called yumdownloader to download individual packages from an accessible repository.
# yumdownloader –v dhclient