6

How do I upgrade a single Debian package without marking it as "manually installed"? apt install upgradeable-lib works of course, but then I have to apt-mark auto (or the package is no longer autoremoveable).

6

By poking at the sources, I found the feature you are looking for, but it was made available only in a commit made a few months ago, so is available only in bullseye (future Debian 11):

Support marking all newly installed packages as automatically installed

Add option '--mark-auto' to 'apt install' that marks all newly installed packages as automatically installed.

The equivalent configuration option (having no effect in Debian 10) is APT::Get::Mark-Auto.

| improve this answer | |
  • This probably won't hurt anything, but it could mark some packages as automatic when they are new installs and "should" be marked as manual. – Joe Aug 16 at 21:20
1

I ran into this awhile ago trying to install everything from an old install onto a new one using a package list provided by running dpkg -l on the old system.

This is handy if you want everything you had before, but can't remember all the things you installed over the life of the installed system.

The following script does this by trying to install everything using the install_new function. The trick is to run dpkg -s package-name first. If it doesn't find the package, it returns an error so you know the package is not installed.

The script below has a echo prefixed on the apt command, so it will be a dry run until you remove the prefix. This will allow you to review what it will do first so you can edit the input list and eliminate things you don't want to carry over to the new system or redirect the output of the script into a file to run later to do the installs. This is particularly useful because some "reinstalls" may fail, so you may need to fix things and edit the file to restart where you left off.

To use the script to generate an installation script, the other echo commands in the script need to be commented out.

#!/bin/bash

function install_new () {
  if [[ -z "$1" ]]
  then
    echo "install_new called with empty argument"
    rc=1
  else
    dpkg -s "$1" &> /dev/null
    rc=$?
    if (( rc ))
    then
      echo sudo apt-get install "$1"
      rc=$?
    else
      echo -e "\tSkipping [$1] - already installed"
      rc=1
    fi
  fi
  return ${rc}
}

while read package action
do
  echo "Package [${package}] Action [${action}]"
  action="${action:-install}"  ## If action is not present, default to install
  
  case "${action}" in
    # 
    "install")
      install_new "${package}"
    ;;
    #
    *)
      echo -e "\tDon't know how to ${action} ${package}"  
    ;;
  esac

done < "${1}"
| improve this answer | |
  • So this keeps the manually installed status as opposed to using dpkg --get-selections then set-selections – Ald In Aug 17 at 20:47
  • @AldIn Not sure what you mean. If you manually install a package, it makes sense for it to be marked manual, as my script will do, but since it would be unlikely to have another package that depends on it, it probably won't make any practical difference. What the script does is prevent already installed packages from being set to manual if they were automatic. – Joe Aug 19 at 6:09
  • "prevent already installed packages from being set to manual if they were automatic" is what I meant. Because there is no "upgrade only specified packages" semantic in Debian (seems to be a unique deficiency) so you have use apt install – Ald In Aug 21 at 22:38
0

You can't in apt, but the interactive mode of aptitude can do this.

I question why you want to do it though. Automatically-installed libraries are installed because something you've expressed a desire to install needs the library to function. By asking apt to install a different version of the library, you're expressing a desire to install it. It's no longer automatic - you have asked for it and apt will no longer consider it removable when dependent packages go away.

| improve this answer | |
  • Because somepkg might depend, directly or indirectly, on somelib. apt install somepkg will upgrade somepkg, but not necessarily somelib. apt install somelib will upgrade both the lib and all packages that break with the new lib version – Ald In Aug 8 at 17:01
  • 2
    Can you expand on how one would do it with aptitude? – Quasímodo Aug 8 at 17:14
  • Aptitude was great, but it seems not so well maintained lately, and has always been quite opinionated. Plus, it's not available on Termux – Ald In Aug 8 at 17:16
0

Since I got tired of copy/pasting, I've ended up writing aptup to do the simple job of upgrading specified packages (or choosing from a list of upgradables via dialog). apt-mark showauto pkg... prints the automatically-installed status, which can be restored after apt-install.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.