Vagrant with VirtualBox with Ubuntu Step-by-Step

“If everyone has to think outside the box, maybe it is the box that needs fixing.” Malcolm Gladwell

Dog with boxes

Photo by Curology on Unsplash

The following is meant to be a checklist regarding how to install Vagrant inside VirtualBox in a Ubuntu 22.04 guest on a Windows host. It supplements https://www.keypuncher.net/blog/vagrant-intro-win-11 and https://www.keypuncher.net/blog/virtualbox-windows-host. I did this in Vagrant 2.4.3 and VirtualBox 7.1.4.

Download Your First Vagrant Box

First create a folder for all your boxes. Open up PowerShell on Windows and type the following:

mkdir vagrant_test

Then create another folder to house a Vagrant Box

cd vagrant_test

mkdir Ubuntu22.04-desktop

cd Ubuntu22.04-desktop

The box I’m using lives here: HashiCorp Cloud Platform. Note that this VM can take up to 128 GB! Make sure you have sufficient space.

To install it you can just use PowerShell as follows:

vagrant init caspermeijn/ubuntu-desktop-22.04 --box-version 2024.09.11

Then edit the Vagrantfile in your favorite text editor. Insert the following text:

# -*- mode: ruby -*-

# vi: set ft=ruby :

 

# All Vagrant configuration is done below. The "2" in Vagrant.configure

# configures the configuration version (we support older styles for

# backwards compatibility). Please don't change it unless you know what

# you're doing.

Vagrant.configure("2") do |config|

  # The most common configuration options are documented and commented below.

  # For a complete reference, please see the online documentation at

  # https://docs.vagrantup.com.

 

  # Every Vagrant development environment requires a box. You can search for

  # boxes at https://vagrantcloud.com/search.

  config.vm.box = "svetterIO/UbuntuDesktop22.04"

  config.vm.box_version = "1.0"

 

  # Optional: Install vbguest plugin to automate Guest Additions updates

  if Vagrant.has_plugin?("vagrant-vbguest")

    config.vbguest.auto_update = true

  else

    puts "WARNING: Install the 'vagrant-vbguest' plugin for automatic Guest Additions updates."

  end

 

  # Memory, CPUs, video memory  

  config.vm.provider "virtualbox" do |vb|

    vb.gui = true

    vb.name = "Ubuntu22.04_desktop_keypuncher"

    vb.memory = "12048"

    vb.cpus = 2

    vb.customize ["modifyvm", :id, "--vram", "32"]

    vb.customize ["modifyvm", :id, "--clipboard", "bidirectional"]

  end

end

Then in a terminal enter:

vagrant plugin install vagrant-vbguest

Then enter:

vagrant up --provider=virtualbox

This can take a while to download depending on your Internet speed.

When it’s almost done it should bring up a Vagrant/VirtualBox log in screen. Password and username are both vagrant — You may need to wait for the software to keep installing to ensure guest additions get installed. To do so, wait for the text in the PowerShell terminal to stop scrolling.

Vagrant login screen

Vagrant / VirtualBox login screen

After you log in you may be asked about:

  • Enable Ubuntu Pro — DON’T!

  • Up to you to send updates to Canonical. I did not.

  • I didn’t enable location services.

  • Upgrading to another version of Ubuntu. Decline this by clicking “Don’t Upgrade.”

Regrading Software Updates

  • I like to use the command line to install updates but you can also use the Software Updater GUI. Be careful though, unattended upgrades may already have beat you to it and be running in the background!  If that is the case it’s best to just wait a few minutes and let it finish. More on Ubuntu’s unattended upgrades can be found here: How to Configure Unattended Upgrades on Ubuntu 24.04, 22.04 or 20.04 - LinuxCapable.

Speaking of the command line, where is it? Go to Activities in the upper left of the screen, then search for “Terminal.”

Terminal Search In Activities

Terminal Search in Activities

