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

Ubuntu software package management

2025-01-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

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

Apt

First introduce apt,apt (Advanced Package Tool) advanced software package tools, which are used to download, install, delete and upgrade software packages and report the status of software packages. Apt is not a specific command, but a package management tool set composed of a set of commands, the more commonly used is apt-get,apt-cache. Apt is mainly responsible for downloading the package, but after downloading it locally, it will call dpkg to process the package.

/ etc/apt/sources.list

The / etc/apt/sources.list file specifies the repository that apt searches for when it finds or installs a package, and each line defines a repository. The warehouse stores a set of software packages and related information, including the header information used to describe each package and the dependencies between packages. The packages in the Ubuntu repository can be divided into the following categories:

1) Open source software supported by main # Ubuntu

2) universe # open source software maintained by the community

3) multiverse # Software with copyright restrictions or legal issues

4) restricted # proprietary device driver

5) backports # software packages found in newer Ubuntu releases but not in earlier releases

When selecting a package, apt searches the repositories according to the categories specified in the sources.list file. When you try to install a package, the following error message may appear:

Root@baby-Inspiron-N5110:~# apt-get install xxxReading package lists... DoneBuilding dependency tree Reading state information... DoneE: Unable to locate package xxx

This means that any of the repositories defined in the sources.list file do not contain the package, and if you do not use the latest version of ubuntu, it is possible that the package can only be used in the latest version. Try to start the backports repository in the sources.list file.

The format of the sources.list file definition repository is as follows:

Type URL repository category-list

Type=deb # software package for executable files

Type=deb-src # Source Code package

URL # specifies the location of the warehouse, usually a URL

Name of the warehouse to be searched by repository # apt

Category-list # package categories (separated by spaces if more than one main,universe,multiverse,restricted,backports)

Deb http://security.ubuntu.com/ubuntu precise-security main restricted

The above line comes from the sources.list file, which means that apt searches the precise-security repository at http://security.ubuntu.com/ubuntu for deb packages that contain executable files. The acceptable package category is main,restricted. Replacing deb with deb-src,apt will search for the source package in the same way and download the source package by commanding apt-get source.

Apt native package index and apt cache

The / var/lib/apt/lists directory stores the local package index and its related files. For each repository listed in the / etc/apt/sources.list file, this directory has a file listing the latest version information for each package in the repository. Apt uses these files to determine whether the package in the system and its cache is the latest version. When the sources.list file adds a new repository, you can use the apt-get update or aptitude update command to synchronize the index in the / var/lib/apt/lists directory with the relevant information in the repository so that apt can download the software packages in the newly added repository.

Apt's cache is stored in the / var/cache/apt/archives directory, which contains the recently downloaded deb file. By default, apt's cron script limits the size of this directory and the validity of the files in this directory.

In Ubuntu Linux, you need to explain a concept-virtual software packages.

Take multiple packages in the system with the same or similar functions as a collection of software packages, called virtual packages, and specify one of the packages as the default preference for virtual packages. The intention of virtual software is to prevent conflicts in the process of software installation. For example, exim, sendmail, and postfix packages are all used for mail transfer agents, specifying "mail-transport-agent" as their virtual packages. When users install "mail-transport-agent", they will choose to install the preferences of exim, sendmail, and postfix.

Apt profile

The configuration file for apt is stored in the / etc/apt/apt.conf.d directory. The apt cron script is stored in the / etc/cron.daily directory so that it can be run every day. It reads the configuration files in the apt.conf.d directory and maintains the apt local package index and cache according to the instructions in those configuration files.

The following two files control how the apt cron script maintains the apt local package index and apt cache:

Root@baby-Inspiron-N5110:/etc/apt/apt.conf.d# cat 10periodic APT::Periodic::Update-Package-Lists "0"; APT::Periodic::Download-Upgradeable-Packages "0"; APT::Periodic::AutocleanInterval "0"; root@baby-Inspiron-N5110:/etc/apt/apt.conf.d# cat 20archive APT::Archives::MaxAge "30"; APT::Archives::MinAge "2"; APT::Archives::MaxSize "500"

