How I installed Vagrant in ubuntu 14.04 LTS

10 min. read

You will need to install two things:

  • Vagrant
  • A virtual machine

To install Vagrant, the best way is to go to their dedicated page:

There are several ways you can do this:

Installing Vagrant from package managers

In many blog posts around the web, you will find people recommending this way of installing, using apt-get install vagrant. This is not the recommended way, as stated in the official site:

"Beware of system package managers! Some operating system distributions include a vagrant package in their upstream package repos. Please do not install Vagrant in this manner. Typically these packages are missing dependencies or include very outdated versions of Vagrant. If you install via your system's package manager, it is very likely that you will experience issues. Please use the official installers on the downloads page."

Installing Vagrant from Source

Installing Vagrant from source is an advanced topic and is only recommended when using the official installer is not an option. This page details the steps and prerequisites for installing Vagrant from source.

But if you still want to install from source, here is the link:

Installing Vagrant from the official installers

Here is a list of the official installers for four different O.S. For ubuntu 14.04, download the Debian package. I have a 64bit machine, so I downloaded that package:

This will download a .deb file, that you can double click and it will be opened in Ubuntu Software Center, where you just have to click the "Install" button. Or you can install it through the terminal. Go to the folder where you installed it and type:

$ sudo dpkg -i vagrant_1.8.4_x86_64

After installing

Check that you have installed Vagrant correctly:

$ vagrant --version
Vagrant 1.8.4

The installer will create a directory for the Vagrant installation to live in /opt/vagrant directory, and will link to an executable in the /usr/bin/vagrant.

This way, when you uninstall Vagrant, you can do so very cleanly by doing:

rm -rf /opt/vagrant
rm -f /usr/bin/vagrant

The installer will also create a ~/.vagrant.d in your home directory:

$ tree .vagrant.d/
├── boxes
├── data
│   ├── machine-index
│   │   └── index.lock
│   └── checkpoint_signature
├── gems
│   └── ruby
│       └── 2.2.0
├── rgloader
│   └── loader.rb
├── tmp
├── insecure_private_key
└── setup_version

8 directories, 5 files

From the official book:

"Vagrant puts all global state by default into the ~/.vagrant.d folder, including boxes. This means that when Vagrant manages boxes “globally,” it actually means it manages boxes per user, by default. Because boxes can be large (sometimes gigabytes), you can move this global state directory by setting the environmental variable VAGRANT_HOME to another directory."

To do so, in your ~/.bashrc file, add:

# vagrant
export VAGRANT_HOME="$DATA/vagrant"

now run your bash file for the changes to take effect

$ . ~/.bashrc

You will need a Virtual Machine to run it

Make a directory somewhere and cd into it. Type:

$ vagrant init hashicorp/precise64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`` for more information on using Vagrant.

This creates a Vagrantfile which contains Ruby code, basically configuration stuff for Vagrant. The Vagrantfile is a simple text file that Vagrant reads in order to determine what needs to be done to create your working environment. This file is meant to be placed under version control.

Now if you do:

$ vagrant up
No usable default provider could be found for your system.

You get an error because you don't have any VM installed.

Go to Linux downloads page in VirtualBox's official site, and download the deb file for Ubuntu 14.04, in my case AMD64 because I have Intel 65 bits. Again you can double-click it and install it from the USC. You will have all these programs available from the terminal: VBox, VBoxAutostart, VBoxBalloonCtrl, VBoxDTrace, VBoxHeadless, VBoxManage, VBoxSDL, VBoxTunctl, VBoxVRDP, VirtualBox, rdesktop-vrdp, vbox-img, vboxautostart, vboxballoonctrl, vboxheadless, vboxmanage, vboxsdl, vboxwebsrv, virtualbox.

You can head of to the VirtualBox manuals:

Check that you have installed it properly:

$ virtualbox

This should open the VirtualBox GUI.

Now go ahead and repeat the previous command:

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'hashicorp/precise64' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: >= 0
==> default: Loading metadata for box 'hashicorp/precise64'
    default: URL:
==> default: Adding box 'hashicorp/precise64' (v1.1.0) for provider: virtualbox
    default: Downloading:
==> default: Successfully added box 'hashicorp/precise64' (v1.1.0) for 'virtualbox'!
==> default: Importing base box 'hashicorp/precise64'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'hashicorp/precise64' is up to date...
==> default: Setting the name of the VM: vagrant_default_1468152938049_45697
==> default: Clearing any previously set network interfaces...
==> default: Preparing network interfaces based on configuration...
    default: Adapter 1: nat
==> default: Forwarding ports...
    default: 22 (guest) => 2222 (host) (adapter 1)
==> default: Booting VM...
==> default: Waiting for machine to boot. This may take a few minutes...
    default: SSH address:
    default: SSH username: vagrant
    default: SSH auth method: private key
    default: Vagrant insecure key detected. Vagrant will automatically replace
    default: this with a newly generated keypair for better security.
    default: Inserting generated public key within guest...
    default: Removing insecure key from the guest if it's present...
    default: Key inserted! Disconnecting and reconnecting using new SSH key...
==> default: Machine booted and ready!
==> default: Checking for guest additions in VM...
    default: The guest additions on this VM do not match the installed version of
    default: VirtualBox! In most cases this is fine, but in rare cases it can
    default: prevent things such as shared folders from working properly. If you see
    default: shared folder errors, please make sure the guest additions within the
    default: virtual machine match the version of VirtualBox you have installed on
    default: your host and reload your VM.
    default: Guest Additions Version: 4.2.0
    default: VirtualBox Version: 5.0
==> default: Mounting shared folders...
    default: /vagrant => YOUR VAGRANT_HOME_HERE

If you open virtual box now, you will see Vagrant is loaded.