Jacob Budin is a 29-year-old software developer. He works at Kettle and lives in Jersey City. He graduated Phi Beta Kappa from Penn State with degrees in English and marketing.

Saturday, May 14, 2016

How to Upgrade to Ubuntu 16.04 with Vagrant

Canonical released Ubuntu 16.04 LTS (Xenial Xerus) a few weeks ago. Ubuntu 16 includes many updated packages, and since Ubuntu 15.04, uses systemd in place of Upstart. To upgrade to Ubuntu 16.04 using Vagrant, you’ll need to make some changes to your project.

1. Upgrade local machine

Before you begin, make sure you’re running the latest version of VirtualBox and Vagrant. (If you’re having trouble upgrading VirtualBox on OS X and getting stuck on verifying, try rebooting your machine and then installing the package.)

2. Replace box image

In your Vagrantfile, replace config.vm.box to point to Ubuntu’s official “cloud” image distribution:

config.vm.box = "https://cloud-images.ubuntu.com/xenial/current/xenial-server-cloudimg-amd64-vagrant.box"

3. Destroy virtual machine

Next, you’ll need to replace your existing virtual machine. This will delete the contents of your virtual machine. If you do not use automated provisioning, you will have to reinstall all your packages and replace their configurations manually.

Important: Do not destroy your virtual machine if you cannot recreate your server’s system configuration.

$ vagrant suspend
$ vagrant destroy
$ vagrant up

4. Install VirtualBox Guest Additions

If you have trouble mounting synced folders using the default shared filesystem vboxsf, install VirtualBox Guest Additions:

$ vagrant ssh
$ sudo apt-get --no-install-recommends install virtualbox-guest-utils

And then exit and reload the guest machine: $ vagrant reload.

5. Add default synced folder

If you expect but cannot find /vagrant on your guest machine, you need to manually add it to your Vagrantfile:

config.vm.synced_folder "", "/vagrant"

6. Update provisioning

If you use automated provisioning, you’ll probably need to make some minor modifications.

Add missing dependencies

Packages you expected to be installed may no longer be installed by the base OS. You’ll need to add them to your provisioning manifests or install them manually using apt-get install.

Use new hostname

If you rely on the system hostname, you’ll need to update it to reflect the new default hostname: ubuntu-xenial.

Use new default user

The default user for this image is ubuntu. (Some Vagrant boxes previously had a vagrant user.)

Use systemd

If you use service to start, restart, or stop service, or if you have Upstart jobs, you may want to familiarize yourself with systemd and its systemctl command.

systemctl is used to manage systemd services. For basic system administration, it’s as easy as changing the syntax. For example, to reload nginx using service:

$ sudo service nginx reload

Whereas with systemctl:

$ sudo systemctl reload nginx

Lastly, reprovision your virtual machine ($ vagrant provision) until you’re satistified with your server’s configuration.