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: apt-get install --only-upgrade updates one package and never installs it new

Apt
~/tips/tip-apt-only-upgrade-one-package

sudo apt-get install --only-upgrade nginx

Upgrades a named package only if it is already installed, and never installs it as new.

Sometimes I want to update one package, for example a server, and nothing else. A plain install would also install it if it is missing, which is not what I mean.

The apt-get manual describes --only-upgrade like this: do not install new packages; used together with install, it installs upgrades for already installed packages only and ignores requests to install new packages. So the command touches only what you already have:

sudo apt-get install --only-upgrade nginx

If nginx is installed and a newer version is available, it gets upgraded. If nginx is not installed, nothing is installed, which is a nice safety net against a typo in the package name that happens to match another package. You can list several names, and the manual says package names are matched as regular expression, glob or exact name, so I would test a pattern with a simulation first:

apt-get -s install --only-upgrade 'php8*'

The -s flag only simulates the run. Look at the output to see which packages would be upgraded before you run it for real.

There is a sibling option with the opposite meaning, --no-upgrade. With install, it prevents packages named on the command line from being upgraded if they are already installed, which is handy when you want to add something and leave the rest as it is.

The caveat is that --only-upgrade still follows dependencies. The manual says it ignores requests to install new packages, but a newer version of the package may want new or changed dependencies, and apt works that out like it always does. The simulation shows this.

For a package I never want to move, apt-mark hold is the permanent version of this idea.

Further reading: apt-get(8): –only-upgrade and –no-upgrade

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