Running a VM with Vagrant¶
In this section you will find instructions on how to setup an Ubuntu 16.04 VM using Vagrant
Download Vagrant from the official web site. Choose the installer matching your operating system and architecture.
Installation process is straightforward, refer to Vagrant official documentation if you encounter any problems.
At the end of the installation process log out your system and log back in.
Open a terminal and type vagrant version. A message containing the installed version of Vagrant will be printed on the terminal
Installed Version: 2.0.2 Latest Version: 2.0.3 ...
Virtual Machine Setup¶
Now that Vagrant is installed let’s create our Ubuntu Virtual Machine. Open the terminal and create a new folder called vagrand. Within folder vagrand create a new file called Vagrantfile with following content.
Vagrant.configure(2) do |config| config.vm.box = "ubuntu/xenial64" # To automatically configure a private network uncomment following line. # config.vm.network "private_network", ip: "192.168.33.30" config.vm.provider "virtualbox" do |vb| # Customize the amount of memory on the VM: vb.memory = "4024" end # Port forwarding: If unneeded comment or remove following lines config.vm.network "forwarded_port", guest: 80, host: 8001 config.vm.network "forwarded_port", guest: 8000, host: 8000 config.vm.network "forwarded_port", guest: 8080, host: 8080 end
This Vagrantfile containing the settings for the virtual machine, notably the config.vm.box variable set to “ubuntu/xenial64” will tell Vagrant the specific VM we want to run (Ubuntu 16.04 “Xenial Xerus”, 64 bit version). Please take note of comments regarding private network setup, amount of memory and port forwarding within this file. Further visit official vagrant documentation for more explanations on fine tuning your VM.
To finally start the VM, run
The first time you run the command it is going to take some time since you do not have a locally available image of the Ubuntu 16.04 VM. Vagrant will download the VM from the Vagrant Cloud to your local system.
Bringing machine 'default' up with 'virtualbox' provider... ==> default: Box 'ubuntu/xenial64' could not be found. Attempting to find and install... default: Box Provider: virtualbox default: Box Version: >= 0 ==> default: Loading metadata for box 'ubuntu/xenial64' default: URL: https://vagrantcloud.com/ubuntu/xenial64 ==> default: Adding box 'ubuntu/xenial64' (v20180406.0.0) for provider: virtualbox default: Downloading: https://vagrantcloud.com/ubuntu/boxes/xenial64/versions/20180406.0.0/providers/virtualbox.box
At the end of the download process Vagrant will start the VM.
To access the Virtual machine, run
You need an SSH client for the previous command to work. Most Linux distributions come with an SSH installed. If you are using Windows as the guest operating system install MinGW or Cygwin or Git to obtain a command line SSH client. More information available here
You will be connected to the guest Virtual Machine over SSH as user vagrant. Vagrant provides all files next to your Vagrantfile in a folder called /vagrant at your VM.