-
-
Save shekkbuilder/8899e9f57414206baf04 to your computer and use it in GitHub Desktop.
# do not rely on specific architecture | |
BuildArch: noarch | |
# suppress automatic detection of requirements | |
AutoReqProv: no |
### INSTALLATION ### | |
# install | |
rpm -i ${packagename}.rpm | |
# install with progress | |
rpm -ivh ${packagename}.rpm | |
# install in full-on debug mode | |
rpm -ivvvh ${packagename}.rpm | |
# install without running scripts | |
rpm -i ${packagename}.rpm --noscripts | |
# install even if this version is already installed | |
rpm -i ${packagename}.rpm --force | |
### UNINSTALLATION ### | |
# uninstall | |
rpm -e ${packagename} | |
# uninstall without running scripts | |
rpm -e ${packagename} --noscripts | |
# uninstall even if there are dependencies | |
rpm -e ${packagename} --nodeps | |
# uninstall all rpms containing "foo" in name | |
rpm -e `rpm -qa | grep foo` | |
### UPGRADE ### | |
# upgrade | |
rpm -U ${packagename}.rpm | |
# install without running scripts | |
rpm -U ${packagename}.rpm --noscripts | |
# update even if this version is already installed | |
rpm -U ${packagename}.rpm --force | |
### ANALYSIS OF UNINSTALLED RPM FILES ### | |
# print properties | |
rpm -qipv ${packagename}.rpm | |
# print filelist | |
rpm -qlpv ${packagename}.rpm | |
# print required dependencies | |
rpm -qpR ${packagename}.rpm | |
### ANALYSIS OF INSTALLED RPM FILES | |
# list all installed rpms containing "foo" in name | |
rpm -qa | grep foo | |
# print installed files of installed package | |
rpm -ql ${packagename} |
A Few Handy Queries
Below are some examples of situations you might find yourself in, and ways you can use RPM to get the information you need. Keep in mind that these are just examples. Don't be afraid to experiment!
Finding Config Files Based on a Program Name
You're setting up a new system, and you'd like to implement some system-wide aliases for people using the Bourne Again SHell, bash. The problem is you just can't remember the name of the system-wide initialization file used by bash, or where it resides:
rpm -qcf /bin/bash
/etc/bashrc
Rather than spending time trying to hunt down the file, RPM finds it for you in seconds.
Learning More About an Uninstalled Package
Practically any option can be combined with -qp to extract information from a .rpm file. Let's say you have an unknown .rpm file, and you'd like to know a bit more before installing it:
rpm -qpil foo.bar
Name : rpm Distribution: Red Hat Linux Vanderbilt
Version : 2.3 Vendor: Red Hat Software
Release : 1 Build Date: Tue Dec 24 09:07:59 1996
Install date: (none) Build Host: porky.redhat.com
Group : Utilities/System Source RPM: rpm-2.3-1.src.rpm
Size : 631157
Summary : Red Hat Package Manager
Description :
RPM is a powerful package manager, which can be used to build, install,
query, verify, update, and uninstall individual software packages. A
package consists of an archive of files, and package information,
including name, version, and description.
/bin/rpm
/usr/bin/find-provides
/usr/bin/find-requires
/usr/bin/gendiff
/usr/bin/rpm2cpio
/usr/doc/rpm-2.3-1
…
/usr/src/redhat/SOURCES
/usr/src/redhat/SPECS
/usr/src/redhat/SRPMS
By displaying the package information, we know that we have a package file containing RPM version 2.3. We can then peruse the file list, and see exactly what it would install before installing it.
Finding Documentation for a Specific Package
Picking on bash some more, you realize that your knowledge of the software is lacking. You'd like to see when it was installed on your system, and what documentation is available for it:
rpm -qid bash
Name :bash Distribution: Red Hat Linux (Picasso)
Version :1.14.6 Vendor: Red Hat Software
Release :2 Build Date: Sun Feb 25 13:59:26 1996
Install date:Mon May 13 12:47:22 1996 Build Host: porky.redhat.com
Group :Shells Source RPM: bash-1.14.6-2.src.rpm
Size :486557
Description :GNU Bourne Again Shell (bash)
/usr/doc/bash-1.14.6-2
/usr/doc/bash-1.14.6-2/NEWS
/usr/doc/bash-1.14.6-2/README
/usr/doc/bash-1.14.6-2/RELEASE
/usr/info/bash.info.gz
/usr/man/man1/bash.1
You never realized that there could be so much documentation for a shell!
Finding Similar Packages
Looking at bash's information, we see that it belongs to the group "Shells". You're not sure what other shell packages are installed on your system. If you can find other packages in the "Shells" group, you'll have found the other installed shells:
rpm -qa --queryformat '%10{NAME} %20{GROUP}\n' | grep -i shells
ash Shells
bash Shells
csh Shells
mc Shells
tcsh Shells
Now you can query each of these packages, and learn more about them, too. [1]
Finding Recently Installed Packages, Part I
You remember installing a new package a few days ago. All you know for certain is that the package installed a new command in the /bin directory. Let's try to find the package:
find /bin -type f -mtime -14 | rpm -qF
rpm-2.3-1
Looks like RPM version 2.3 was installed sometime in the last two weeks.
Finding Recently Installed Packages, Part II
Another way to see which packages were recently installed is to use the --queryformat option:
rpm -qa --queryformat '%{installtime} %{name}-%{version}-%{release} %{installtime:date}\n' | sort -nr +1 | sed -e 's/^[^ ]* //'
rpm-devel-2.3-1 Thu Dec 26 23:02:05 1996
rpm-2.3-1 Thu Dec 26 23:01:51 1996
pgp-2.6.3usa-2 Tue Oct 22 19:39:09 1996
…
pamconfig-0.50-5 Tue Oct 15 17:23:22 1996
setup-1.5-1 Tue Oct 15 17:23:21 1996
By having RPM include the installation time in numeric form, it was simple to sort the packages and then use sed to remove the user-unfriendly numeric time.
Finding the Largest Installed Packages
Let's say that you're running low on disk space, and you'd like to see what packages you have installed, along with the amount of space each package takes up. You'd also like to see the largest packages first, so you can get back as much disk space as possible:
rpm -qa --queryformat '%{name-%{version}-%{release} %{size}\n' | sort -nr +1
kernel-source-2.0.18-5 20608472
tetex-0.3.4-3 19757371
emacs-el-19.34-1 12259914
…
rootfiles-1.3-1 3494
mkinitrd-1.0-1 1898
redhat-release-4.0-1 22
If you don't build custom kernels, or use TeX, it's easy to see how much space could be reclaimed by removing those packages.
Notes
[1]
Did you see this example and say to yourself, "Hey, they could've used the -g option to query for that group directly"? If you did, you've been paying attention. This is a more general way of searching the RPM database for information: we just happened to search by group in this example.
Some Facts about RPM (RedHat Package Manager)
There are five basic modes for RPM command
Where to find RPM packages
Below is the list of rpm sites, where you can find and download all RPM packages.
Read Also :
Please remember you must be root user when installing packages in Linux, with the root privileges you can manage rpm commands with their appropriate options.
Always check the PGP signature of packages before installing them on your Linux systems and make sure its integrity and origin is OK. Use the following command with –checksig (check signature) option to check the signature of a package called pidgin.
[root@tecmint]# rpm --checksig pidgin-2.7.9-5.el6.2.i686.rpm
pidgin-2.7.9-5.el6.2.i686.rpm: rsa sha1 (md5) pgp md5 OK
For installing an rpm software package, use the following command with -i option. For example, to install an rpm package called pidgin-2.7.9-5.el6.2.i686.rpm.
[root@tecmint]# rpm -ivh pidgin-2.7.9-5.el6.2.i686.rpm
Preparing... ########################################### [100%]
1:pidgin ########################################### [100%]
RPM command and options
Let’s say you would like to do a dependency check before installing or upgrading a package. For example, use the following command to check the dependencies of BitTorrent-5.2.2-1-Python2.4.noarch.rpm package. It will display the list of dependencies of package.
[root@tecmint]# rpm -qpR BitTorrent-5.2.2-1-Python2.4.noarch.rpm
/usr/bin/python2.4
python >= 2.3
python(abi) = 2.4
python-crypto >= 2.0
python-psyco
python-twisted >= 2.0
python-zopeinterface
rpmlib(CompressedFileNames) = 2.6
RPM command and options
If you know that all needed packages are already installed and RPM is just being stupid, you can ignore those dependencies by using the option –nodeps (no dependencies check) before installing the package.
[root@tecmint]# rpm -ivh --nodeps BitTorrent-5.2.2-1-Python2.4.noarch.rpm
Preparing... ########################################### [100%]
1:BitTorrent ########################################### [100%]
The above command forcefully install rpm package by ignoring dependencies errors, but if those dependency files are missing, then the program will not work at all, until you install them.
5. How to check an Installed RPM Package
Using -q option with package name, will show whether an rpm installed or not.
[root@tecmint]# rpm -q BitTorrent
BitTorrent-5.2.2-1.noarch
To view all the files of an installed rpm packages, use the -ql (query list) with rpm command.
[root@tecmint]# rpm -ql BitTorrent
/usr/bin/bittorrent
/usr/bin/bittorrent-console
/usr/bin/bittorrent-curses
/usr/bin/bittorrent-tracker
/usr/bin/changetracker-console
/usr/bin/launchmany-console
/usr/bin/launchmany-curses
/usr/bin/maketorrent
/usr/bin/maketorrent-console
/usr/bin/torrentinfo-console
Use the following rpm command with -qa (query all) option, will list all the recently installed rpm packages.
[root@tecmint]# rpm -qa --last
BitTorrent-5.2.2-1.noarch Tue 04 Dec 2012 05:14:06 PM BDT
pidgin-2.7.9-5.el6.2.i686 Tue 04 Dec 2012 05:13:51 PM BDT
cyrus-sasl-devel-2.1.23-13.el6_3.1.i686 Tue 04 Dec 2012 04:43:06 PM BDT
cyrus-sasl-2.1.23-13.el6_3.1.i686 Tue 04 Dec 2012 04:43:05 PM BDT
cyrus-sasl-md5-2.1.23-13.el6_3.1.i686 Tue 04 Dec 2012 04:43:04 PM BDT
cyrus-sasl-plain-2.1.23-13.el6_3.1.i686 Tue 04 Dec 2012 04:43:03 PM BDT
Type the following command to print the all the names of installed packages on your Linux system.
[root@tecmint]# rpm -qa
initscripts-9.03.31-2.el6.centos.i686
polkit-desktop-policy-0.96-2.el6_0.1.noarch
thunderbird-17.0-1.el6.remi.i686
If we want to upgrade any RPM package “–U” (upgrade) option will be used. One of the major advantages of using this option is that it will not only upgrade the latest version of any package, but it will also maintain the backup of the older package so that in case if the newer upgraded package does not run the previously installed package can be used again.
[root@tecmint]# rpm -Uvh nx-3.5.0-2.el6.centos.i686.rpm
Preparing... ########################################### [100%]
1:nx ########################################### [100%]
To un-install an RPM package, for example we use the package name nx, not the original package name nx-3.5.0-2.el6.centos.i686.rpm. The -e (erase) option is used to remove package.
[root@tecmint]# rpm -evv nx
The –nodeps (Do not check dependencies) option forcefully remove the rpm package from the system. But keep in mind removing particular package may break other working applications.
[root@tecmint]# rpm -ev --nodeps vsftpd
Let’s say, you have list of files and you would like to find out which package belongs to these files. For example, the following command with -qf (query file) option will show you a file /usr/bin/htpasswd is own by package httpd-tools-2.2.15-15.el6.centos.1.i686.
[root@tecmint]# rpm -qf /usr/bin/htpasswd
httpd-tools-2.2.15-15.el6.centos.1.i686
Let’s say you have installed an rpm package and want to know the information about the package. The following -qi (query info) option will print the available information of the installed package.
[root@tecmint]# rpm -qi vsftpd
Name : vsftpd Relocations: (not relocatable)
Version : 2.2.2 Vendor: CentOS
Release : 11.el6 Build Date: Fri 22 Jun 2012 01:54:24 PM BDT
Install Date: Mon 17 Sep 2012 07:55:28 PM BDT Build Host: c6b8.bsys.dev.centos.org
Group : System Environment/Daemons Source RPM: vsftpd-2.2.2-11.el6.src.rpm
Size : 351932 License: GPLv2 with exceptions
Signature : RSA/SHA1, Mon 25 Jun 2012 04:07:34 AM BDT, Key ID 0946fca2c105b9de
Packager : CentOS BuildSystem http://bugs.centos.org
URL : http://vsftpd.beasts.org/
Summary : Very Secure Ftp Daemon
Description :
vsftpd is a Very Secure FTP daemon. It was written completely from
scratch.
You have download a package from the internet and want to know the information of a package before installing. For example, the following option -qip (query info package) will print the information of a package sqlbuddy.
[root@tecmint]# rpm -qip sqlbuddy-1.3.3-1.noarch.rpm
Name : sqlbuddy Relocations: (not relocatable)
Version : 1.3.3 Vendor: (none)
Release : 1 Build Date: Wed 02 Nov 2011 11:01:21 PM BDT
Install Date: (not installed) Build Host: rpm.bar.baz
Group : Applications/Internet Source RPM: sqlbuddy-1.3.3-1.src.rpm
Size : 1155804 License: MIT
Signature : (none)
Packager : Erik M Jacobs
URL : http://www.sqlbuddy.com/
Summary : SQL Buddy â Web based MySQL administration
Description :
SQLBuddy is a PHP script that allows for web-based MySQL administration.
To get the list of available documentation of an installed package, use the following command with option -qdf (query document file) will display the manual pages related to vmstat package.
[root@tecmint]# rpm -qdf /usr/bin/vmstat
/usr/share/doc/procps-3.2.8/BUGS
/usr/share/doc/procps-3.2.8/COPYING
/usr/share/doc/procps-3.2.8/COPYING.LIB
/usr/share/doc/procps-3.2.8/FAQ
/usr/share/doc/procps-3.2.8/NEWS
/usr/share/doc/procps-3.2.8/TODO
Verifying a package compares information of installed files of the package against the rpm database. The -Vp (verify package) is used to verify a package.
[root@tecmint downloads]# rpm -Vp sqlbuddy-1.3.3-1.noarch.rpm
S.5....T. c /etc/httpd/conf.d/sqlbuddy.conf
Type the following command to verify all the installed rpm packages.
[root@tecmint]# rpm -Va
S.5....T. c /etc/rc.d/rc.local
.......T. c /etc/dnsmasq.conf
.......T. /etc/ld.so.conf.d/kernel-2.6.32-279.5.2.el6.i686.conf
S.5....T. c /etc/yum.conf
S.5....T. c /etc/yum.repos.d/epel.repo
To verify RHEL/CentOS/Fedora packages, you must import the GPG key. To do so, execute the following command. It will import CentOS 6 GPG key.
[root@tecmint]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6
To print all the imported GPG keys in your system, use the following command.
[root@tecmint]# rpm -qa gpg-pubkey*
gpg-pubkey-0608b895-4bd22942
gpg-pubkey-7fac5991-4615767f
gpg-pubkey-0f2672c8-4cd950ee
gpg-pubkey-c105b9de-4e0fd3a3
gpg-pubkey-00f97f56-467e318a
gpg-pubkey-6b8d79e6-3f49313d
gpg-pubkey-849c449f-4cb9df30
Sometimes rpm database gets corrupted and stops all the functionality of rpm and other applications on the system. So, at the time we need to rebuild the rpm database and restore it with the help of following command.
[root@tecmint]# cd /var/lib
[root@tecmint]# rm __db*
[root@tecmint]# rpm --rebuilddb
[root@tecmint]# rpmdb_verify Packages