How to Install Vagrant on Ubuntu 22.04

Vagrant is a tool for building and managing virtual machine environments in a single workflow. With an easy-to-use workflow and focus on automation, Vagrant lowers development environment setup time, increases production parity, and makes the "works on my machine" excuse a relic of the past.

Install Vagrant

  1. To download and configure a GPG key for the HashiCorp package repository, run the command:

     wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
    

    This command downloads the GPG key for the HashiCorp APT repository, converts it from an ASCII armored format to a binary format, and stores it in the directory where APT looks for additional GPG keys.

  2. To add the HashiCorp software repository to the list of sources from which packages can be installed, run the command:

      echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
    

    This command creates a new file named hashicorp.list in the /etc/apt/sources.list.d/ directory with the repository entry for HashiCorp's packages. It ensures that your system's package manager (APT) will know where to find HashiCorp's packages and that it can verify their authenticity using the GPG key that was previously set up.

  3. To update the local list of available packages and their versions (it does not install or upgrade any packages), run the command:

     sudo apt update
    
  4. To install the latest version of Vagrant, run the command:

     sudo apt install vagrant
    

    At the time of the writing of this article, the Vagrant version is 2.4.0. Find the latest version by checking the developer's download page.

References:

  1. Introduction to Vagrant

  2. Install Vagrant