Up and running Ubuntu VM with Vagrant

Jimmy Liao
2 min readJan 30, 2021

Write down what I do for prepare the Vagrant on fresh macOS environment.

$ brew install --cask virtualbox
$ brew install --cask vagrant
$ brew install —-cask vagrant-manager
$ brew install vagrant-completion
(prepare whole new environment)
$ mkdir -p ~/workspace/vagrantenv/testserver
$ cd ~/workspace/vagrantenv/testserver

Can find more boxes at Vagrant Cloud.

Ex. https://app.vagrantup.com/ubuntu/boxes/bionic64

find the exactly link. https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20210125.0.0/providers/virtualbox.box

$ vagrant box add bionic64 https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20210125.0.0/providers/virtualbox.box
==> box: Box file was not detected as metadata. Adding it directly...
==> box: Adding box 'bionic64' (v0) for provider:
box: Downloading: https://app.vagrantup.com/ubuntu/boxes/bionic64/versions/20210125.0.0/providers/virtualbox.box
Download redirected to host: cloud-images.ubuntu.com
Progress: 40% (Rate: 9.9M/s, Estimated time remaining: 0:00:29)
...
==> box: Successfully added box 'bionic64' (v0) for 'virtualbox'!$ vagrant box list
bionic64 (virtualbox, 0)

init new configuration for bionic64, will auto-generate Vagrantfile

$ vagrant init bionic64
A `Vagrantfile` has been placed in this directory. You are now
ready to `vagrant up` your first virtual environment! Please read
the comments in the Vagrantfile as well as documentation on
`vagrantup.com` for more information on using Vagrant.

modify Vagrantfile. Since I will prepare the VM for MicroK8S, will use at least 2 CPUs and 8G RAM, also set preferable VM name.

Vagrant.configure("2") do |config|
config.vm.box = "bionic64"
config.vm.provider "virtualbox" do |vb|
vb.name = "testserver"
vb.cpus = 2
vb.memory = "8192"
end
config.vm.provision "shell", inline: <<-SHELL
snap install hello-world
apt-get update
apt-get install -y vim tmux jq curl wget
SHELL
end

boot up

$ vagrant up

ssh to check

$ vagrant ssh

shutdown the vm (why not the vagrant down????)

$ vagrant halt

--

--

Jimmy Liao

🏃Leisure Runner (completed full marathon * 12), 🤓Fullstack, 🐵 React Native / Golang / Node Practitioner, 🐧 Flutter Starter, Life-Hacker, DevOps Starter