APT::Periodic::Update-Package-Lists "days"

# synchronize local package indexes with their corresponding repositories every days day. Days is 0, disable this command.

APT::Periodic::Download-Upgradeable-Packages "days"

# the packages required to upgrade all software packages in the system are loaded per days (not installed). Days is 0, disable this command.

APT::Periodic::AutocleanInterval "days"

# clear the apt cache of packages that can no longer be downloaded every days day. Days is 0, disable this command.

APT::Archives::MaxAge "days"

# delete files from days days ago from the apt cache. Days is 0, disable this command.

APT::Archives::MinAge "days"

# do not delete files within days days from the apt cache. Days is 0, disable this command.

APT::Archives::MaxSize "MB"

# set the maximum size of the apt cache. When the cache increases by more than MB megabytes, the apt cron script deletes the file until the cache size is smaller than this size. It first deletes the files with the largest size. MB is 0, disable this command.

The use of aptitude

Aptitude is an apt-based package management tool, the function is similar to apt-get, which is used to manage software packages. Aptitude has two interfaces: a pseudo-graphical interface and a text interface. Only the text interface is introduced here. The log of the aptitude tool is recorded in / var/log/aptitude, and the log is very readable.

Aptitude autoclean # clears the apt cache for packages that can no longer be downloaded.

Aptitude clean # removes all packages from the apt cache

Aptitude download # download the deb file of a software package

Aptitude upgrade # upgrade the specified software package

Aptitude full-upgrade # upgrades all packages in the system and installs new packages as needed

Aptitude safe-upgrade # upgrades all packages in the system without installing new packages

Aptitude install # installs the specified package and all packages on which the package depends

Aptitude reinstall # reinstall the specified package

Aptitude purge # Delete the specified package including the configuration file

Aptitude remove # removes the specified package, including the package it depends on, and does not delete the configuration file

Aptitude search # look for software packages in the warehouse designated by sources.list

Aptitude show # displays the details of the package, including dependency information

Aptitude update # synchronizes the local apt package index files with the files in the repository

When aptitude deletes a package, it also removes dependent packages that are automatically installed when the package is installed.

Pay attention to the following items:

1) the aptitude update:apt corn script automatically synchronizes the package index files at night, but if you want to use it immediately after adding a new repository in / etc/apt/sources.list, you must run this command.

2) the difference between aptitude safe-upgrade and full-upgrade is that when aptitude full-upgrade upgrades all software packages, it installs some uninstalled packages in order to meet the dependency, while aptitude safe-upgrade only upgrades all those packages in the system that only rely on those packages that have been installed into the system. This command does not install new packages.

3) when aptitude search package-list searches through this command, a line of information is displayed for each package in the repository whose name matches an element in package-list:

Root@baby-Inspiron-N5110:/tmp# aptitude search apachep apache2- Apache HTTP Server metapackage p apache2:i386-Apache HTTP Server metapackage v apache2-dev -v apache2-dev:i386- P apache2-doc-Apache HTTP Server documentation v apache2-mpm-v apache2-mpm: I386-p apache2-mpm-event-Apache HTTP Server-event driven model.

The letters in the first column of each line give the status of the corresponding software package in the system: I indicates that it has been installed, c indicates that the rest of the configuration file has been deleted, p indicates cleared (including configuration file), and v indicates virtual package. The second letter in the first column shows the storage action to be performed on the corresponding software package. If the third letter is A, it means that the corresponding software package has been installed automatically.

Apt-cache

Apt-cache is an apt package management tool under linux, which can query the binary package cache files of apt. Most of the information query functions managed by the APT package can be implemented by the apt-cache command. The cache information used by apt-cache is generated by the apt-cache gencaches command from the source (repository) specified in the / etc/apt/sources.list file, including details of all software packages and their dependencies contained in each repository. The cache information is stored in / var/lib/dpkg/status.

