Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Rpm package Management for getting started with Linux

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Software package Management for getting started with Linux

There are many kinds of package management mechanisms in linux, but in systems such as redhat and centos, the same mechanism is used, that is, rpm package management mechanism, and of course, there are different mechanisms used by other versions of linux:

Debian: make .deb file, dpkg package manager

Redhat: use .rpm file, rpm package manager

There are two types of software packages in use (source packages and binary packages):

Source code package: generally provides a combination of some source code modules and compilation steps of the compressed file, command format such as:

Name-version.tar. {gz | bz2 | xz}, etc. A source code package is listed here:

[root@localhost ~] # ls-l tengine-1.4.2.tar.gz

-rw-r--r-- 1 root root 1185902 Aug 15 18:57 tengine-1.4.2.tar.gz

Binary rpm package: software that implements the compiled package and whose functional modules have been set beforehand. The command format is as follows:

The composition of the rpm package:

Main package:

Name-version-release.arch.rpm for example:

Bind-9.7.1-1.e15.i586.rpm

Subpackage:

Name-toolname-9.7.1-1.e15.i586.rpm for example:

Bind-libs-9.7.1-1.e15.i586.rpm

Bind-utils-9.7.1-1.e15.i586.rpm

Package name format:

Name-version-release.arch.rpm

Bind-major.minor.release-release.arch.rpm

Version number description:

Major version number: significant improvements in the software package

This version number: a major change has taken place in a sub-function.

Issue number: fixed part of bug and adjusted some functions

The core functions of the Software Manager:

1. Make a software package

2. Install, uninstall, upgrade, query and verify

Note: the rpm package itself has dependencies, and when installing the package, you need to install the dependent package first.

Classification of package tools:

Front tool: yum,apt-get

Back-end tool: rpm,dpt

Rpm command:

Rpm rpmduild

Rpm database: / var/lib/rpm

Note: if some files in / var/lib/rpm are just destroyed, you can create or initialize the database through the command, but if the files are deleted, their database information cannot be recovered, so back up this from time to time.

How to use the rpm command:

1. Install:

Rpm-I / PATH/TO/PACKAGE_FILE Note: here is the path to the package file

-h: shows progress with a # symbol, with each # symbol indicating 2% progress

-v: show detailed process

-vv: show a more detailed process

Rpm-ivh / PATH/TO/PACHAGE_FILE hint: this is generally used in combination to show its installation status.

-- nodeps: ignore dependencies

-- replacepkgs: reinstall and replace the original installation

-- replacefiles: the original file will be replaced

-- force: forced installation can be reinstalled or downgraded

-- nosgnature: do not check the legality of the source

-- nodigest: integrity is not checked

-- noscripts: do not execute the package steps

% pre: step before installation;-- nopre

% post: post-installation script;-- nopost

% preun: step before uninstalling;-- nopre

% postun: step after uninstalling;-- nopost

Note: sometimes for packages of unknown origin, the above options can be used to prevent dangerous programs in the package.

2. Upgrade:

Rpm-Uvh / PATH/TO/NEW_PACKAGE_FILE: upgrade if the old version is installed, otherwise reinstall

Rpm-Fvh / PATH/TO/NEW_PACKAGE_FILE: upgrade if there is an older version, otherwise exit

-- oldpackage: downgrade

Note:

1. Do not upgrade or downgrade the system kernel. Linux executes the coexistence of multiple kernels, so you can install the new kernel directly.

2. If kernel is upgraded, if the configuration file in the original kernel is changed before the upgrade, the configuration file of the original kernel will be renamed to the file of filename.rpmnew and the file of the new kernel will be used after the upgrade.

3. Query

Rpm-Q PACKAGE_NAME: query whether the specified package has been installed

Rpm-qa: view all installed packages

Rpm-qi PACKAGE_NAME: query the description of the installation package of the specified package

Rpm-ql PACKAGE_NAME: query the list of files generated after the specified package is installed

Rpm-qc PACKAGE_NAME: query the configuration file generated after the specified package is installed

Rpm-qd PACKAGE_NAME: query the help files for the specified package installation

Rpm-- scripts PACKAGE_NAME: the query indicates the steps contained in the package

Rpm-qf / PATH/TO/SOMEFILE: query which rpm package the specified file is generated after installation

Rpm-- whatprovides CAPABILTTY: which package the query keyword or command is replaced by

Rpm-- whatrequires CAPABILTTY: query which package or command is dependent on

If the package has not been installed, we need to query its description and the files that will be generated after installation:

Rpm-qpi / PATH/TO/PACKAGE_FILES View package file information

Rpm-qpl / PATH/TO/PACKAGE_FILES to see which files are generated after the package is installed

If the installed file is missing and there is a configuration instead of reinstalling to overwrite the file, you can handle it through the tool:

Rpm2cpio package file | cpio-itv preview package file