This will bring up the terminal. Optionally, you can right click and add it to favorites as shown below:

Adding the terminal to favorites

Adding the terminal to favorites

The terminal can appear many different ways depending on the Vagrantfile chosen:

Gag me with a spoon! That’s a terrible font! If you want to fix it then click on the three bars near the top right corner of the screen as shown above.

In the resulting screen, click on the “+” button in the Profiles and add a font with any name you want. Here, I have added a Default profile:

Near the Default button is a downward facing triangle. Click on it to make “Default” the default profile.

I have specified more or less the following settings:

Text:

  • Custom font: FreeMono

Colors:

  • Green on Black

  • GNOME Pallet

  • Show bold text in bright colors

You of course are free to use whatever settings you like.

Installing Updates

If you use the command line to update enter the following in the terminal:

sudo apt update

sudo apt upgrade

Change Default Password!

After installing updates, you definitely don’t want to keep your default password for logging into vagrant! On the command line you can change your password with the passwd command:

passwd

After changing your password, you are going to want to shut down in case any of the updates have modified the kernel. To shutdown enter the following at the terminal:

sudo shutdown -h now

Next verify all your VirtualBox settings are what you want by following the instructions in the “VirtualBox Settings” section of this article: https://www.keypuncher.net/blog/vagrant-intro-win-11.

Enable VirtualBox Guest Additions

The minimal Ubuntu Vagrant install sometimes does not provide all the packages you need for the guest additions to work. To install them, start up your VirtualBox app and select the virtual machine you want:

Vagrant inside VirtualBox

VirtualBox with Vagrant Inside

Open up a terminal and enter the following:

sudo apt install build-essential dkms linux-headers-$(uname -r) wget bash-completion bzip2

In all likelihood since we have installed the vagrant-vbguest plugin above this probably isn’t necessary and you will be met with Ubuntu saying those packages are already installed, but it’s nice to double check.

If the Guest Additions still don’t work, try clicking on Devices > Upgrade Guest Additions…, wait for the update to finish or fail, and then rebooting the virtual machine. Mine failed, but the Guest Additions started working after that (weird).

NAT Forwarding

Ensure you have NAT https://en.wikipedia.org/wiki/Network_address_translation enabled if you wish to connect to the Internet on this guest. There are other networking options available in VirtualBox https://www.virtualbox.org/manual/ch06.html but I’m only covering NAT in this tutorial. See this article https://stackoverflow.com/questions/15580525/virtualbox-port-forwarding-not-working-with-nat-adapter should you need to set up more than one VirtualBox VM at the same time. Basically, you have to port forward ssh to something other than 2222.

Disable Screen Lock

https://linuxconfig.org/disable-turn-off-lock-screen-on-ubuntu-22-04-jammy-jellyfish-linux

Virtual Terminals

Most Linux flavors come with a feature called “virtual terminals” or “virtual consoles.”  Virtual terminals in Ubuntu work like so: Terminal 1 corresponds to the GUI and terminals 2-6 correspond to command line consoles. For example, to get to the 2nd virtual terminal press <CTRL> + <ALT> + <F2>.

See these links: Virtual console - Wikipedia and https://askubuntu.com/questions/33078/what-is-a-virtual-terminal-for.

Folder Sharing

https://www.keypuncher.net/blog/virtualbox-shared-folders

In the link above, this step is crucial:

sudo usermod -aG vboxsf $(whoami)

and then reboot the virtual machine!

Regarding Snapshots

See my article here: https://www.keypuncher.net/blog/virtualbox-windows-host-manjaro-guest.

And that’s it! You have successfully installed Vagrant inside of VirtualBox!

Feedback

As always, do make a comment or write me an email if you have something to say about this post!

Credits

Cover art for vagrant book

Cover Art for Vagrant Book

Previous
Previous

Introduction to Rust

Next
Next

Vagrant Introduction (Windows 11)