In an earlier version of this recipe, I criticized Debian's documentation of their "package management" system. In fact, I said flatly that it was god-awful. I felt that was true - at the time. I've recently reviewed their documentation again, and found it to be improved... still somewhat disjointed - but improved. But this inanity still exists in the Administrator's Handbook:
APT is a vast project, whose original plans included a graphical interface. It is based on a library which contains the core application, and apt-get is the first front end — command-line based — which was developed within the project. apt is a second command-line based front end provided by APT which overcomes some design mistakes of apt-get.
Both tools are built on top of the same library and are thus very close, but the default behavior of apt has been improved for interactive use and to actually do what most users expect. The APT developers reserve the right to change the public interface of this tool to further improve it. Conversely, the public interface of apt-get is well defined and will not change in any backwards incompatible way. It is thus the tool that you want to use when you need to script package installation requests.
Real progress is still slow, I suppose. Anyway... my advice now is to skip the Administrator's Handbook - it seems no one in the Debian organization is putting any effort into it.
Some advocate using apt
, others advocate using apt-get
. I've come to favor the newer apt
for my routine tasks. The differences between apt
and apt-get
are varied, and you will need to decide which you prefer. Here's a good, brief explanation that might help; there are many other comparisons available for the cost of a search.
The following lists of apt
and apt-get
commands is not intended to be a comprehensive list, and the "Explanation" column omits many details that may be significant to your usage! Always refer to the appropriate man
pages if you have questions.
Command | Explanation |
---|---|
df -h |
check available space; apt doesn't do this automatically, so it's up to you |
sudo apt update |
updates the system's "Package List" from all configured sources |
sudo apt upgrade |
upgrade all installed packages to the latest version from the sources enumerated in /etc/apt/sources.list , but under no circumstances are currently installed packages removed, or packages not already installed retrieved and installed. This is the "foolproof" version of an upgrade. |
sudo apt full-upgrade |
upgrade all installed packages to the latest version from the sources enumerated in /etc/apt/sources.list . It will add & remove packages if needed to upgrade the system. |
sudo apt-get dist-upgrade |
Roughly equivalent to apt full-upgrade . Upgrade all installed packages to the latest version from the sources enumerated in /etc/apt/sources.list . It will add & remove packages if necessary, and attempts to deal "intelligently" with changed dependencies. Exceptions may be declared in apt_preferences(5) . |
unattended-upgrades |
A script to download and install upgrades automatically and unattended. It is run periodically by APT's systemd service (apt-daily-upgrade.service), or from cron (e.g. via /etc/cron.daily/apt). Operation is configured via file at /etc/apt/apt.conf.d/50unattended-upgrades |
sudo reboot |
when in doubt, or if "weird" things happen! REFERENCE |
Command | Explanation |
---|---|
apt search XXXX |
Compared to apt-cache search XXXX , a less-compact, but more detailed listing. Take your pick! Can be verbose, so consider piping into a pager (apt search XXXX | less ) |
apt-cache search XXXX |
You always need the exact name of package "XXXX" - this is one way to get it. If you're looking for a package, and recall only that its name contains the characters `priv`, then `apt-cache search priv` should list all matching packages in the repository. |
apt list --installed |
Displays list of packages satisfying certain criteria (e.g. --installed ), or matching a glob pattern. |
apt show XXXX |
Show information about package(s) XXXX including dependencies, installation size, sources, etc. |
sudo apt install XXXX |
Install package(s) named "XXXX" |
sudo apt remove XXXX |
Remove a package "XXXX", leaving its configuration files on the system |
sudo apt autoremove |
Remove packages that were automatically installed to satisfy dependencies for other packages, and are no longer needed due to dependency changes. |
sudo apt purge XXXX |
Remove a package "XXXX", deleting its configuration files from the system |
sudo apt edit-sources |
Opens /etc/apt/sources.list file for editing, and performs some basic sanity checks on the edited file. |
When available, it's usually best to install packages using apt
or apt-get
. But on occasion, you may need to install a .deb
package. Here's a summary of how to do that:
$ sudo dpkg -i ./some_pkg.deb # from the folder where the .deb file is located
# ...
# Many times this will end well, but you may be notified that one or more dependencies
# have not been met; e.g.
some_pkg depends on libwhatever; however:
Package libwhatever is not installed.
# ...
# The solution:
$ sudo apt-get -f install
# ...
Setting up libwhatever...
Setting up some_pkg.deb...
# refer to man apt-get for details
N.B: This is typically not a reliable method to upgrade Raspbian (though it often works well with some distributions)
To do an in-place upgrade of the OS; e.g. from jessie to stretch:
Opinions vary on the details, but in general: (note: sudo
needed for all commands, but omitted for brevity):
-
sudo apt-get update
,... upgrade
,... dist-upgrade
-
Verify no issues exist in previous updates or upgrades:
dpkg --audit
dpkg --get-selections | grep hold
-
BACKUP!!!
-
change
jessie
tostretch in
/etc/apt/sources.list` -
... update
,... upgrade
,... dist-upgrade
again (which may take a while!) -
reboot
-
cat /etc/os-release
to verify the upgrade was successful
NOTE: This recipe augments one at the raspberrypi.org website on the same subject- but lost in the great documentation re-shuffle, and from this source for linux tutorials.
- Debian CLI for APT package management tools
- Uninstalling Packages With Apt Package Manager
- Q&A: clean, autoclean, and autoremove — combining them is a good step?
- Why you need apt-get clean options?
- Debian / Ubuntu Linux Delete Old Kernel Images Command
- A Guide to Yum and Apt
- Chapter 4. Upgrades from Debian 9 (stretch)
- How to upgrade Debian 9 to Debian 10 Buster using the CLI
- How to Configure sources.list on Debian 10
- Ubuntu ‘apt-get’ list of commands (list, update, upgrade, cheatsheet)
- How to Install Development Tools on Debian 10/9/8
- 10 Cool Linux Terminal Commands - a couple of these actually do look cool!
- Debian Package Dependencies; another useful guide from Frank Hofmann
- Q&A: How to let
dpkg -i
install dependencies for me?