1. Home
  2. Maintenance
  3. How to Upgrade an Ubuntu Server

How to Upgrade an Ubuntu Server

Do you need to upgrade?

If you login to your server and notices that upgrades are available, like this:

46 packages can be updated.
13 updates are security updates.

Synchronize Your Packages

First you should synchronize your package indices:

$ sudo apt-get update
Used to re-synchronize the package index files from their sources.
The indexes of available packages are fetched from the location(s)
specified in /etc/apt/sources.list(5). An update should always be 
performed before an upgrade or dist-upgrade.

If you don’t update them, you may not get the latest available upgrades. You’ll see something like:

Hit:1 http://sfo1.mirrors.digitalocean.com/ubuntu xenial InRelease
Get:2 http://sfo1.mirrors.digitalocean.com/ubuntu xenial-updates InRelease [102 kB] 
Get:3 http://security.ubuntu.com/ubuntu xenial-security InRelease [102 kB] 
Hit:4 http://ppa.launchpad.net/certbot/certbot/ubuntu xenial InRelease 
Get:5 http://sfo1.mirrors.digitalocean.com/ubuntu xenial-backports InRelease [102 kB] 
Fetched 306 kB in 0s (373 kB/s) 
Reading package lists... Done

Upgrading Your Packages

Next, for safety, I stop the MySQL server, although the upgrade scripts likely do this too:

$ sudo service mysql stop

You can upgrade your server like this:

$ sudo apt-get upgrade

You’ll see something like this:

Reading package lists... Done
Building dependency tree 
Reading state information... Done
Calculating upgrade... Done
The following packages have been kept back:
 linux-generic linux-headers-generic linux-image-generic
The following packages will be upgraded:
 apparmor dh-apparmor eject initramfs-tools initramfs-tools-bin
 landscape-common libapache2-mod-php7.0 libapparmor-perl libapparmor1
 linux-libc-dev makedev php7.0 php7.0-bz2 php7.0-cli php7.0-common
 php7.0-curl php7.0-gd php7.0-json php7.0-mbstring php7.0-mcrypt php7.0-mysql
 php7.0-opcache php7.0-readline php7.0-tidy php7.0-xml php7.0-zip php7.1-bz2
 php7.1-cli php7.1-common php7.1-curl php7.1-gd php7.1-imap php7.1-json
 php7.1-mysql php7.1-opcache php7.1-readline php7.1-xml php7.1-zip
 python3-update-manager update-manager-core update-notifier-common
41 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.
Need to get 8,675 kB of archives.
After this operation, 22.5 kB of additional disk space will be used.
Do you want to continue? [Y/n] y

Then, you’ll see the upgrade proceed like these excerpts below:

Get:1 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main update-manager-core all 1:0.196.23 [8,194 B]
Get:2 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main python3-update-manager all 1:0.196.23 [32.0 kB]
Get:3 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main update-notifier-common all 0.154.1ubuntu3 [164 kB]
Get:4 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main eject amd64 2.1.5+deb1+cvs20081104-13.1ubuntu0.14.04.1 [23.4 kB]
Get:5 http://mirrors.digitalocean.com/ubuntu/ trusty-updates/main initramfs-tools all 0.103ubuntu4.7 [44.5 kB]
...
Fetched 8,675 kB in 9s (917 kB/s) 
Extracting templates from packages: 100%
Preconfiguring packages ...
(Reading database ... 102300 files and directories currently installed.)
Preparing to unpack .../update-manager-core_1%3a0.196.23_all.deb ...
Unpacking update-manager-core (1:0.196.23) over (1:0.196.22) ...
...
Setting up php7.1-zip (7.1.4-1+deb.sury.org~trusty+1) ...
Setting up dh-apparmor (2.10.95-0ubuntu2.6~14.04.1) ...
Processing triggers for initramfs-tools (0.103ubuntu4.7) ...
update-initramfs: Generating /boot/initrd.img-3.13.0-113-generic
Processing triggers for libc-bin (2.19-0ubuntu6.11) ...
Processing triggers for ureadahead (0.100.0-16) ...
Processing triggers for libapache2-mod-php7.0 (7.0.18-1+deb.sury.org~trusty+1) ...

What Does Kept Back mean?

You might also see that some packages are “kept back:”

Calculating upgrade... Done
The following packages have been kept back:
 linux-generic linux-headers-generic linux-image-generic
0 upgraded, 0 newly installed, 0 to remove and 3 not upgraded.

What Does Apt-Get Dist-Upgrade Do?

The upgrade command does not install packages that may create conflicts. For that you need, sudo apt-get dist-upgrade.

 

Updated on April 17, 2017

Was this article helpful?

Related Articles

Leave a Comment