Last article《Linux software installation management — source code installation details》The installation principle of source code package under Linux platform is introduced in detail. Although software compilation using source code can have customized settings, it is not too late for Linux distribution publishers to manage software. After all, not everyone will compile source code. This problem will seriously affect the distribution and promotion of software on Linux platform.
In order to solve the above problems, manufacturers first compile the software required by our users on their system, and then release the compiled and executable software directly to users for installation. Different Linux distributions use different packaging systems. Generally speaking, most distributions belong to two major package management technology camps: Debian’s “DEB” and red hat’s “RPM”. There are some important exceptions, such as Gentoo, Slackware, and foresight, but most will use one of these two basic systems.
Here we will introduce the detailed usage of dpkg and apt – * of Debian series distribution. If you need to know the package management system of red hat series distribution, please see another article:《Linux software installation management — detailed explanation of RPM and yum》。
Note: my system version [Ubuntu 12.04 lts]
Dpkg – Package Manager for Debian.
Dpkg is a tool to install, build, remove and manage Debian packages.
The dpkg mechanism was first developed by Debian Linux community. Through the dpkg mechanism, the software provided by Debian can be easily installed and the installed software information can be provided at the same time. It is really very good. As long as other Linux distributions derived from Debian mostly use dpkg this mechanism to manage, including B2D, Ubuntu, etc.
2. Deb package name rule
Format: package_ Version-Build_ Architecture.deb
Such as nano_ 1.3.10-2_ i386.deb
- Package name: nano
- Version number: 1.3.10
- Build number: 2
- Platform architecture: i386
3. Introduction to dpkg software package related documents
/Var / log / dpkg.log dpkg package management software log file [default log file (see / etc / dpkg / dpkg. CFG (5) and option — log)]
/Var / lib / dpkg / available stores all installed software package information of the system [list of available packages.]
/Var / lib / dpkg / status stores the status information of all installed software in the system
/Var / lib / dpkg / Info records the control information file of the installation package control directory
4. Dpkg database
Dpkg uses text files as a database to maintain the software in the system, including file lists, dependencies, software status, and other details, usually in the / var / lib / dpkg directory. Software status and control information is usually stored in the status file. Back up the control file in the info / directory, and record the installation file list in the. List file under it. Mdasums saves the MD5 code of the file.
Example: query dpkg database (display all installed DEB packages)
As shown in the figure above, each record corresponds to a software package. Note that the first, second and third characters of each record are the status identification of the software package, followed by the software package name, version number and brief description.
1) The first character is the expected value (desired = unknown / install / remove / purge / hold), which includes:
U unknown status is unknown, which means that the software package is not installed and the user has not issued an installation request
I install user requests to install the package
R remove the user requested to uninstall the package
P purge user requests to clear the package
H hold user requests to keep the software package version locked
2) The second column is the current status of the software package (status = not / Inst / conf files / unpacked / halfconf / half Inst / trig await / trig pend)
N the not package is not installed
I install Inst software package and complete configuration
The C conf files package was previously installed and is now deleted, but its configuration file remains in the system
U unpacked package is unpacked but not configured
F half conf tried to configure the package, but failed
H half Inst package was installed but failed
W trig await trigger wait
T trig pend trigger pending
3) The third column identifies the error status. The first status identifies no problem and is empty. Other symbols identify the corresponding problem (ERR=（ none)/Reinst-required (Status,Err: uppercase=bad)）
H the software package is forced to be maintained because other software packages depend on requirements and cannot be upgraded
R REINST required, the software package is damaged and may need to be reinstalled for normal use (including deletion)
X the soft package is damaged and forcibly maintained
II - indicates that the software is normally installed in the system PN - indicates that the software is installed and then cleared Un - indicates that the software has never been installed IU - indicates that the software is installed but not configured RC - the software has been deleted, but the configuration file is still
5. Dpkg subcommand
For the convenience of users, dpkg not only provides a large number of parameter options, but also provides many subcommands.
The command of dpkg will not be described in detail here. If you need to know, you can consult the data yourself.
3、 Dpkg user manual
1) Installation related commands
dpkg -i package-name.deb # –install,
To install a package, it must be the full name of the DEB package（ Software installation can be divided into two opposing processes (unpacking and configuration)
dpkg –unpack package-name.deb #
“Unpacking”: unpack the software package to the system directory without configuration. If used with – R, the parameter can be a directory
Dpkg — configure package-name.deb # “configure”: configure the software package
Dpkg – C package-name.deb # lists the contents of the DEB package
2) Installation related options
-R, –recursive Recursively handle all regular files matching pattern *.deb found at specified directories and all of its
- This can be used with -i, -A, –install, –unpack
- –Available actions (recursively points to all installation packages in a specific directory, which can be combined with – I, – A, – install, – unpack and
–(used with avail)
2. Remove package
Dpkg – R package name # — remove, remove the package but keep its configuration file
Dpkg – P package name # — purge, clear all files in the package (remove everything,
Dpkg – L package name pattern # — list to view the packages in the system whose package names conform to the pattern pattern
Dpkg – L package name # — listfiles to view the installed files and directories of packages corresponding to package name
Dpkg – P package name # — print available to display the specific information of the package
Dpkg – s package name # — status to view the package information corresponding to package name (installed)
dpkg -S filename-search-pattern # –search,
Find the package name containing filename from the installed package (tip: you can also use the subcommand dpkg query to query)
Example 1: list the dpkg related software packages installed on the system
dpkg -l \*dpkg*
Example 2: view the files installed in the system by dpkg software package
dpkg -L dpkg
For more ways to use dpkg, you can use man dpkg on the command line or directly use dpkg — help.
1. Introduction to apt
Although we have solved a lot of problems in the software installation process when using dpkg, we still need to solve them manually when the dependencies are not satisfied. Apt solves such problems. Linux distribution first places the software in the corresponding server, then analyzes the software dependencies and records them, Then, when the client needs to install the software, compare the list with the existing software data of the local dpkg, and you can get all the required software with dependent attributes from the network.
2. Working principle
Ubuntu uses a centralized software warehouse mechanism to store all kinds of software packages in the software warehouse for effective organization and management. Then, the software warehouse is placed in many mirror servers and kept basically consistent. In this way, all Ubuntu users can get the latest version of the installation package at any time. Therefore, for users, these mirror servers are their software repository
However, due to the different network environment of each user, it is impossible to access each mirror site at will. In order to selectively access, in the Ubuntu system, use the software source configuration file / etc / apt / sources.list to list the most appropriate image site addresses to access.
Example 1: apt get update process
1) Execute apt get update 2) Program analysis / etc / apt / sources.list 3) Automatically connect the network to find the corresponding packages / sources / release list file in the list. If there is an update, download it and store it in the / var / lib / apt / lists / directory 4) Then apt get install the corresponding package, download and install it.
Even so, the software source configuration file only tells the address of the image sites that the Ubuntu system can access, but it is not clear what software resources those image sites have. If you search the server every time you install a software package, the efficiency is very low. Therefore, it is necessary to make a list (index file) for these software resources for local host query.
Users can use the “apt get update” command to refresh the software source and establish a list of updated software packages. In Ubuntu Linux, the “apt get update” command will scan each software source server and establish an index file for the software package resources of the server, which is stored in the local / var / lib / apt / lists / directory. When using apt get to perform installation and update operations, resources will be applied to the software source server according to these index files. Therefore, it is a good habit to often use the “apt get update” command to refresh the software source when the computer device is idle.
Example 2: apt get install schematic diagram
3. Apt related documents
The content of var / lib / dpkg / available file is the description of the software package, which includes all the software packages in the Debian installation source used by the current system, including the installed and uninstalled software packages in the current system
/Etc / apt / sources.list record the address of the software source (when you execute sudo apt get install XXX, Ubuntu will go to these sites to download the software package locally and perform the installation)
/All downloaded software packages of var / cache / apt / archives are placed here (the temporary storage path of the software package when installing the software with apt get install)
/Var / lib / apt / lists use the apt get update command to download the software list from / etc / apt / sources.list and save it to this directory
4. Source file
The source file of apt is specified by the configuration file / etc / apt / sources.list, which configures memory as shown in the following figure:
The storage location of the mirror server is as follows:
After decompressing packages.gz, we can see the basic information of all software packages, and packages.gz already contains all the dependent software and its version information, as well as the download address.
4、 Apt user manual
apt-get is the command-line tool for handling packages, and may be considered the user’s “back-end” to other tools using the APT library. Several “front-end” interfaces exist, such as dselect(1), aptitude(8), synaptic(8) and wajig(1).
Apt get is a simple command line interface for downloading and installing software packages. The most common commands are update and install.
Usage: apt get [options] Command
-H this help file.
-Q output to log – no progress indication
-QQ does not output information except errors
-D download only – do not install or unzip the archive
-S is not actually installed. Simulate execution command
-Y. all prompts are assumed to be false
-F try to correct the system dependency damage
-M if the archive cannot be located, try to continue
-U also displays a list of update packages
-B obtain the source package and compile it
-V displays the detailed version number
-c=? Read this profile
-o=? Set custom configuration options, such as – O dir:: cache = / tmp
1) Apt get update update source
2) Apt get dist upgrade upgrade upgrade the system to the corresponding distribution (according to the configuration of source.list)
3) Apt get upgrade updates all installed packages
4）apt-get install package_ Name installs the package (plus — reinstall)
apt-get install package_ Name = version installs the specified version of the package
【aptitude install package_name】
5）apt-get remove package_ Name uninstalls an installed package (keeps the configuration file)
【aptitude remove package_name】
6）apt-get purge package_ Name remove package (delete configuration information)
Or apt get — purge remove packagename
【aptitude purge package_name】
7) Apt get check checks for corrupt dependencies
Delete the software you have deleted (run this command regularly to clear the. DEB files of the uninstalled packages). In this way, you can free up a lot of disk space. If your needs are urgent, you can use apt get
Clean to free up more space. This command will delete the. DEB file of the installed software package. In most cases, you will not reuse these. Debs files, so if you are out of disk space
And feel overwhelmed, this method may be worth trying)
9) Apt get clean also deletes the backup of the installed software, but this will not affect the use of the software
apt-cache – query the APT cach.
apt-cache performs a variety of operations on APT’s package cache. apt-cache does not manipulate the state of the system but does provide operations to search and generate interesting output from the package metadata.
1) Apt cache dependencies packagename understand usage dependencies
2) Apt cache rdependents packagename is used to view which packages the package depends on
3) Apt cache search packagename
【aptitude search packagename】
4) Apt cache show packagename obtains package related information, such as description, size, version, etc
【aptitude show packagename】
5) Apt cache showpkg packagename displays the general information of the software package
(Note: aptitude in brackets  is also a package management upper level tool similar to apt – *)
Alibaba cloud open source mirror station:http://mirrors.aliyun.com/
Netease open source mirror station:http://mirrors.163.com/
Book: the Linux command line William E. Shotts, Jr
Ubuntu official website:https://www.ubuntu.com
Debian official website:https://www.debian.org/doc/us…
Lost personal blog:http://blog.csdn.net/astrayli…