Installing Vagrant and VirtualBox

Video loading...

  • 0:01
    Vagrant Installing Vagrant and VirtualBox
  • 0:05
    with Emma Jane Westby
  • 0:09
    In this lesson, we're going to install VirtualBox, install
  • 0:12
    Vagrant, create a new directory to store the configuration files
  • 0:16
    for Vagrant, run the setup commands.
  • 0:18
    And then once we're all finished, we're
  • 0:20
    going to destroy the vagrant instance.
  • 0:23
    From the VirtualBox website, go ahead
  • 0:25
    and click on the link Downloads.
  • 0:28
    For your particular host system choose whichever
  • 0:31
    is the appropriate option for you to download.
  • 0:33
    So if you're running Windows, you would click the Windows link.
  • 0:36
    If you're running a Mac, then you would
  • 0:38
    click the OS X host link, et cetera.
  • 0:41
    I'm running OS X, so I'm going to go ahead and click that link.
  • 0:45
    Choose to save the file.
  • 0:47
    And we'll come back to this in a minute.
  • 0:49
    Click OK.
  • 0:51
    And while that's downloading, I'm now
  • 0:52
    going to switch over to the Vagrant website
  • 0:55
    and do the same thing-- find the appropriate link
  • 0:58
    and click Download.
  • 1:00
    On the Vagrant website I need to do the same thing again.
  • 1:03
    So from the top navigation menu, I'm going to select Downloads.
  • 1:09
    And then because I'm on a Mac, I'm going to go ahead and click
  • 1:12
    the Universal 32- and 64-bit download.
  • 1:15
    And click this link.
  • 1:17
    And once again, save the file.
  • 1:21
    I'm going to show you how I did the installation on my Mac.
  • 1:25
    There aren't any really gotchas for the other platforms.
  • 1:28
    All of the defaults are going to be fine for the installation.
  • 1:31
    However, you may need to reboot after installing Vagrant.
  • 1:36
    I know I definitely had to do this on my Windows 8 instance.
  • 1:41
    You might need to do it on Linux.
  • 1:42
    It depends on how the kernel drivers were
  • 1:44
    configured before you did the installation.
  • 1:47
    Vagrant installs new ones and sort of messes with things a bit
  • 1:52
    in a way that might require you to reboot.
  • 1:55
    Again, that's on Linux and Windows.
  • 1:57
    On a Mac, we're just going to step through and do the installation.
  • 2:01
    Nothing really exciting to worry about.
  • 2:05
    Once VirtualBox and Vagrant have finished downloading,
  • 2:07
    navigate to the folder or location where
  • 2:09
    you downloaded both of these binary files.
  • 2:13
    In my case, this lands in the Downloads folder.
  • 2:16
    In order to run Vagrant, you need to have VirtualBox accessible,
  • 2:20
    but it doesn't actually matter which one you install first.
  • 2:23
    You just can't run Vagrant before VirtualBox is installed.
  • 2:26
    So we'll go ahead and run that one first.
  • 2:33
    The process will be a little bit different for each
  • 2:35
    of the different hosts that you may be using.
  • 2:38
    Again, we're working on a Mac, so we'll
  • 2:40
    follow the instructions for the Mac.
  • 2:43
    It says here, double-click on the icon.
  • 2:48
    Downloaded off the internet, are we sure we want to continue?
  • 2:51
  • 2:53
    Now, these screens are going to be similar for each
  • 2:56
    of the different host machines.
  • 2:58
    So let's just walk through these steps.
  • 3:00
    First one, hi, welcome to VirtualBox.
  • 3:03
    Fine, Continue.
  • 3:05
    It's going to take up a chunk of space.
  • 3:08
    Doesn't really matter where it gets installed.
  • 3:10
    We can choose the default location.
  • 3:12
    And go ahead and click Install.
  • 3:16
    With VirtualBox installed, we are now ready to install Vagrant.
  • 3:19
    Once again, it's a matter of double-clicking
  • 3:21
    on the binary file you downloaded.
  • 3:24
    And according to whatever system you're using,
  • 3:27
    go through the installation procedure.
  • 3:39
    With Vagrant and VirtualBox installed,
  • 3:42
    we're now ready to create our first instance.
  • 3:45
    I'm going to do this just on the desktop
  • 3:47
    to show you how it quickly snaps together.
  • 3:50
    In subsequent videos, I'll put it into, perhaps,
  • 3:53
    a more sensible location.
  • 3:54
    But let's just take a look at how this works.
  • 3:57
    I'm going to make a new directory for our test install of Vagrant,
  • 4:02
    change into that directory.
  • 4:05
    And then, once I'm here, I'm going to initialize
  • 4:09
    the folder as being a new vagrant instance.
  • 4:12
    Now, in this case, I'm specifying which box to use.
  • 4:15
    And I grab this box just off of the documentation for Vagrant.
  • 4:18
    It doesn't need to be anything magical.
  • 4:20
    It's OK to follow documentation.
  • 4:23
    So Vagrant in it and then the name of the box, and the location.
  • 4:29
    Once we've got our Vagrant file in place,
  • 4:31
    we went from an empty directory to a directory with a Vagrant file.
  • 4:39
    We'll go into this in a little more detail later on, but just
  • 4:42
    to show you what's in here, there's a bunch of stuff, including the URL
  • 4:47
    for the box and the name of the virtual environment.
  • 4:52
    Like I said, we'll get into this stuff later on.
  • 4:54
    We just want to try it out for now.
  • 4:56
    So we've done our Vagrant in it and now we're going to do a Vagrant up.
  • 5:00
    This is basically saying start the machine or power on.
  • 5:06
    This Vagrant up process can take quite a while the very first time,
  • 5:10
    especially if you need to download that base box.
  • 5:13
    So again, be patient, this could take a while.
  • 5:19
    The next step that you need to do is try
  • 5:22
    to actually get into the machine.
  • 5:26
    It's going to depend on your host system how you do this,
  • 5:30
    but on a Mac, I can simply say vagrant SSH.
  • 5:34
    And if everything's worked, I've now logged into my Ubuntu machine.
  • 5:38
    Pretty cool, right?
  • 5:39
    I've got Ubuntu installed on top of OS X.
  • 5:43
    On Windows, you'll need to do a little bit of configuring,
  • 5:46
    if you want to be able to run the command vagrant SSH.
  • 5:49
    I'm not going to worry about that.
  • 5:51
    I'm just going to get you to use Putty instead.
  • 5:54
    You can download this SSH client from
  • 5:58
    When the configuration or the login screen comes up,
  • 6:01
    you'll want to use the host name of
  • 6:05
    this is local host-- and the port 2222.
  • 6:10
    Typically with an SSH connection you're going to use port 22,
  • 6:14
    but we're going to be using port 2222.
  • 6:18
    Your user and password are both vagrant.
  • 6:21
    You can use an SSH client from Mac and Linux as well,
  • 6:26
    but it's just as easy to use that Vagrant SSH command,
  • 6:29
    once it's configured.
  • 6:31
    Now let's get out of the box and destroy it,
  • 6:33
    just so that we can see how easy this is.
  • 6:36
    We really want to get into the habit of making things that feel
  • 6:39
    like they might be hard, automated, and natural, because, ultimately,
  • 6:45
    we don't want to get stuck with a fragile or brutal system.
  • 6:48
    We always want to be able to get in and out
  • 6:50
    of those systems using our start-up scripts.
  • 6:52
    So I'm going to exit from a Ubuntu box.
  • 6:56
    And then I'm going to destroy the machine.
  • 6:59
    Now, we just made it.
  • 7:00
    We can make it again later on.
  • 7:02
    It's not a big deal to destroy the machine at this point.
  • 7:04
    There's nothing stuck inside of it.
  • 7:07
    So I'm going to say vagrant destroy.
  • 7:11
    Are you sure?
  • 7:12
    Yup, I'm sure.
  • 7:15
    It shuts down the virtual machine and then
  • 7:18
    destroys anything associated with it.
  • 7:21
    So now, if I go and take a look in my virtual machine folder,
  • 7:25
    it should be empty.
  • 7:26
    There shouldn't be any large binary files kicking around.
  • 7:31
    I'm going to navigate to my home directory and then VirtualBox VMs.
  • 7:35
    And we can see here that this folder is now empty.
  • 7:38
    If I were to create a new machine, I'd get a folder in here
  • 7:41
    with the disk image for that particular VirtualBox.
  • 7:47
    Back at the command line, I'm going to type in vagrant
  • 7:50
    up again to create a new box.
  • 7:53
    This way you can see where the virtual machine shows up and then
  • 7:56
    disappears when I type in vagrant destroy.
  • 8:04
    The new machine's created.
  • 8:06
    And now if I go take a peek in my Finder, you can see it here.
  • 8:09
    This test install.
  • 8:10
    And if I go ahead and destroy the machine,
  • 8:25
    you can see that the file is now gone.
  • 8:27
    So again, if you want to clean up your machine,
  • 8:29
    this is the way to do it.
  • 8:31
    In summary, install VirtualBox, install
  • 8:34
    Vagrant using the defaults for both.
  • 8:37
    Then proceed to create your first Vagrant instance.
  • 8:40
    Create a new directory to store the configuration files,
  • 8:44
    run the setup commands, and then when you're finished,
  • 8:47
    go ahead and destroy the Vagrant instance.
  • 8:50
    The vagrant commands that we used were vagrant init.
  • 8:53
    We also needed to name the base and give a URL for the base box.
  • 8:59
    Then we ran vagrant up, vagrant SSH, or used
  • 9:04
    Putty to log in through SSH.
  • 9:06
    And finally, we exited from our Ubuntu machine
  • 9:09
    and destroyed the box.
