brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: a minus after a package name lets apt-get install and remove in one go

Apt
~/tips/tip-apt-get-install-trailing-minus

sudo apt-get -s install chrony systemd-timesyncd-

Swaps one package for another in a single apt transaction.

Replacing one package with another usually takes two commands, and between them your system lacks both. apt-get can do it in one step.

Put a - right after the name of the package to remove, with no space:

sudo apt-get -s install chrony systemd-timesyncd-
sudo apt-get install chrony systemd-timesyncd-

This installs chrony and removes systemd-timesyncd in one transaction, so apt solves the dependencies for both together. The reverse also exists: in apt-get remove, a + after a name installs that package instead.

I like it for swaps where two packages conflict or provide the same thing, like time sync daemons, mail transfer agents or editors. apt sees the full picture at once instead of complaining halfway.

As always, simulate first. Ask it to remove tar this way, and apt refuses because dpkg depends on it. When apt can’t find a clean solution it stops with an error, but when it can, the plan may remove more than the one package you named, so read the Remv lines.

Watch the spacing. The minus has to touch the name. In a test, apt-get install wget - with a space simply ignored the lone minus, so the removal you wanted quietly doesn’t happen.

Further reading: apt-get(8) manual page

More Apt tips sudo apt-mark minimize-manual apt list '~c' grep -E ' (install|upgrade|remove) ' /var/log/dpkg.log | tail -o Dpkg::Options::="–force-confold" upgrade sudo apt-get -d -y full-upgrade All Apt tips (42) All topics

Link