- 20 Practical Examples of RPM Commands in Linux
- Some Facts about RPM (RedHat Package Manager)
- There are five basic modes for RPM command
- Where to find RPM packages
- 1. How to Check an RPM Signature Package
- 2. How to Install an RPM Package
- 3. How to check dependencies of RPM Package before Installing
- 4. How to Install a RPM Package Without Dependencies
- 5. How to check an Installed RPM Package
- 6. How to List all files of an installed RPM package
- 7. How to List Recently Installed RPM Packages
- 8. How to List All Installed RPM Packages
- 9. How to Upgrade a RPM Package
- 10. How to Remove a RPM Package
- 11. How to Remove an RPM Package Without Dependencies
- 12. How to Query a file that belongs which RPM Package
- 13. How to Query a Information of Installed RPM Package
- 14. Get the Information of RPM Package Before Installing
- 15. How to Query documentation of Installed RPM Package
- 16. How to Verify a RPM Package
- 17. How to Verify all RPM Packages
- 18. How to Import an RPM GPG key
- 19. How to List all Imported RPM GPG keys
- 20. How To rebuild Corrupted RPM Database
- If You Appreciate What We Do Here On TecMint, You Should Consider:
- ИТ База знаний
- Полезно
- Навигация
- Серверные решения
- Телефония
- Корпоративные сети
- RPM — установка и использование в Linux
- Установка
- Удаление
- Полезно?
- Почему?
- How to create a Linux RPM package
- More about automation
- What is an RPM package?
- How to create an RPM package
- Installing the required software
- Place the script in the designated directory
- Create a .spec file
- Checking the .spec file on error (rpmlint)
- Building the package (rpmbuild)
- Installing the RPM package
- Verify the package has been installed
- See what’s in the RPM package
- Removing the RPM package
20 Practical Examples of RPM Commands in Linux
RPM (Red Hat Package Manager) is an default open source and most popular package management utility for Red Hat based systems like (RHEL, CentOS and Fedora). The tool allows system administrators and users to install, update, uninstall, query, verify and manage system software packages in Unix/Linux operating systems. The RPM formerly known as .rpm file, that includes compiled software programs and libraries needed by the packages. This utility only works with packages that built on .rpm format.
20 Most Useful RPM Command Examples
This article provides some useful 20 RPM command examples that might be helpful to you. With the help of these rpm command you can managed to install, update, remove packages in your Linux systems.
Some Facts about RPM (RedHat Package Manager)
- RPM is free and released under GPL (General Public License).
- RPM keeps the information of all the installed packages under /var/lib/rpm database.
- RPM is the only way to install packages under Linux systems, if you’ve installed packages using source code, then rpm won’t manage it.
- RPM deals with .rpm files, which contains the actual information about the packages such as: what it is, from where it comes, dependencies info, version info etc.
There are five basic modes for RPM command
- Install : It is used to install any RPM package.
- Remove : It is used to erase, remove or un-install any RPM package.
- Upgrade : It is used to update the existing RPM package.
- Verify : It is used to verify an RPM packages.
- Query : It is used query any RPM package.
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.
1. How to Check an RPM Signature Package
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.
2. How to Install an RPM Package
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.
RPM command and options
- -i : install a package
- -v : verbose for a nicer display
- -h: print hash marks as the package archive is unpacked.
3. How to check dependencies of RPM Package before Installing
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.
RPM command and options
- -q : Query a package
- -p : List capabilities this package provides.
- -R: List capabilities on which this package depends..
4. How to Install a RPM Package Without Dependencies
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.
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.
6. How to List all files of an installed RPM package
To view all the files of an installed rpm packages, use the -ql (query list) with rpm command.
7. How to List Recently Installed RPM Packages
Use the following rpm command with -qa (query all) option, will list all the recently installed rpm packages.
8. How to List All Installed RPM Packages
Type the following command to print the all the names of installed packages on your Linux system.
9. How to Upgrade a RPM Package
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.
10. How to Remove a RPM Package
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.
11. How to Remove an RPM Package Without Dependencies
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.
12. How to Query a file that belongs which RPM Package
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.
13. How to Query a Information of Installed RPM Package
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.
14. Get the Information of RPM Package Before Installing
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.
15. How to Query documentation of Installed RPM Package
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.
16. How to Verify a RPM Package
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.
17. How to Verify all RPM Packages
Type the following command to verify all the installed rpm packages.
18. How to Import an RPM GPG key
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.
19. How to List all Imported RPM GPG keys
To print all the imported GPG keys in your system, use the following command.
20. How To rebuild Corrupted RPM Database
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.
If You Appreciate What We Do Here On TecMint, You Should Consider:
TecMint is the fastest growing and most trusted community site for any kind of Linux Articles, Guides and Books on the web. Millions of people visit TecMint! to search or browse the thousands of published articles available FREELY to all.
If you like what you are reading, please consider buying us a coffee ( or 2 ) as a token of appreciation.
We are thankful for your never ending support.
Источник
ИТ База знаний
Курс по Asterisk
Полезно
— Узнать IP — адрес компьютера в интернете
— Онлайн генератор устойчивых паролей
— Онлайн калькулятор подсетей
— Калькулятор инсталляции IP — АТС Asterisk
— Руководство администратора FreePBX на русском языке
— Руководство администратора Cisco UCM/CME на русском языке
— Руководство администратора по Linux/Unix
Навигация
Серверные решения
Телефония
FreePBX и Asterisk
Настройка программных телефонов
Корпоративные сети
Протоколы и стандарты
RPM — установка и использование в Linux
Вам пакет нужен? Нет, я со своим.
RPM (Red Hat Package Manager) — это наиболее популярная утилита управления пакетами для Linux систем на базе Red Hat, таких как (RHEL, CentOS и Fedora). Она используется для установки, удаления, обновления, запроса и проверки пакетов программного обеспечения. Пакет состоит из архива файлов и информации о пакете, включая имя, версию и описание. Формат файлов также называется RPM.
Мини — курс по виртуализации
Знакомство с VMware vSphere 7 и технологией виртуализации в авторском мини — курсе от Михаила Якобсена
Есть несколько способов откуда можно взять пакеты RPM: CD/DVD с программным обеспечением, CentOS Mirror, RedHat (нужен аккаунт) или любые открытые сайты репозитория.
В RPM используется несколько основных режимов команд: Install (используется для установки любого пакета RPM), Remove (используется для удаления, стирания или деинсталляции пакета), Upgrade (используется для обновления существующего пакета), Query (используется для запроса пакета) и Verify (используется для проверки пакетов RPM).
Рассмотрим это на примере. У нас есть пакет, и теперь посмотрим, что мы можем с ним делать.
Установка
Как узнать информацию о пакете RPM без установки?
После того, как мы скачали пакет мы хотим узнать информацию о пакете перед установкой. Мы можем использовать -qipoption (запрос информации о пакете), чтобы вывести информацию о пакете.
Как установить RPM пакет?
Мы можем использовать параметр -ivh для установки определенного пакета, как показано ниже.
Как проверить установленный пакет RPM?
Мы можем использовать параметр -q с именем пакета, и он покажет, установлен ли пакет или нет.
Как вывести список всех файлов для определенного установленного пакета RPM?
Мы можем перечислить все файлы установленных пакетов rpm, используя опцию -ql с командой rpm.
Как вывести список недавно установленных пакетов RPM?
Мы можем использовать параметр -qa с параметром —last, в котором будут перечислены все недавно установленные пакеты rpm.
Как установить RPM пакет без зависимостей?
Мы можем использовать параметры -ivh с параметром —nodeps для проверки отсутствия зависимостей, чтобы установить конкретный пакет без зависимостей, как показано ниже.
Как заменить установленный пакет RPM?
Мы можем использовать параметры -ivh –replacepkgs для замены установленного пакета.
Удаление
Как удалить пакет RPM?
Мы можем использовать параметр -e для удаления определенного пакета, установленного без зависимостей. Обратите внимание, что удаление определенного пакета может нарушить работу других приложений.
Обновление
Как обновить установленный пакет RPM?
Для обновления пакета мы используем параметры -Uvh
Запрос
Как запросить все установленные пакеты?
Мы можем использовать параметры -a вместе с q для запроса всех установленных пакетов на сервере.
Как запросить конкретный пакет?
Мы можем использовать команду grep, чтобы узнать, установлен ли конкретный пакет или нет.
Как запросить файл, который принадлежит пакету RPM?
Чтобы узнать к какому пакету RPM относится файл /usr/lib64/libGeoIP.so.1.5.0. используем следующую команду.
Проверка
Как получить информацию для конкретного пакета?
Мы можем использовать параметры -i вместе с q, чтобы получить информацию для конкретного пакета, как показано ниже.
Как проверить RPM пакет?
Мы можем проверить пакет, сравнив информацию об установленных файлах пакета с базой данных rpm, используя опцию -Vp.
Как проверить все пакеты RPM?
Мы можем проверить все установленные пакеты rpm, используя опцию -Va
Онлайн курс по Linux
Мы собрали концентрат самых востребованных знаний, которые позволят тебе начать карьеру администратора Linux, расширить текущие знания и сделать уверенный шаг к DevOps
Полезно?
Почему?
😪 Мы тщательно прорабатываем каждый фидбек и отвечаем по итогам анализа. Напишите, пожалуйста, как мы сможем улучшить эту статью.
😍 Полезные IT – статьи от экспертов раз в неделю у вас в почте. Укажите свою дату рождения и мы не забудем поздравить вас.
Источник
How to create a Linux RPM package
Photo by Ketut Subiyanto from Pexels
This article shows you how to package a script into an RPM file for easy installation, updating, and removal from your Linux systems. Before I jump into the details, I’ll explain what an RPM package is, and how you can install, query, remove, and, most importantly, create one yourself.
This article covers:
- What an RPM package is.
- How to create an RPM package.
- How to install, query, and remove an RPM package.
More about automation
What is an RPM package?
RPM stands for Red Hat Package Manager. It was developed by Red Hat and is primarily used on Red Hat-based Linux operating systems (Fedora, CentOS, RHEL, etc.).
An RPM package uses the .rpm extension and is a bundle (a collection) of different files. It can contain the following:
- Binary files, also known as executables ( nmap , stat , xattr , ssh , sshd , and so on).
- Configuration files ( sshd.conf , updatedb.conf , logrotate.conf , etc.).
- Documentation files ( README , TODO , AUTHOR , etc.).
The name of an RPM package follows this format:
Some packages also include a shorthand version of the distribution they were built for, such as:
How to create an RPM package
You’ll need the following components to build an RPM package:
- A workstation or a virtual machine running an RPM-based distribution, such RHEL or Fedora.
- Software to build the package.
- Source code to package.
- SPEC file to build the RPM.
Installing the required software
The following packages need to be installed to build the RPM package:
After installing rpmdevtools , create the file tree you need to build RPM packages:
You build RPM packages as a normal (not root) user, so your build environment is placed into your home directory. It contains this directory structure:
- The BUILD directory is used during the build process of the RPM package. This is where the temporary files are stored, moved around, etc.
- The RPMS directory holds RPM packages built for different architectures and noarch if specified in .spec file or during the build.
- The SOURCES directory, as the name implies, holds sources. This can be a simple script, a complex C project that needs to be compiled, a pre-compiled program, etc. Usually, the sources are compressed as .tar.gz or .tgz files.
- The SPEC directory contains the .spec files. The .spec file defines how a package is built. More on that later.
- The SRPMS directory holds the .src.rpm packages. A Source RPM package doesn’t belong to an architecture or distribution. The actual .rpm package build is based on the .src.rpm package.
A .src.rpm package is very flexible, because it can be built and re-built on every other RPM-based distribution and architecture.
You’re now familiar with what each directory holds, so now create a simple script to distribute:
This creates a shell script called hello.sh , which prints «Hello world» to the terminal. It’s simple, but it’s enough to demonstrate packaging.
Place the script in the designated directory
To build a package for your script, you must put your script in the directory that the RPM build system expects it to be in. Create a directory for it, using semantic versioning as most projects do, and then move hello.sh into it:
Most source code is distributed as an archive, so use the tar command to create an archive file:
Then move the tarball you’ve just created into the SOURCES directory:
Create a .spec file
An RPM package is defined by a .spec file. The syntax of a .spec file is strict, but rpmdev can generate a boilerplate file for you:
This generates a file called hello.spec , which you must move to the SPECS directory. Run tree
/rpmbuild to see what the directory structure looks like:
The generated hello.spec file provides a good starting point, but it doesn’t have any specific information about what you’re building. The generated .spec file assumes that I am going to compile and build software.
You’re packaging a Bash script, so there’s some simplification you can do. For instance, there’s no Build process because there’s no code to compile. I’ve added BuildArch: noarch because this package is valid for 32-bit, 64-bit, Arm, and any other CPU architecture that runs Bash.
I’ve also added Requires: bash so that the package ensures that Bash is installed. This simple «hello world» script runs on any shell, of course, but that’s not true for all scripts, so this is a good way to demonstrate dependencies.
As you can tell, there are a lot of shortcuts in .spec files. They’re called macros, and there’s an excellent list of what’s available in the Fedora packaging documentation. It’s important to use macros in your .spec files. They help ensure consistency across all RPM systems, they help you avoid mistakes in filenames and version numbering, and they make it easier to update the .spec file when you release a new version of your script.
For example, it’s required that you specify exactly which files are installed under the %files section. Here I’ve explicitly put the following line:
This works because I want the script to go to % (which is a macro that translates to /usr/bin by default, but is configurable when users want to install to a different location, such as /usr/local/bin ). You can verify macro values by running:
Other useful macros:
- %
name of the package (as defined in the Name: field) - %
version of the package (as defined in the Version: field) - % <_datadir>shared data ( /usr/sbin by default)
- % <_sysconfdir>configuration directory ( /etc by default)
Checking the .spec file on error (rpmlint)
The rpmlint command can find errors in .spec files:
There are 2 errors reported, but they’re both acceptable. There’s no code to build, so there’s no need for a %build section, and the source archive is a local file and has no network URL.
Everything looks good.
Building the package (rpmbuild)
To build the RPM package, use the rpmbuild command. Earlier in this tutorial, I mentioned the difference between the .src.rpm (Source RPM package) and the .rpm package.
To create the .src rpm package:
The flags -bs have the following meanings:
To create the binary .rpm package:
The flags -bb have the following meanings:
Use -ba to build both.
After the build process is finished, you have the following directory structure:
Installing the RPM package
After a successful build of the package, you can install the RPM package using the dnf command:
It can alternately be installed with the rpm command directly:
Verify the package has been installed
To verify the package has correctly been installed, run the following command:
The %changelog entry of a package can be viewed, too:
See what’s in the RPM package
It’s easy to see which files an RPM package contains:
Removing the RPM package
Removing the package from the system is just as easy as installing it. You can use the dnf command:
Источник