If / var/lib/dpkg/status is deleted or changed to a different file name, the command apt-cache will have no effect:

Root@baby-Inspiron-N5110:/var/lib/dpkg# apt-cache show bind9E: Could not open file / var/lib/dpkg/status-open (2: No such file or directory) E: The package lists or status file could not be parsed or opened.E: No packages found

The error message shows that the / var/lib/dpkg/status file cannot be opened!

Main usage of apt-cache:

Commands:

Gencaches # rebuild the caching of source packages and code packages

Showpkg # displays individual package information (including package information, forward dependent packages, reverse dependent packages, etc.)

Showsrc # displays the records of the source file (including version number, installation status, package dependencies, etc.)

Stats # displays some basic statistics

Dump # briefly displays the contents of the entire cache file

Dumpavail # prints a list of all valid package files to standard output

Unmet # shows all unsatisfied dependencies

Search # search package, regular expressions are available

Show # introduces the software package in an easy-to-read format

Depends # shows the package on which the specified package depends (forward dependent package)

Rdepends # shows the reverse dependency of software packages, that is, what packages depend on the package you specify

Pkgnames # lists the names of all software packages (pipe filtering to see if the software repository contains the package)

Dotty # generates software package diagrams that can be processed by GraphVis

Xvcg # generates diagrams of software packages available for xvcg processing

Policy # displays the installation setting status of the package

Options:

-h # display help documentation

-packs? # package cache.

-slots? # Source package cache.

-Q # makes the output available as a log-does not show progress

-I # displays only important information that does not satisfy the dependency.

-caching? # read the specified configuration file

-dir::cache=/tmp? # set any specified configuration options, such as-o configuration

Apt-file

Apt-file is a special tool for software package search. Its usage is similar to apt-cache. First, cache information is generated according to the source specified in / etc/apt/sources.list file through apt-file update command, and stored in / var/cache/apt/apt-file directory. When querying, the cache information is accessed directly.

The main usage of apt-file:

Apt-file update # updates the cache based on the source specified in the / etc/apt/sources.list file

Apt-file search # queries which software package a file comes from (similar to dpkg-S filename, but this package may not be installed when apt-file queries)

Apt-file find # same as search

Apt-file list # query which files will be generated by a software package (similar to dpkg-L, but this package may not be installed when querying apt-file)

Apt-file show # same as list

Apt-file purge # clear the cache

Option:

-- cache |-c cache-directory # specifies the directory where the cache is placed. The default is / var/cache/apt/apt-file

-- ignore-case |-I # ignore case when querying

-- sources-list |-s sources.list # specifies the file that configures the package repository. Default is / etc/apt/sources.list.

Other options can be queried through man.

Apt-get

Apt-get is the most commonly used of apt's many tools, and it is also a package management tool. There are two related directories: the local package index is located in the / var/lib/apt/lists directory, and the most recently downloaded packages are cached in the / var/cache/apt/archives directory, both of which are described above.

Apt-get usage:

Commands:

Apt-get update # Update local package index / var/lib/apt/lists

Apt-get upgrade # updates all installed packages

Apt-get install # installation package

Apt-get remove # remove packages (do not delete configuration files or dependent packages)

Apt-get remove-purge # remove packages (delete configuration files, do not delete dependent packages)

Apt-get autoremove-purge # remove packages (delete configuration files, delete dependent packages)

Apt-get source # download the source code of the package

Apt-get build-dep # relevant compilation environment required to install package compilation

Apt-get dist-upgrade # updates all installed packages

Apt-get clean # Clean the cache (clear the / var/cache/apt/archives/ and / var/cache/apt/archives/partial/ directories)

Apt-get autoclean # cleans up the cache (only packages that cannot be downloaded in the / var/cache/apt/archives/ directory)

Apt-get check # updates the apt cache to check for corrupted dependencies

Apt-get download # download the package to the current directory

