Spinning up a local environment using Vagrant

Quick Link – Github Project

Introduction

In this post, I described steps for setting up an Ubuntu virtual machine using Virtualbox, to connect to with Visual Studio Code. This allows you to do your development work inside a sandboxed Linux environment, while having the full functionality on Windows. This can be very useful if you don’t have local administrator rights to your machine, and don’t want to mess with cross platform tools like the Windows Subsystem for Linux (WSL) for compatibility. This is the setup I use at work most of the time. Recently, I needed to reimage my workstation, and rather than backing up and restoring the Virtualbox machine, I took the opportunity to start fresh.

Enter Vagrant

Rather than reinstalling Ubuntu manually from an ISO using the steps described in my previous article, I automated the entire method of bringing up the Ubuntu OS, and installing most of the needed packages using Hashicorp Vagrant.

Vagrant is a tool for building and managing virtual machine environments in a single workflow. The key of the process is creating a Vagrantfile, which describes the type of machine required for a project, and how to configure and provision the machine.

Instructions

The README.md in this Github repository has instructions for installing the required software, initializing Vagrant, and setting up an Ubuntu environment using a downloadable Vagrantfile. The file should be fairly easy to read, but ensure you adjust the values in the User Variables section to your preferences:

  • By default, the setup will create an Ubuntu LTS 22.04 “Jammy Jellyfish” 64-bit machine, with 2 CPUs, 8GB RAM, and will map port 2222 for SSH access.
  • It will also try to map a local “data” folder to /media/data in the virtual machine, so you can move files back and forth without having to set up another method for file transfer.
  • It will also create a new user other than “vagrant” for you to log in with. It will copy the custom Vagrant SSH keys to /home/newuser/.ssh, which can then be used with VS Code.

Note: On the first initialization of the machine, it may take a while to bring up the virtual machine the first time, as it will need to download the base OS box, then download and install all of the additional packages. Be patient. The virtual machine will reboot a few times during the process.

Once the machine is fully up, you can follow the instructions in the first article for connecting to the Virtualbox machine with VS Code.

Loading

Leave a Reply

Your email address will not be published. Required fields are marked *