Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Linux Distributions»Ubuntu»How To Exclude Packages from Apt-Get Upgrade

    How To Exclude Packages from Apt-Get Upgrade

    RahulBy RahulApril 2, 20172 Mins ReadUpdated:September 29, 2020

    Sometimes we upgrade packages accidentally which is not to update. It also happens during the full update or automatic packages upgrade process. This creates serious issues on the server. For example, You need to exclude kernel, PHP, MySQL and Apache packages from getting updated while updating system via apt update. This tutorial will help you find the answer of how to exclude packages from Apt-get update? How to use exclude package in Ubuntu? How to prevent packages from auto update using apt?

    • How to Exclude Specific Packages from Yum Update

    Hold or Exclude Packages from Upgrade

    Use the following command to exclude or hold specific Debian package from an update. This will turn off the updates of specified packages from an automatic upgrade or manual upgrades.

    • Using apt
      sudo apt-mark hold package_name 
      
    • Using dpkg
      echo "package_name hold" | sudo dpkg --set-selections 
      
    • Using aptitude
      sudo aptitude hold package_name 
      

    Change the package_name with your actual package name to be set on hold.

    List Packages on Hold

    You can check the packages on hold anytime. Use the following command to view all packages already set to hold.

    sudo dpkg --get-selections | grep "hold" 
    

    exclude package upgrades with apt-get

    Unhold or Enable Package Upgrade

    In future, If you need to upgrade any package set on hold. You need to unhold any package before an upgrade. Use one of the following commands to unhold any package.

    • Using apt
      sudo apt-mark unhold package_name 
      
    • Using dpkg
      echo "package_name install" | sudo dpkg --set-selections 
      
    • Using aptitude
      sudo aptitude unhold package_name 
      

    Now, the unhold packages will be upgraded with apt upgrade or unattended upgrades.

    Conclusion

    In this tutorial, you have learned to hold packages from unnecessary upgrades. You can remove hold any time from package to allow upgrade again.

    apt dkpg hold package update
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Install Visual Studio Code Editor in SEL & openSUSE
    Next Article How To Upgrade to Ubuntu 17.04 (Zesty Zapus)

    Related Posts

    How to Install Composer on Ubuntu 22.04

    Updated:June 24, 20223 Mins Read

    How to Install Apache Kafka on Ubuntu 22.04

    Updated:June 5, 20225 Mins Read

    Setting Up Environment Variables on Ubuntu

    Updated:May 28, 20222 Mins Read

    How to Install Apache Solr 9.0 on Ubuntu 22.04

    Updated:May 26, 20223 Mins Read

    How to Install .NET Core (dotnet) on Ubuntu 22.04

    Updated:May 25, 20224 Mins Read

    Changing the Login Screen Background in Ubuntu 22.04 & 20.04

    Updated:May 9, 20222 Mins Read

    4 Comments

    1. Leonardo B. on November 12, 2020 5:18 pm

      Hi Rahul,
      In my experience, in Ubuntu 16.04 LTS, with kernel 4.15.0-120, if you want to ‘hold’ the kernel it in that version, but if you still have installed the packages:
      linux-image-generic
      linux-headers-generic
      linux-image-generic-hwe-16.04
      linux-headers-generic-hwe-16.04
      It will NOT work. Took me a while to figure it out, since apt-mark, aptitude hold, and dpkg –set-selections methods were not preventing the install of new version of the Linux kernel.

      Basically, remove these packages. They do not provide the kernel, so you won’t break the system.

      They are a placeholder for all kernel packages versions, so the apt system knows that it has to install (instead of update the package as it would be with all other packages — kernel is a special package in this concern!) a new package in order for the kernel to be updated.

      This worked for me:
      apt remove linux-image-generic linux-headers-generic linux-image-generic-hwe-16.04 linux-headers-generic-hwe-16.04

      I hope this helps someone else 🙂

      Reply
    2. Jack D. Ripper on July 25, 2018 9:23 am

      In the section: “Unhold or Include Package in Install”, the unhold command for aptitude is slightly wrong. Should be unhold not hold 🙂

      Reply
      • Rahul K. on July 26, 2018 5:34 am

        Thanks Jack, I have corrected the command.

        Reply
    3. Denilson on October 19, 2017 12:10 pm

      Thanks for the post!

      Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • Filesystem Hierarchy Structure (FHS) in Linux
    • How to accept user input in Python
    • What is difference between var, let and const in JavaScript?
    • What is CPU? – Definition, Types and Parts
    • What is the /etc/aliases file
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.