Rpm2cpio package file | cpio-idv "* .conf" expand the package file

Note: it can be a specific path or file wildcard

Rpm-- scripts / PACKAGE_NAME: the footstep file generated by the query package

-R: query the specified package dependent libraries and software

-- provides: lists the tools and commands provided by the specified package

-- changelog: query the change information of the rpm package

4. Uninstall

Rpm-e PACKAGENAME

Rpm-erase PACKAGENME

-- nodeps: ignore dependencies and still uninstall

-- test: just test the uninstall process, not really uninstall it

-- noscripts: do not run the steps of the process when uninstalling

-- notriggers: do not start the trigger

-- allmatches: uninstall all matching files

5. Check

Rpm-V PACKNAME PACKAGE_NAME

Information description:

S stands for software change information

M displays permission information

5 display encrypted information

D displays the primary and secondary device number

L displays the number of link paths

U display package user

G display package user group

T display change time

P display update comparison properties

6. Verify the validity and integrity of the source of the software package:

Key file:

/ etc/pki/rpm-gpg/ directory:

RPM-GPG-KEY-readhat-release

RPM-GPG-KEY-centos-release

Check the integrity of the package:

Rpm-K / path/to/rpmfile

Information description:

Dsp, gpg: verify the validity of the source, that is, verify the previous field. You can skip this item using-- nosignature

Sha1, md5: verify the integrity of the package, you can use-- nodigest, skip this item

Before that, you need to have a public key. You can use the command to import the public key:

Rpm--import / etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-7

Uninstall the public key:

Rpm-qa gpg-pubkey* to find out the public key name

Rpm-e gpg-pubkey. Uninstall public key

7. Rebuild the database

Database file path: / var/lib/rpm/

Use the command to rebuild:

Rpm

-- rebuilddb: if the database is rebuilt, it will be re-established.

-- initdb: initialize the database. No database will be created until it is created. If there is no database, no database will be created.

Case study:

# Mount CentOS image to / mnt/iso folder

[root@mzf ~] # mount / dev/cdrom / mnt/iso/mount: block device / dev/sr0 is write-protected, mounting read-only

# cd enter the / mnt/iso directory

[root@mzf ~] # cd / mnt/iso/ [root@mzf iso] # pwd/mnt/iso

# check that the package is stored in Packages

[root@mzf iso] # lsCentOS_BuildTag EULA p_w_picpaths Packages repodata RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Testing-6 EFI GPL isolinux RELEASE-NOTES-en-US.html RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Security-6 TRANS.TBL

# cd to this Packages directory

[root@mzf iso] # cd Packages/

# find the tree software

[root@mzf Packages] # find. /-name "tree-1.5.3-3.el6.x86_64.rpm". / tree-1.5.3-3.el6.x86_64.rpm

# found to have been installed

[root@mzf Packages] # rpm-ivh tree-1.5.3-3.el6.x86_64.rpm Preparing... # [100%] package tree-1.5.3-3.el6.x86_64 is already installed

# then uninstall this file first

[root@mzf Packages] # rpm-e tree

# install again, showing the progress of successful installation

[root@mzf Packages] # rpm-ivh tree-1.5.3-3.el6.x86_64.rpm Preparing... # [100%] 1:tree #

# install zsh found that it has been installed

[root@mzf Packages] # rpm-ivh zsh-4.3.11-4.el6.centos.2.x86_64.rpm Preparing... # [100%] package zsh-4.3.11-4.el6.centos.2.x86_64 is already installed

# use-- force to force installation and overwrite previous installation

[root@mzf Packages] # rpm-ivh-- force zsh-4.3.11-4.el6.centos.2.x86_64.rpm Preparing... # [100%] 1:zsh #

# query whether bind has been installed and find that it is only some libraries and tools

[root@mzf Packages] # rpm-qa | grep'^ bind'bind-libs-9.8.2-0.47.rc1.el6.x86_64bind-utils-9.8.2-0.47.rc1.el6.x86_64

# install a server configuration that shows that this package depends on the bind-9.8.2-0.47.rc1.el6 package

[root@mzf Packages] # rpm-ivh bind-chroot-9.8.2-0.47.rc1.el6.x86_64.rpm error: Failed dependencies:bind = 32 0.47.rc1.el6.x86_64.rpm error 9.8.2-0.47.rc1.el6 is needed by bind-chroot-32:9.8.2-0.47.rc1.el6.x86_64

# then you can choose to install together, or you can ignore or force the installation.

[root@mzf Packages] # rpm-ivh-nodeps-force bind-chroot-9.8.2-0.47.rc1.el6.x86_64.rpm Preparing... # [100%] 1:bind-chroot warning: group named does not exist-using rootwarning: group named does not exist-using root%) warning: group named does not exist-using root%) warning: group named does not exist-using root%)

Description: although installed, but show some error messages, because there is no main configuration file, here we still install together

