Apt-get/dpkg for beginners in Debian [reprint]

Source: Internet
Author: User
Tags superuser permission

 

Debian and Debian-based systems, such as Ubuntu, use the package format deb. The following table lists the commonly used Dpkg commands for operating the deb package.

Command
Function

Dpkg-I package. deb
Installation Package

Dpkg-r package
Delete package

Dpkg-P package
Delete a package (including configuration files)

Dpkg-L package
List the files associated with the package

Dpkg-l package
Show the version of this package

Dpkg-unpack package. deb
Unbind deb Package content

Dpkg-S keyword
Search for the package content

Dpkg-l
List packages currently installed

Dpkg-c package. deb
List deb Package content

Dpkg-configure package
Configuration package

Note: More options can be queried through dpkg-h. Some commands require the superuser permission to be executed.

========================================================== ======

Apt usage reference

Command function
Apt-cache search package
Apt-cache show package obtains package information, such as description, size, and version.
Sudo apt-get install package installation package
Sudo apt-get install package--reinstall re-installation package
Sudo apt-get-f install force Installation
Sudo apt-get remove package Delete package
Sudo apt-get remove package--purge delete a package, including deleting a configuration file.
Sudo apt-get autoremove automatically deletes unnecessary packages
Sudo apt-get update source
Sudo apt-get upgrade updates installed packages
Sudo apt-get dist-upgrade System
Sudo apt-get dselect-upgrade using dselect
Apt-cache depends package for dependency usage
Apt-cache rdepends package to understand specific Dependencies
Sudo apt-get build-dep package installation-related compilation environment
Apt-get source package download the source code of the package
Sudo apt-get clean & sudo apt-get autoclean clear the archive of the downloaded file
Sudo apt-get check whether any corrupted dependency exists

==============================================

Like apt-get, aptitude is a powerful package management tool in Debian and its derivative systems. Unlike apt-get, aptitude is better in dealing with dependency issues. For example, aptitude deletes the packages it depends on when deleting a package. In this way, useless packages will not be left in the system, and the whole system will be cleaner. The following are some common aptitude commands that I have summarized for your reference only.

Command
Function

Aptitude update
Update the list of available packages

Aptitude upgrade
Upgrade available packages

Aptitude dist-upgrade
Upgrade the system to a new release

Aptitude install pkgname
Installation Package

Aptitude remove pkgname
Delete package

Aptitude purge pkgname
Delete packages and their configuration files

Aptitude search string
Search package

Aptitude show pkgname
Show package details

Aptitude clean
Delete downloaded package files

Aptitude autoclean
Only Delete expired package files

You can also use aptitude in text interface mode.

========================================================== ===

Brief Translation: the original article is on the Blog of All about Linux. In fact, there is a more comprehensive apt howto that has been translated for a long time, which is strongly recommended.
Debian is one of the earliest Linux releases. It can attract public attention because it makes it very easy to install and uninstall software. When other releases are stuck in the dependency quarary, Debian users are immune from these problems because of a better package management system.
All Debian-based distributions use this package management system. The Deb package can package the files of an application together, basically like the installation files on Windows. Here we will introduce how to use the installation package processing software to achieve our goal.
The first step to use apt-get is to introduce the necessary software libraries. The Debian software libraries are the collection of all Debian software packages, which exist on some public websites on the Internet. Add their addresses to apt-get to search for the software we want. /Etc/apt/sources. list is the configuration file that stores these address lists. The format is as follows:
Deb [web or ftp address] [release name] [main/contrib/non-free]
For example, Ubuntu is a Debian-based release, and its Sources. list can be like this:
Deb http://in.archive.ubuntu.com/ubuntu breezy main restrcted
You can add your own address. The apt-get.org has some nice address lists.
After setting the address, you must synchronize the software library on the local machine with the online library (only the software description information, excluding the software itself ). In this way, a list of available software is available on the local machine. The command is as follows:
# Apt-get update
After running successfully, you can find the software in your release. The command is apt-cache, and the command is retrieved on the local machine instead of connected to the Internet. For example:
# Apt-cache search baseutils
This command can be used to list the situation of the baseutils software package, such as whether it is available or not.
You can install this software package in the Library:
# Apt-get install baseutils
Now we can see the power of apt-get. If baseutils is dependent on another software or a Runtime Library xyz.0.01.so, apt-get will automatically download this package (or a software package containing this library ). This is called automatic dependency processing. Generally, if you only use the software in the Debian software library, you will not find the package or the package version is incorrect, unless you use the Testing or Unstable version being developed.
Uninstall software:
# Apt-get remove baseutils
If you want to see how many software is in the Library:
# Apt-cache stats
Total package names: 22502 (900 k)
Normal packages: 17632
Pure virtual packages: 281
Single virtual packaging: 1048
Mixed virtual packages: 172
Missing: 3369
...
Upgrade all software on the local machine to the latest version:
# Apt-get upgrade
Finally, the most powerful version -- upgrade the entire release to the new version:
# Apt-get dist-upgrade
During the upgrade, pay attention to the things that affect system startup, such as upgrading the kernel, grub or lilo. After that, you should re-run grub or lilo to point them to the correct position, otherwise, the upgrade will fail.
When you use apt-get to install the software, it will start from the Internet (at sources. the software package used for downloading. The package will be stored on the local machine. The directory is/var/cache/apt/archives /. After a long time, it will become very huge and occupy a lot of hard disk space. To clear this directory, run:
# Apt-get clean
There is also an automatic cleanup function that only clears useless or incomplete software packages:
# Apt-get autoclean
In this way, you can still use the downloaded software when you reinstall it, instead of downloading it online.
Dpkg-some underlying package management tools
After apt (Advanced package management tool) is used, you do not need to process a single deb file. If necessary, run the dpkg command. For example, you want to install gedit yourself:
# Dpkg-I gedit-2.12.1.deb
Uninstall:
# Dpkg-r gedit
Write the name here. You can also add the -- purge (-P) Flag:
# Dpkg-P gedit
This will be deleted together with the gedit configuration file. If only-r is used, the configuration file will not be deleted.
If you do not want to install a deb package, but want to see what files it contains:
# Dpkg-c gedit-2.12.1.deb
If you want to view more information:
# Dpkg-I gedit-2.12.1.deb
You can also use wildcards to list the software on the machine:
# Dpkg-l gcc *
This will list all software packages starting with gcc:
Desired = Unknown/Install/Remove/Purge/Hold
Status = Not/Installed/Config-files/Unpacked/Failed-config /.
/Err? = (None)/Hold/Reinst-required/X = both-problems
/Name Version Description
++-=================================================== ==============================
Ii gcc 4.0.1-3 The gnu c compiler
Ii gcc-3.3-base 3.3.6-8ubuntu1 The GNU Compiler Colletio
Ungcc-3.5 none (no description available)
Among them, 1st I indicates that you want to install, 2nd I indicates that you have installed, and 3rd fields are problematic (if any) (the meaning of these three words can be seen in the above three lines, desired, status, err), followed by the name, version, and description. Un indicates Unknown, not-installed.
If you want to see if a package has been installed:
# Dpkg-s gedit
If you want to see what files are installed in a software, where:
# Dpkg-L gedit
If you only want to view some of the files, add Grep:
# Dpkg-L gedit grep png
Of course, there are also aptitude and Aptitude. The former is a menu-based tool running on the terminal, and the latter is a graphical program running on the X Window.
Also, list the details of a package: apt-cache show gedit
Some Mandatory Commands: dpkg -- force-help

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.