Skip to content

Instantly share code, notes, and snippets.

@thinktanklinux
Created June 2, 2020 06:37
Show Gist options
  • Save thinktanklinux/673e8d4bc153f36bb41f7b30d892bcdd to your computer and use it in GitHub Desktop.
Save thinktanklinux/673e8d4bc153f36bb41f7b30d892bcdd to your computer and use it in GitHub Desktop.
Install Vagrant on Ubuntu
To install Vagrant on your Ubuntu system, follow these steps:
1. Installing VirtualBox
As mentioned in the introduction, we will provision the machines on top of VirtualBox, so the first step is to [install the VirtualBox package] which is available in the Ubuntu’s repositories:
sudo apt install virtualbox
If you want to install the latest VirtualBox version from the Oracle repositories, check this tutorial.
2. Installing Vagrant
The Vagrant package, which is available in Ubuntu’s repositories, is pretty outdated. We’ll download and install the latest version of Vagrant from the official Vagrant site.
At the time of writing this article, the latest stable version of Vagrant is version 2.2.6. Before continuing with the next steps, check the Vagrant Download page to see if a newer version is available.
Start by updating the package list with:
sudo apt update
Download the Vagrant package using the following curl command:
curl -O https://releases.hashicorp.com/vagrant/2.2.6/vagrant_2.2.6_x86_64.deb
Once the .deb file is downloaded, install it by typing
sudo apt install ./vagrant_2.2.6_x86_64.deb
3. Verify Vagrant installation
To verify that the installation was successful, run the following command which prints the Vagrant version:
vagrant --version
The output should look something like this:
Vagrant 2.2.6
Getting Started with Vagrant
Now that Vagrant is installed on your Ubuntu system let’s create a development environment.
The first step is to create a directory which will be the project root directory and hold the Vagrantfile file. Vagrantfile is a Ruby file that describes how to configure and provision the virtual machine.
Create the project directory and switch to it with:
mkdir ~/my-first-vagrant-projectcd ~/my-first-vagrant-project
Next, initialize a new Vagrantfile using the vagrant init command and specify the box you want to use.
Boxes are the package format for the Vagrant environments and are provider-specific. You can find a list of publicly available Vagrant Boxes on the Vagrant box catalog page.
In this example, we will use the centos/7 box. Run the following command to initialize a new Vagrantfile:
vagrant init centos/7
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
`vagrantup.com` for more information on using Vagrant.
You can open the Vagrantfile, read the comments and make adjustment according to your needs.
Run the vagrant up command to create and configure the virtual machine as specified in the Vagrantfile:
vagrant up
==> default: Configuring and enabling network interfaces...
default: SSH address: 192.168.121.74:22
default: SSH username: vagrant
default: SSH auth method: private key
==> default: Rsyncing folder: /home/linuxize/Vagrant/my-first-vagrant-project/ => /vagrant
Vagrant also mounts the project directory at /vagrant in the virtual machine which allows you to work on your project’s files on your host machine.
To ssh into the virtual machine, run:
vagrant ssh
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment