Environment setup

Virtual Box

  • Installing VirtualBox, visit the VirtualBox website using this link

Vagrant (Windows)

  1. Installing Vagrant Go to the Vagrant download page at link, and under the “Operating System” heading, click on the appropriate “Binary” for your computer. The installer will be downloaded to your computer.
Choose AMD64 if you are using Windows 64bits
  1. Setting up the Ubuntu machine
    • List out the files in the home directory cd ~ using the ls command to check if Vagrant was successfully installed, you should find the file .vagrant.d.
    • After confirming the installation, create a directory for the Ubuntu setup using the mkdir
    • Change into the directory that you created
    • Run vagrant init command. Running this command automatically places a Vagrantfile in the directory created above. A Vagrantfile is a file that instructs Vagrant to create new Vagrant machines or boxes.
  1. run vagrant init alvistack/ubuntu-24.04 --box-version 20250802.1.1 then vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Box 'alvistack/ubuntu-24.04' could not be found. Attempting to find and install...
    default: Box Provider: virtualbox
    default: Box Version: 20250802.1.1
==> default: Loading metadata for box 'alvistack/ubuntu-24.04'
    default: URL: https://vagrantcloud.com/api/v2/vagrant/alvistack/ubuntu-24.04
==> default: Adding box 'alvistack/ubuntu-24.04' (v20250802.1.1) for provider: virtualbox (amd64)
    default: Downloading: https://vagrantcloud.com/alvistack/boxes/ubuntu-24.04/versions/20250802.1.1/providers/virtualbox/amd64/vagrant.box
    default:
==> default: Successfully added box 'alvistack/ubuntu-24.04' (v20250802.1.1) for 'virtualbox (amd64)'!
==> default: Importing base box 'alvistack/ubuntu-24.04'...
  1. SSH to your vagrant machine
    • Ensure your virtual box VM is running
    • Connect to the VM using vagrant ssh

Vagrant (macOS Apple Silicon)

  1. Check the architecture of your machine
$ arch
arm64

You can also use uname -m to check the architecture.

  1. Ensure Homebrew is installed
$ brew --version
Homebrew 4.6.9

If Homebrew is not installed, run the following command to install it:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  1. Install Vagrant via Homebrew
$ brew tap hashicorp/tap
$ brew install --cask hashicorp-vagrant
  1. Install QEMU via Homebrew
$ brew install qemu
  1. Install the vagrant-qemu plugin
$ vagrant plugin install vagrant-qemu
  1. Create a Vagrant workspace
$ mkdir ~/os-workspace
$ cd ~/os-workspace
  1. Initialize the Vagrantfile
$ vagrant init -m perk/ubuntu-24.04-arm64
  1. Start the Vagrant VM
$ vagrant up --provider qemu
  1. SSH into the Vagrant machine
$ vagrant ssh
  1. Destroy the VM when no longer needed
$ cd ~/os-workspace
$ vagrant status
Current machine states:

default                  running (qemu)
$ vagrant destroy
    default: Are you sure you want to destroy the 'default' VM? [y/N] y
==> default: Stopping the instance...
==> default: Destroying the instance..
$ vagrant status
Current machine states:

default                  not_created (qemu)

Reference

Vagrant SSH from VS Code

The following steps should be run in the VS Code terminal
  • Change to the directory containing the Vagrantfile
~$ cd $(vagrant_machine)
  • Get the SSH config that Vagrant uses:
~/$(vagrant_machine)$ vagrant ssh-config
Host default
  HostName 127.0.0.1
  User vagrant
  Port 2222
  UserKnownHostsFile /dev/null
  StrictHostKeyChecking no
  PasswordAuthentication no
  IdentityFile /Users/liz/vagrant/machine/.vagrant/machines/default/virtualbox/private_key
  IdentitiesOnly yes
  LogLevel FATAL
  • Copy the output of this into an SSH config file — I added it to my default SSH config at ~/.ssh/config. In VScode you can easily open this file, or generate a custom config file for VSCode to use, by pressing ⌘⇧P and selecting Remote-SSH: Open Configuration File…

  • Then connect to the host, you can also click on the Remote “Quick Access” status bar item in the lower left corner to get a list of the most common commands.

Bonus: if you put the config in your default SSH config file, you can now also SSH into the box from your laptop terminal with ssh default, saving you the bother of moving into the Vagrant machine’s directory.

Contributors

  • @黃頂軒
  • @Everydayhappy
Back to top