What happens with package when I upgrade rather than removing and reinstalling? What is the real difference between the two? How will the results differ?

Are following two options equal (by package preinst/postint/prerm/postrm steps) ?

apt-get update
apt-get remove <packagename>
apt-get install <packagename>


apt-get update
apt-get install --only-upgrade <packagename>

Can you handle upgrade command specially? Is it possible to make a handler for upgrade instead of deleting and installing?

  • I don't understand your question. Jul 27, 2015 at 9:53
  • Wen you remove package: dpkg -r <packagename> Its including few steps, such as calling a prerm/postrm script. When you executing dpkg -i <packagename> The preinst/postint scripts from .deb package will calling. What scripts will calling if I try to exec apt-get install --only-upgrade <packagename> ?
    – Sild
    Jul 27, 2015 at 10:18
  • 1
    Your comment is clearer than your question. I recommend editing your question to make it clearer. Jul 27, 2015 at 10:38
  • 1
    Ok, your question is clearer now. However, I still don't understand what you mean by "is it possible to make a handler for upgrade instead of deleting and installing?" What do you mean by a handler? Jul 27, 2015 at 15:02
  • 1
    The Debian wiki has some handy flowcharts that explain what scripts are called in what order when you install, remove or update a package: wiki.debian.org/MaintainerScripts
    – n.st
    Jul 27, 2015 at 17:15

3 Answers 3


Upgrading a package is not the same thing as removing and then installing it. Upgrading takes care to minimize the time during which the package isn't fully operational, whereas removing then installing leaves a window during which none of the package's files are present. Apart from that, they don't run the same maintainer scripts: upgrading runs the maintainer scripts (old prerm, new preinst, old postrm, new postinst) with the upgrade action, whereas removing then reinstalling runs old prerm remove, old postrm remove, new preinst install, new postinst configure. See the Debian policy manual for details, or the wiki for diagrams.

If you're making deb packages and you want to do something special on an upgrade, do it for the upgrade action of the relevant maintainer script (usually postinst to upgrade configuration files and restart daemons).

  • That's exactly what I have searched. Thanks.
    – Sild
    Jul 28, 2015 at 7:54

To answer your question, dpkg calls the same scripts (on a per package basis) whether you are using --only-upgrade with apt or not. It makes no difference. --only-upgrade only affects which packages apt operates on. As the man page says:

       Do not install new packages; when used in conjunction with 
       install, only-upgrade will install upgrades for already 
       installed packages only and ignore requests to install new 
       packages. Configuration Item: APT::Get::Only-Upgrade.

When dpkg removes a package, the corresponding prerm/postrm scripts of that package are called. When dpkg installs a package, the corresponding preinst/postint scripts are called. And again, this is all run by dpkg. apt operates at a higher level.

  • This doesn't answer the question. The question is about the difference between upgrading vs removing + installing a package; it is not about the difference between installing with or without the --only-upgrade option. See the accepted answer for what the question is looking for.
    – JBentley
    Mar 16, 2021 at 15:25

"upgrade" means upgrade all packages which have newer versions available in the configured package repositories than the ones which you currently have installed.

"install" means add a particular package (with the latest available version), or upgrade to that version if an earlier version of the package is already installed.

Removing an installed package, before running install to upgrade it, is unnecessary, and might have unpleasant side effects.

It is good practice to run "upgrade" regularly, to get security updates for all packages you have installed.

  • The question is about upgrade package steps, which will run after apt-get install --only-upgrade <packagename>. Does it include only prerm/postrm, preinst/postinst steps?
    – Sild
    Jul 27, 2015 at 10:17
  • This does not answer the question.
    – JBentley
    Mar 16, 2021 at 15:28

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .