Ubuntu: “The following packages have been kept back”

I was doing some work on an Invenio installation today, and I came across a warning that’s pretty common to Ubuntu: “The following packages have been kept back.” Here’s what happened, and here’s how to fix it.
Unless you’ve changed your message of the day file, when you log into an Ubuntu server it gives you some general system info. This is the MOTD I got when I logged in this morning:
Noticing that there were some packages that could be updated, I ran the normal update and upgrade commands:

sudo apt-get update && sudo apt-get upgrade

I expected that this would install the newest versions of whatever packages needed to be updated, but my server had something else in mind.

Why “The following packages have been kept back”?

The output of this warning isn’t very clear, and it begs the question: why? The message doesn’t tell us, so unless we know better it can be a confusing result.

Under normal circumstances running sudo apt-get upgrade would install the newest version of any packages installed on your computer. The problem is that sometimes the newest versions have new dependencies that weren’t required before.

apt-get checks for those new dependencies, and if they aren’t installed, the upgrade stops and we get this warning.

Resolution

We have to tell apt-get to install the updates and any dependencies they require. The command for that is:

sudo apt-get dist-upgrade

This is a pretty handy command, but an important warning from the AskUbuntu forums tells us this:

dist-upgrade will install all pending updates, with their new dependencies. If for some reason, you don’t want to do that, you should use apt-get install package-name dependency-package-name instead.

Now you know why those packages have been kept back and how to get your updates.