Dpkg:debian software package management system

The debian package Management system (dpkg) database records which packages are installed on the system, where each package is installed, the version installed, and which packages it depends on. The debian package management system has many management tools for installing, uninstalling, upgrading, querying, and validating software packages. The initial and most important management tool is dpkg. Although dpkg can accomplish most of the tasks of package management, other tools can make it easier for you to do so. These tools are: apt-cache,apt-file,aptitude,apt-get. These tools have been introduced above, let's introduce dpkg.

The dpkg management system processes .deb format files, which are often referred to as deb files. Because dpkg cannot download deb files from the repository, tools such as aptitude,apt-get perform this task. By default, the downloaded deb files are stored in the / var/cache/apt/archives directory. Dpkg then completes the subsequent installation, which stores the available package information in / var/lib/dpkg/available and the package installation information in / var/lib/dpkg/status.

In addition, again, this / var/lib/dpkg/status file is very important, which is equivalent to a cache file. The dpkg package management system will update this file when the status of the package changes, such as deleting a package, installing a package, and changing the index of the local package. The query information of many tools comes from this file, such as aptitude show,aptitude search,dpkg-l |-- list. Almost all commands of apt-cache, etc.

Several files involved in dpkg:

/ etc/dpkg/dpkg.cfg # configuration file for dpkg

Default log file for / var/log/dpkg.log # dpkg (defined in the configuration file)

/ var/lib/dpkg/available # list of available software packages

/ var/lib/dpkg/status # status information description file of available software packages (apt-cache 's related queries are based on the contents of this file)

Dpkg usage:

Dpkg-I |-- install packageName.deb # install the specified software package

Dpkg-r,-- remove,- P,-- purge # delete the package (--remove,-r) and keep the configuration file. -P,-- purge deleted along with the configuration file)

Dpkg-- update-avail # updates the list of available software packages

Dpkg-l |-- list # displays the relevant information of the software package. If the package name is not added, the relevant information of all software packages (including installed and uninstalled) is displayed.

Dpkg-- info |-I packageName.deb # displays the information of the specified software package, followed by a specified package name, for example: dpkg-- info

Dpkg-- status |-s # displays information about software packages (for installed packages only)

Dpkg-L # queries the location of installed packages in the system (only installed packages, unlike apt-file list)

Dpkg-- search |-S filename # query which package a file comes from (only installed packages, unlike apt-file search)

When using dpkg-l |-- list to list the relevant information of the software package, there are certain formats for a brief introduction.

Root@baby-Inspiron-N5110:/tmp# dpkg-list "bind*" Desired=Unknown/Install/Remove/Purge/Hold | Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend | / Err?= (none) / Reinst-required (Status) Err: uppercase=bad) | | / Name Version Description+++-====un bind (no description available) un bind9 (no description available) un bind9-doc (no) Description available) ii bind9-host 1:9.8.1.dfsg.P1-4ubuntu0.10 Version of 'host' bundled with BIND 9.Xii bind9utils 1:9.8.1.dfsg.P1-4ubuntu0.10 Utilities for BIND

The above command lists all packages that start with bind. The first row in the header lists the possible expected status of the package, and the second column lists the possible package status. The first column of each message is desire, and the second column is status. The u in the first column above indicates a package that is not recognized by dpkg, and the n in the status column indicates that the package has not been installed. Columns 1 and 2 almost mean that the package has been installed.

Desire (selection status) u (package I (install) that unknown dpkg does not know has been installed r (remove) has been deleted, but retention profile p (purge) has been deleted No configuration file h (hold) not handled by dpkg Status (package status) n (not install) not installed I (installed) installed c (config-files) not installed, only the configuration file u (unpacked) is unpacked in the system, but f (failed-config) is not configured No configuration, configuration failed h (half-installed) part installation, installation has not been completed

These are the ones commonly used. For more detailed information, you can man dpkg~~~

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

Internet Technology

Wechat

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

12
Report