The apt command-line interface is a powerful tool that enables users to search for packages, install or remove them, and upgrade the system. This how-to guide will explain how to use the apt package manager in Debian without needing GUI package managers like Synaptic or Discover.
Since apt can do system-wide changes, it needs root or sudo privileges. If your system has root or sudo enabled depends if you set a root password during installation. If you set a root password, you can use root. If you didn't set one, you must use sudo.
Open a terminal with Ctrl + Alt + T.
You should then get a command prompt like this:
Code: Select all
hallvor@debian:~$
Using root
You can switch from user to root by typing in the following command and pressing enter. Notice the - after su.
Code: Select all
hallvor@debian:~$ su -
Code: Select all
root@debian:~#
Code: Select all
hallvor@debian:~$ sudo apt update
In this howto, we'll use root (#) for the examples.
In order to edit your sources.list, you can use the apt edit-sources-command
Code: Select all
# apt edit-sources
To exit and save in Vim:
Press "Esc" to enter command mode. Type ":wq" to write the file out to disk and quit vim. Press "Enter" to execute the command.
Update the package lists
It is always a good idea to update the package lists before installing anything to ensure that you have the latest package information. If you have edited your sources.list
Code: Select all
# apt update
Install upgrades
If there are any updates, you can install them with
Code: Select all
# apt upgrade
Search for an application
We can search for an application with the search command. In order to search for the multimedia player VLC, we can use this command:
Code: Select all
# apt search vlc
Some searches will give too many results, resulting in output that is only partial. One solution is to pipe the output into less:
Code: Select all
# apt search vlc | less
To exit less, you can press the q key.
Show information about a package
The show-command will give extensive information about a given package, including its dependencies, installation and download size.
Code: Select all
# apt show vlc
Package: vlc
Version: 3.0.18-0+deb11u1
Priority: optional
Section: video
Maintainer: Debian Multimedia Maintainers <debian-multimedia@lists.debian.org>
Installed-Size: 237 kB
Provides: mp3-decoder
Depends: vlc-bin (= 3.0.18-0+deb11u1), vlc-plugin-base (= 3.0.18-0+deb11u1), vlc-plugin-qt (= 3.0.18-0+deb11u1), vlc-plugin-video-output (= 3.0.18-0+deb11u1)
Recommends: vlc-l10n (= 3.0.18-0+deb11u1), vlc-plugin-access-extra (= 3.0.18-0+deb11u1), vlc-plugin-notify (= 3.0.18-0+deb11u1), vlc-plugin-samba (= 3.0.18-0+deb11u1), vlc-plugin-skins2 (= 3.0.18-0+deb11u1), vlc-plugin-video-splitter (= 3.0.18-0+deb11u1), vlc-plugin-visualization (= 3.0.18-0+deb11u1)
Suggests: vlc-plugin-fluidsynth (= 3.0.18-0+deb11u1), vlc-plugin-jack (= 3.0.18-0+deb11u1), vlc-plugin-svg (= 3.0.18-0+deb11u1)
Homepage: https://www.videolan.org/vlc/
Tag: hardware::storage, hardware::storage:cd, hardware::storage:dvd,
hardware::video, implemented-in::c, implemented-in::c++,
interface::commandline, interface::graphical, interface::x11,
protocol::ipv6, protocol::ssl, role::program, scope::application,
scope::utility, sound::compression, sound::player, uitoolkit::ncurses,
uitoolkit::qt, use::converting, use::playing, works-with-format::TODO,
works-with-format::mp3, works-with-format::oggtheora,
works-with-format::oggvorbis, works-with-format::wav, works-with::TODO,
works-with::audio, works-with::video, x11::application
Download-Size: 146 kB
APT-Manual-Installed: yes
APT-Sources: http://deb.debian.org/debian bullseye/main amd64 Packages
Description: multimedia player and streamer
VLC is the VideoLAN project's media player. It plays MPEG, MPEG-2, MPEG-4,
DivX, MOV, WMV, QuickTime, WebM, FLAC, MP3, Ogg/Vorbis files, DVDs, VCDs,
podcasts, and multimedia streams from various network sources.
.
VLC can also be used as a streaming server that duplicates the stream it
reads and multicasts them through the network to other clients, or serves
them through HTTP.
.
VLC has support for on-the-fly transcoding of audio and video formats, either
for broadcasting purposes or for movie format transformations. Support for
most output methods is provided by this package, but features can be added by
installing additional plugins:
* vlc-plugin-access-extra
* vlc-plugin-fluidsynth
* vlc-plugin-jack
* vlc-plugin-notify
* vlc-plugin-samba
* vlc-plugin-skins2
* vlc-plugin-svg
* vlc-plugin-video-splitter
* vlc-plugin-visualization
Installing an application
In order to install an application, we can use the apt install command. In order to install vlc and international translations, we can issue the following command:
Code: Select all
# apt install vlc vlc-l10n
Removing an application
In order to remove an application, we can use the apt remove command, for instance like this:
Code: Select all
# apt remove vlc vlc-l10n
Purging an application
In Debian, the purge command is used to completely remove an application along with its configuration files. This means that if you reinstall the program at a later time, it will be installed with its default settings.
Code: Select all
# apt purge vlc
View the apt log entries
Apt logs are located in /var/log/apt/history.log. We can view them conveniently with less:
Code: Select all
# less /var/log/apt/history.log
Saving a list of all your installed packages
You can use apt to save a list of all your installed packages.
Code: Select all
# apt list --installed > packages.txt
Code: Select all
# nano packages.txt
As mentioned, apt is a powerful tool that lets you set up your sources.list, view, install, remove, purge and save lists of your installed packages. I hope this was useful.
Edits:
10.04.23: Edited default directory after changing to root account. Thanks to itmicp for pointing it out. Added info about piping search results into less. Thanks to CynicalDebian.
11.04.23: Added location of apt's log. Thanks to CwF.