Table of Contents
- History of apt and apt-get
- Comparison of apt and apt-get commands
- Examples of common commands
-
- Update repository index
- Upgrade installed packages
- list all available packages
- Keyword search installation package
- install software
- uninstall software
- View installation package information
- Clean up useless dependencies
- Clean up downloaded cache packages
- Clean up leftover configuration files
- View the dependencies of the installation package
- refer to
Apt and apt-get development history
Debian uses a set of tools called Advanced Packaging Tool (APT) to manage software packages (not to be confused with the apt command, not the same thing), in Debian-based Linux distributions (such as Ubuntu), there are various tools that can be used with APT interacts to facilitate users to install, remove and manage software packages. apt-get and apt-cache are two of the most popular tools.
The usage of apt-get and apt-cache commands is very low-level. The commonly used software package management commands are scattered in different commands. You have to use apt-get for a while, and you have to use apt-cache for a while. The interface cannot be unified, which is very unfriendly.
To this end, Ubuntu 16.04 introduces the apt command set, which is optimized on the basis of apt-get and apt-cache, and is more structured and advanced. Apt ignores the needs of fetching and caching. With apt, you don’t have to switch back and forth between apt-get and apt-cache commands. With apt, you get all the necessary tools at once. Don’t get lost in the multitude of command options. Apt’s main goal is to provide a user-pleasing way to work efficiently with software packages. Its streamlined command options are easier to use and easier to remember.
Whether apt-get will be deprecated in the future is unknown, but many other Linux distributions are also following the steps of Ubuntu and starting to encourage users to use apt instead of apt-get. Unless you plan to do some specific operations, and these operations use more features of apt-get. Otherwise, use apt.
To sum up the difference between apt and apt-get is:
- Apt is a new tool, used to replace apt-get and apt-cache, the purpose is a more friendly and easy-to-use package management tool;
- apt-get has not been abandoned or outdated, and can still be used with confidence, but ordinary users are advised to switch to apt.
Comparison of apt and apt-get commands
Although apt does provide some options similar to apt-get, it is not backward compatible with apt-get. This means that if you just use apt instead of apt-get in the apt-get command, it won’t always work.
Let’s see which command options of apt-get and apt-cache are replaced by the apt command
apt command | replaced command | function of the command |
---|---|---|
apt update | apt-get update | update repository index |
apt upgrade | apt-get upgrade | Upgrade all upgradeable packages |
apt install | apt-get install | install package |
apt remove | apt-get remove | remove package but keep config file |
apt purge | apt-get purge | Remove the package and delete the configuration file |
apt autoremove | apt-get autoremove | Automatically delete useless dependencies |
apt full-upgrade | apt-get dist-upgrade | Automatically handle dependencies when upgrading packages |
apt search | apt-cache search | Search applications |
apt show | apt-cache show | Display the basic information of the specified installation package |
apt also has some unique commands of its own:
New apt command | Command function |
---|---|
apt list | List packages containing conditions (installed, upgradable, etc.) |
apt edit-sources | edit sources list |
For their commonly used commands, see the help instructions of apt, apt-get and apt-cache:
$ apt -h apt 2.0.9 (amd64) Usage: apt [options] command The command-line package manager apt provides functions such as package search, management and information query. It provides the same functionality as other APT tools (like apt-get and apt-cache), But by default it is set to be more interactive. Common commands: list - list packages by name search - search package descriptions show - show package details install - Install a package reinstall - reinstall a package remove - remove a package autoremove - remove all automatically installed packages that are no longer in use update - update the list of available packages upgrade - update the system by installing/upgrading software full-upgrade - Update system by uninstall/install/upgrade edit-sources - Edit software source information files satisfy - Satisfy the system with dependency strings
$ apt-get -h apt 2.0.9 (amd64) Usage: apt-get [options] command apt-get [options] install|remove package1 [package2...] apt-get [options] source package1 [package2...] apt-get can download packages and related information from certified software sources to install and upgrade packages, Or for removing packages. During these processes, package dependencies are handled gracefully. Common commands: update - Retrieve updated package list information upgrade - perform an upgrade install - install a new package (note: the package name should be something like libc6 not libc6.deb) reinstall - reinstalls the package (note: the package name should be something like libc6 not libc6.deb) remove - remove a package purge - Uninstall and purge a package's configuration autoremove - remove all automatically installed packages that are no longer in use dist-upgrade - distribution upgrade, see apt-get(8) dselect-upgrade - upgrade based on dselect selections build-dep - configures required build dependencies for source packages satisfy - Satisfy the system with dependency strings clean - delete all downloaded package files autoclean - remove old downloaded package files check - check to confirm the integrity of the system's dependencies source - Download the source package file download - download the specified binary package to the current directory changelog - Download the specified package and display its changelog (changelog)
$ apt-cache -h apt 2.0.9 (amd64) Usage: apt-cache [options] command apt-cache [options] show package1 [package2...] apt-cache can query and display information about the availability of installed and installable packages. It works exclusively on local data caches that can be accessed via, for example, apt-get's 'update' command to update. If it's been too long since the last update, Then the information it displays may be out of date. But in exchange, apt-cache does not rely on Availability of the current software source (eg: offline status). Common commands: showsrc - show the records of the source file search - search the list of packages based on a regular expression depends - displays the package's dependencies rdepends - show the names of all packages that depend on this package show - presents the package in a human-readable format pkgnames - list all package names policy - Displays the status of a package's installation settings
Example of common commands
For the following example, try to use the apt command.
Update repository index
Use the command apt update to resynchronize the file index from the source warehouse. This command must be executed when the source list is updated.
$ sudo apt update
Upgrade installed packages
Upgrade all installed packages:
apt-get upgrade
Only upgrade specific packages:
apt-get upgrade <package_name>
List all available packages
You can use this command to check whether the package you want to install is in the list of installable packages. This command will display all available installation packages and the installation status of each package, including information such as installed, upgradeable, and remaining configuration files.
apt list
Keyword search installation package
Before apt install, if you don’t know the exact package name, you can use apt search to search, which supports fuzzy search. The more detailed the keyword, the more accurate the search result. The keyword can be part of the package name or the package description part of the content.
apt search <search term>
Install software
install software:
apt install <package_name>
Install specific version software:
apt install <package_name>=<version_number>
Install multiple software at the same time:
apt install <package_1> <package_2> <package_3>
Uninstall the software
There are two ways to uninstall the software:
apt remove <package_name> apt purge <package_name>
View installation package information
For example, check the basic information of the bash installation package
$ apt show bash Package: bash Version: 5.0-6ubuntu1.2 Priority: required Essential: yes Section: shells Origin: Ubuntu Maintainer: Ubuntu Developers <[email protected]> Original-Maintainer: Matthias Klose <[email protected]> Bugs: https://bugs.launchpad.net/ubuntu/ + filebug Installed-Size: 1,700 kB Pre-Depends: libc6 (>= 2.15), libtinfo6 (>= 6) Depends: base-files (>= 2.1.12), debianutils (>= 2.15) Recommends: bash-completion (>= 20060301-0) Suggests: bash-doc Conflicts: bash-completion (<< 20060301-0) Replaces: bash-completion (<< 20060301-0), bash-doc (<= 2.05-1) Homepage: http://tiswww.case.edu/php/chet/bash/bashtop.html
Clean up useless dependencies
When installing software on an Ubuntu system, the software’s dependencies are usually automatically installed as well. After we delete the software, its dependent packages may need to be manually deleted by using the following command:
apt autoremove
Clean up downloaded cache packages
When Ubuntu installs software through apt-get install, the downloaded packages are cached in the /var/cache/apt/archives/ directory. It is not immediately removed from the directory after the installation is complete. If you delete a package and then reinstall it, your system will look for the package in the cache and fetch it from there instead of re-downloading it.
Temporary directory for package management:
Store during download: /var/cache/apt/archives/partial
Store after downloading: /var/cache/apt/archives
If you want to clean up these downloaded cache packages, you can execute the command:
sudo apt-get clean sudo apt-get autoclean
apt-get clean deletes all packages in /var/cache/apt/archives/ and /var/cache/apt/archives/partial/ directories (except locked packages).
apt-get autoclean only removes old (older than currently available) packages and useless packages (locked) in /var/cache/apt/archives/ and /var/cache/apt/archives/partial/ except software packages).
Clean up leftover configuration files
If you use apt remove to uninstall the software, the configuration files of the software will be kept, and there will be configuration files left in the system at this time. Residual configuration files can be viewed with the following command:
$ apt list | grep residual WARNING: apt does not have a stable CLI interface. Use with caution in scripts. appmenu-qt5/now 0.3.0 + 16.04.20170216-0ubuntu1 amd64 [config file leftover] apt-xapian-index/focal,focal 0.51ubuntu1 all [configuration file remains] docutils-common/focal,focal,now 0.16 + dfsg-2 all [configuration leftover] eclipse-platform/now 3.8.1-8 amd64 [configuration file remains] fcitx-ui-qimpanel/focal 2.1.3-2build1 amd64 [config file leftover]
View the dependencies of the installation package
For example, check the bash installation package dependencies:
$ apt-cache depends bash bash Pre-dependency: libc6 Pre-dependency: libtinfo6 Dependency: base-files base-files:i386 Depends on: debianutils debianutils:i386 Conflict: bash-completion Recommended: bash-completion Suggestion: bash-doc Replaces: bash-completion Replaces: bash-doc
Reference
https://blog.csdn.net/slampai/article/details/128072043
https://itsfoss.com/apt-vs-apt-get-difference/
https://itsfoss.com/apt-get-linux-guide/
https://linux.cn/article-4933-1.html