[root@mzf Packages] # rpm-ivh bind-9.8.2-0.47.rc1.el6.x86_64.rpm Preparing... # [100%] 1:bind warning: / etc/sysconfig/named created as / etc/sysconfig/named.rpmnew### [100%]

# Uninstall the software you just installed

[root@mzf Packages] # rpm-e bind-chroot# has no information indicating that it has been installed successfully

# verify the validity of the source of the package. It is normal here.

[root@mzf Packages] # rpm-K bind-chroot-9.8.2-0.47.rc1.el6.x86_64.rpm bind-chroot-9.8.2-0.47.rc1.el6.x86_64.rpm: rsa sha1 (md5) pgp md5 OK

# and verification is handled through public key files. If there are no such files, invalidation will be checked.

[root@mzf Packages] # ls / etc/pki/rpm-gpg/RPM-GPG-KEY-CentOS-6 RPM-GPG-KEY-CentOS-Debug-6 RPM-GPG-KEY-CentOS-Security-6 RPM-GPG-KEY-CentOS-Testing-6

# Import key through command:

[root@mzf Packages] # rpm-- import / mnt/iso/RPM-GPG-KEY-CentOS-6

# View the key just installed

[root@mzf Packages] # rpm-qa | grep 'gpg.*key'gpg-pubkey-c105b9de-4e0fd3a3

# Uninstall this key

[root@mzf Packages] # rpm-e gpg-pubkey

If some files of the installed software are deleted or destroyed, how to restore only the specified files and not reinstall them?

# View the path of the tree execution file

[root@mzf Packages] # which tree/usr/bin/tree

# Delete out the tree execution file

[root@mzf Packages] # rm-f / usr/bin/tree

# this command cannot be found by executing it again

[root@mzf Packages] # tree-bash: tree: command not found

# write the list of files generated by rpm package as a data stream through rpm2cpio and send it to cpio for viewing

[root@mzf Packages] # rpm2cpio. / tree-1.5.3- 3.el6.x86_64.rpm | cpio-tv-rwxr-xr-x 1 root root 41136 Jan 14 2015. / usr/bin/treedrwxr-xr-x 2 root root 0 Jan 14 2015. / usr/share/doc/tree-1.5.3-rw-r--r-- 1 root root 18009 Aug 13 2004. / usr/share/doc/tree-1.5.3/LICENSE- Rw-r--r-- 1 root root 4167 Oct 20 2009. / usr/share/doc/tree-1.5.3/README-rw-r--r-- 1 root root 3375 Jan 14 2015. / usr/share/man/man1/tree.1.gz

# expand the current folder by default according to the instructions shown above

# so let's switch to the home directory

[root@mzf Packages] # cd

# expand only the tree command

[root@mzf~] # rpm2cpio / mnt/iso/Packages/tree-1.5.3-3.el6.x86_64.rpm | cpio-idv. / usr/bin/tree./usr/bin/tree132 blocks

# copy this command to the directory where the original tree command is located

[root@mzf ~] # cp usr/bin/tree / usr/bin/tree

# found that the tree command can be used again

[root@mzf ~] # tree. ├── anaconda-ks.cfg ├── checkdisk.sh

Rebuild Library Fil

# query library files

[root@mzf ~] # ls / var/lib/rpm/Basenames _ _ db.001 _ _ db.003 Dirnames Group Name Packages Provideversion Requirename Sha1header TriggernameConflictname _ _ db.002 _ db.004 Filedigests Installtid Obsoletename Providename Pubkeys Requireversion Sigmd5

# backup Mobile Library Files

[root@mzf ~] # mkdir backup [root@mzf ~] # mv / var/lib/rpm/* backup/

# there are no more library files

[root@mzf ~] # ls / var/lib/rpm/

# initialize library files

[root@mzf ~] # rpm-- initdb [root@mzf ~] # ls / var/lib/rpm/__db.001 _ _ db.002 _ _ db.003 _ db.004 Packages

# rebuild the library file

[root@mzf ~] # rpm-- rebuilddb [root@mzf ~] # ls / var/lib/rpm/Packages

# query has expired

[root@mzf ~] # rpm-qa: the reconstruction here is just to regenerate the library file, but the previous record is gone, so we restore it.

# move the file to / var/lib/rpm again

[root@mzf] # mv-f backup/* / var/lib/rpm/

# query the previously installed software and find that it is ready to view

[root@mzf ~] # rpm-qa | grep'^ bind.*'bind-libs-9.8.2-0.47.rc1.el6.x86_64bind-9.8.2-0.47.rc1.el6.x86_64

Bind-utils-9.8.2-0.47.rc1.el6.x86_64

Note: if only a little file or lock file is destroyed here, you can also use the rebuild database to save, but if all the files in / var/lib/rpm are deleted, even if the files are rebuilt, the records cannot be found, so you need to back up the library files.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report