How To

Install Vagrant on Ubuntu: Setup and Getting Started Guide

If your team needs identical development environments across different operating systems, Vagrant is the tool that makes it effortless. Vagrant is a command-line tool by HashiCorp for building and managing virtual machines in a reproducible, shareable way. It supports multiple providers out of the box, including VirtualBox, Hyper-V, and Docker with additional providers like VMware, AWS, and Libvirt available through its plugin system. This guide walks through how to install Vagrant on Ubuntu and launch your first virtual machine in minutes.

Install Vagrant on Ubuntu from the Official Package

Vagrant requires a virtualization provider. VirtualBox is the default and the simplest option to get running. If it is not already on your system, install it first:

bashsudo apt updatesudo apt install virtualbox

The Vagrant package in Ubuntu’s default repositories tends to lag behind the current release. For the latest stable version, download the official .deb package directly from HashiCorp’s release server:

bashcurl -O https://releases.hashicorp.com/vagrant/2.2.9/vagrant_2.2.9_x86_64.deb

Once the download finishes, install it with apt:

bashsudo apt install ./vagrant_2.2.9_x86_64.deb

Verify the installation by printing the Vagrant version:

bashvagrant --version

A successful install outputs the version number; for example, Vagrant 2.2.9. Always check the official Vagrant downloads page before running the commands above to confirm you are grabbing the latest available release.

Set Up Your First Vagrant Project

A Vagrant project lives in its own directory and is defined by a Vagrantfile, a Ruby-based configuration file that describes how your virtual machine should be built and provisioned. Create a project directory and navigate into it:

bashmkdir ~/my-vagrant-projectcd ~/my-vagrant-project

Initialize the project using a specific Vagrant box. Boxes are pre-packaged base images that Vagrant uses to spin up machines. They are provider-specific, and you can browse thousands of community and official boxes at the Vagrant box catalog. This example uses the CentOS 8 box:

bashvagrant init centos/8

This creates a Vagrantfile in your project directory. Open it to review the default settings and adjust them to your needs. When ready, bring the virtual machine online:

bashvagrant up

Vagrant downloads the box image if not already cached, boots the VM, and configures the network. It also mounts your project directory inside the VM at /vagrant automatically, any file you edit on your host machine is immediately visible inside the environment.

Essential Vagrant Commands

Once your virtual machine is running, these are the commands you will reach for most often:

CommandWhat It Does
vagrant sshOpens an SSH session directly into the running VM
vagrant haltGracefully shuts down the VM, preserving its state
vagrant destroyRemoves the VM and all associated resources
vagrant statusShows the current state of the VM

Tip: Use vagrant halt when you plan to resume work later. vagrant destroy wipes the machine entirely, you will need to run vagrant up again and wait for the full provisioning cycle from scratch.

Vagrant removes the friction of setting up and maintaining development environments manually. Once you have a working Vagrantfile, any team member can replicate your exact environment with a single vagrant up command, regardless of whether they are on Windows, macOS, or Linux. That consistency is invaluable on collaborative projects. From here, explore Vagrant’s provisioning support for tools like Ansible, Chef, and Shell scripts to fully automate the environment inside your VM. Questions about your setup? Drop a comment below.

Cyber Defence

Recent Posts

rmmod Command in Linux: Remove Kernel Modules and Blacklisting

The rmmod command in Linux removes a loaded module from the running kernel. Because the kernel has…

19 hours ago

free Command in Linux: Check Memory Usage and Interpret Output

The free command in Linux gives you a quick summary of RAM and swap usage. It reads…

19 hours ago

diff Command in Linux: Compare Files and Create Patches

The diff command in Linux compares two text files line by line and shows the lines that…

19 hours ago

Flush DNS Cache on Windows, Linux, and macOS: Quick Commands

DNS cache is a temporary database your OS and browser build as you browse. Each time you visit a website, the domain-to-IP mapping is saved locally, cutting out the round trip to a remote DNS server on repeat visits. Stale entries are the most common reason to flush the DNS cache: a server moves to a new IP, but your OS or browser still routes to the old address. This guide covers how to clear the DNS cache on Windows, Linux, and macOS, and how to flush the separate cache stored inside Chrome and Firefox. Flush DNS Cache on Windows The command is the same on Windows 10, Windows 11, and earlier supported releases. Open Command Prompt with administrator privileges. Type cmd in the Windows search bar, right-click Command Prompt, and select Run as…

20 hours ago

Change User Password in Ubuntu: Command Line and GNOME GUI

Using a strong, unique password for every account is one of the most effective security…

2 days ago

Enable and Disable the Root Account in Ubuntu: Full Guide

Ubuntu locks the root account by default. New users often wonder what the root password…

2 days ago