[TUTORIAL] 5 Ways to Disable the Install, Upgrade or Removal of a Package

Write tutorials for Linux Mint here
More tutorials on https://github.com/orgs/linuxmint/discu ... /tutorials and (archive) on https://community.linuxmint.com/tutorial
Forum rules
Don't add support questions to tutorials; start your own topic in the appropriate sub-forum instead. Before you post read forum rules
Post Reply
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

[TUTORIAL] 5 Ways to Disable the Install, Upgrade or Removal of a Package

Post by Welcome »

Here's 5 ways to disable the install, upgrade or removal of a package with apt, aptitude, dpkg, synaptic, and Linux Mint's update manager. If you have a package that you absolutely want to hold the version, disable installation, or prevent an upgrade, then these are the steps you'll want to use.

It is true that only one method may work for you. But, the multiple methods are provided to ensure you've got full control on a package, since it is possible that alternative methods may be used at some point in time.

Where appropriate, replace the word package below with the actual name of the package you wish to put on hold.
  1. apt-mark hold is used to mark a package as held back, which will prevent the package from being automatically installed, upgraded or removed.

    Code: Select all

    sudo apt-mark hold package
  2. aptitude hold will cause a package to be ignored by future safe-upgrade or full-upgrade commands.

    Code: Select all

    sudo aptitude hold package
  3. dpkg: A package marked to be on hold is not handled by dpkg, unless forced to do that with option --force-hold, and --set-selections will set package selections using file read from stdin.

    Code: Select all

    echo "package hold" | sudo dpkg --set-selections
  4. In Synaptic, search for package, click on it, and in the menu click lock (Package->Lock Version).
  5. In Linux Mint's Update Manager, click 'Edit'->'Preferences'->'Blacklist' and add package. If using "Automation", also click 'Edit'->'Preferences'->'Automation' and click on "Export blacklist to /etc/mintupdate.blacklist"
Edit: grammar
Last edited by Welcome on Fri Mar 19, 2021 2:12 pm, edited 1 time in total.
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

Re: [TUTORIAL] 5 Ways to Disable the Install, Upgrade or Removal of a Package

Post by Welcome »

Want to remove a hold on a package? Here's the ways to do this, and in some cases, gather some info on packages on hold...

Where appropriate, replace the word package below with the actual name of the package you wish to gather info on (or remove the hold).
  • apt-mark showhold is used to print a list of packages on hold.

    Code: Select all

    apt-mark showhold
  • apt-mark unhold is used to cancel a previously set hold on a package to allow all actions again.

    Code: Select all

    sudo apt-mark unhold package
  • aptitude show displays detailed information about one or more packages (but not the hold status).

    Code: Select all

    aptitude show package
  • aptitude unhold will allow a package to be upgraded by future safe-upgrade or full-upgrade commands, without otherwise altering its state.

    Code: Select all

    sudo aptitude unhold package
  • dpkg: get the list of package selections for all of your packages:

    Code: Select all

    dpkg --get-selections
  • dpkg: get the list of package selections of a single package:

    Code: Select all

    dpkg --get-selections package
  • dpkg: get the list of package selections on hold:

    Code: Select all

    dpkg --get-selections | grep "\<hold$"
  • dpkg: remove the hold:

    Code: Select all

    echo "package install" | sudo dpkg --set-selections
  • In Synaptic, search for package, click on it, and in the menu click lock (Package->Lock Version) to remove the checkmark.
  • In Linux Mint's Update Manager, click 'Edit'->'Preferences'->'Blacklist' and remove the package's name. If using "Automation", also click 'Edit'->'Preferences'->'Automation' and click on "Export blacklist to /etc/mintupdate.blacklist"
Welcome
Level 6
Level 6
Posts: 1026
Joined: Wed Aug 19, 2020 11:38 am

Re: [TUTORIAL] 5 Ways to Disable the Install, Upgrade or Removal of a Package

Post by Welcome »

Here's an example usage of these 5 ways. In this case, the system crashes if the user attempts to use Hypnotix. The problem is the GPU and video driver (and mpv) are causing the system to hang and crash, but the user doesn't have many other options due to the age of the laptop. Since the GPU and video driver work for all of the user's other needs, one solution is to disable or remove Hypnotix. The below script uses the 5 ways mentioned above to achieve this goal.

Code: Select all

#!/bin/bash
# Disable hypnotix on Studio 1747 Laptops

# run with sudo
if ((EUID != 0)); then
    #echo "Granting root privileges for script ( $(basename $0) )"
    if [[ -t 1 ]]; then
        # [[ -t fd ]]  True if file descriptor fd is open and refers to a terminal.
        sudo "$0" "$@"
    else
        echo "ERROR: stdout is either not open or this is not run from a terminal"
    fi
    exit
fi

echo "Disable the upgrade of hypnotix with apt, aptitude, dpkg, synaptic,"
echo "and Linux Mint's update manager. Change executable to message."
echo
echo "1. apt-mark hold is used to mark a package as held back, which will"
echo "   prevent the package from being automatically installed, upgraded"
echo "   or removed."
sudo apt-mark hold hypnotix
echo
echo "2. aptitude hold will cause a package to be ignored by future"
echo "   safe-upgrade or full-upgrade commands."
sudo aptitude hold hypnotix
echo
echo "3. dpkg: A package marked to be on hold is not handled by dpkg,"
echo "   unless forced to do that with option --force-hold, and"
echo "   --set-selections will set package selections using file read"
echo "   from stdin."
echo "hypnotix hold" | sudo dpkg --set-selections
echo
echo "4. In Synaptic, search for hypnotix, click on it, in menu click lock."
echo "Press Enter when this step is complete."
read x
echo
echo "5. In Linux Mint's Update Manager, click 'Edit'->'Preferences'->"
echo "'Blacklist' and add hypnotix. Then click 'Automation' and click"
echo "'Export blacklist to /etc/mintupdate.blacklist'."
echo "Press Enter when this step is complete."
read x
echo
echo "6. Deleting the desktop file..."
sudo rm /usr/share/applications/hypnotix.desktop
echo
echo "7. Replacing the executable with a short script with a message."
echo '#!/bin/sh' > /usr/bin/hypnotix
echo '# /usr/lib/hypnotix/hypnotix.py &' >> /usr/bin/hypnotix
echo "notify-send -u critical \"Hypnotix Incompatible\" \"Sorry, Hypnotix uses mpv which is not compatible with your GPU and video driver. Aborting...\"" >> /usr/bin/hypnotix
chmod 755 /usr/bin/hypnotix
chown root:root /usr/bin/hypnotix
echo
echo "8. In a separate terminal, test run 'hypnotix'. You should receive a"
echo "notice that Hypnotix uses mpv which is not compatible...."
echo "Press Enter when complete."
read x


Post Reply

Return to “Tutorials”