Loading ...

Installing Vagrant and VirtualBox


Note: This video is outdated. The following command:

$ vagrant init precise32 has download problems if you try it. Try this instead:

$ vagrant init hashicorp/precise64

(The written instructions below contain this update.)

Before we jump into the automation of creating a new developer environment, we need to get the building blocks we'll be working with. You will need to download and install both Vagrant and VirtualBox.

Lesson Outcomes

By the end of this lesson, you will be able to install Vagrant and VirtualBox on a host platform of OSX, or Windows; and create and destroy a Vagrant instance.

Lesson Summary

  1. Install VirtualBox
  2. Install Vagrant
  3. Create a new directory for your configuration scripts. e.g. Websites, or Work-environments. This folder will not contain the VirtualBox binary files, just the Vagrant configuration scripts.
  4. From the command line, run the following commands:
    • $ vagrant init hashicorp/precise64
    • $ vagrant up
    • $ vagrant ssh
      Note: this command will not work for Windows. You will need to use PuTTY to log into your machine. This is covered in the bonus lesson.
  5. To return to your host machine, run the command:
    • $ exit
  6. To destroy the VM and remove the binary disk image:
    • $ vagrant destroy
      This command must be run from the directory which contains the Vagrantfile for the box you wish to destroy. It will not remove any of your configuration files. To recreate the machine, use the commands in step 4.

Troubleshooting and Gotchas

  • The lessons were recorded using Vagrant 1.4.3, and VirtualBox 4.3.6.
  • There are some gotchas to be aware of: Linux and Windows may need a reboot because of the kernel drivers being added.
  • Sometimes upgrades don't work, and re-installing is your best bet. If you have automatic software updates turned on, and Vagrant stops working for you without an obvious reason, try removing everything and re-install using the instructions in this lesson. Removing Vagrant and VirtualBox are covered in one of the extra lessons.
Additional resources: 

VirtualBox Downloads
Vagrant Downloads

Note: another common tool for creating development environments today is Docker, which is becoming very popular with Drupal (and other) developers. Take a look at our Drupal Development with Docker series to learn more.