Debian
Debian administration tasks: check the release, update packages, set the locale and time zone, purge removed packages and boot to text mode.
2 min readUpdated
Everyday administration tasks on a Debian system. Run the commands as root, or prefix them with sudo.
Check the Debian version
Show the distribution, release number and code name:
lsb_release -alsb_release comes from the lsb-release package, which minimal installations and containers often lack. These two files are always present:
cat /etc/os-releasecat /etc/debian_versionUpdate the system
Refresh the package lists, then install the newer versions of the installed packages:
# update the list of available packages and their versions; installs nothingapt update# install newer versions of the installed packagesapt upgradeOr both in one line:
apt update && apt upgradeapt is the interactive front end. Scripts often use apt-get update && apt-get upgrade, whose output format stays stable between releases.
Change the locale
Uncomment the locales you need in /etc/locale.gen, for example tr_TR.UTF-8 UTF-8:
nano /etc/locale.genThen generate them:
locale-genAlternatively, dpkg-reconfigure locales shows the list as a menu, generates the selected locales and asks which one should be the system default. Log out and back in for programs to pick up the new setting.
Change the time zone
Choose the time zone from a menu:
dpkg-reconfigure tzdataThis updates both the /etc/localtime link and the Debian-specific /etc/timezone file. The Debian wiki recommends it over timedatectl set-timezone, which does not update /etc/timezone.
Purge removed packages
When a package is removed without purging, its configuration files stay on disk and dpkg marks it as deinstall.
List the selection state of every package:
dpkg --get-selectionsCount the packages in the deinstall state:
dpkg --get-selections | grep deinstall | wc -lPurge all of them at once. The pipeline changes each deinstall mark to purge, feeds the list back to dpkg, and dpkg -Pa then purges every package marked for purging:
dpkg --get-selections | grep deinstall | sed 's/deinstall/purge/' | dpkg --set-selections; dpkg -PaOn current releases (apt 2.0 and later), an apt search pattern does the same in one command and shows the list before acting:
apt purge '~c'~c (long form ?config-files) matches packages of which only configuration files are left.
Boot to text mode instead of the desktop
Make the system start without the graphical login manager:
systemctl set-default multi-user.targetTo start the desktop once from the text console, without changing the default:
systemctl isolate graphical.targetTo boot to the desktop again by default:
systemctl set-default graphical.targetBefore systemd (Debian 7 and earlier), the same was done by removing the display manager’s init script links with update-rc.d -f gdm remove and restoring them with update-rc.d gdm defaults.