How to stop auto-update of a package on Ubuntu?

This is the most common and recommended method:

# Hold a specific package
sudo apt-mark hold package-name

# Hold multiple packages
sudo apt-mark hold package1 package2 package3

# Check which packages are held
apt-mark showhold

# Remove the hold
sudo apt-mark unhold package-name

Example:

sudo apt-mark hold apache2

Method 2: Using APT Preferences (Pinning)

Create a preferences file to pin a package to a specific version:

sudo nano /etc/apt/preferences.d/package-name-pin

Add content like this:

Package: apache2
Pin: release o=Ubuntu
Pin-Priority: 1

The Pin-Priority: 1 effectively blocks updates since any package with a higher priority will take precedence.

Method 3: Using APT Configuration

Create a configuration file to prevent automatic removal:

sudo nano /etc/apt/apt.conf.d/99autoremove

Add:

Apt::NeverAutoRemove {
    "apache2";
};

Method 4: Temporarily Skip Updates During Upgrade

If you just want to skip a package during a specific upgrade:

sudo apt upgrade --no-upgrade package-name

Important Considerations

  1. Security Updates: When you hold a package, you typically won't receive security updates for that package either, which can be a security risk.
  2. Dependency Issues: Holding packages can sometimes cause dependency conflicts with other packages that need newer versions.
  3. Alternative Approach: Instead of holding packages, consider:
    • Using Ubuntu backports for newer software
    • Keeping multiple kernel versions (Ubuntu does this automatically)
    • Using snap packages or flatpaks for applications

Best Practice

The apt-mark hold method is generally preferred because:

  • It's simple and straightforward
  • Easy to reverse with apt-mark unhold
  • Clearly shows which packages are held with apt-mark showhold
  • Widely supported and documented