Ubuntu on mac

This is part of the Semicolon&Sons Code Diary - consisting of lessons learned on the job. You're in the virtual-machines category.

Last Updated: 2024-04-25

I realized that it is wasteful to learn macOS system tools when I deploy and test exclusively on Linux machines. What's more, with macOS being closed source, the opportunities for learning how things work are reduced, the documentation is worse, and generally my learning is limited.

Therefore I've resolved to do future development on Linux — but while still on my mac. A side goal would to test deploys/provisioning locally before putting them live.

The solution I've decided upon is vagrant with virtualbox using ansible to build stuff.

Prerequisites

brew cask install vagrant virtualbox
brew install ansible`

Starting a project

Chose an image and init

$ vagrant init ubuntu/xenial64

CLI Basics

Get things going (and load VirtualBox GUI if there)

$ vagrant up

Login with SSH

$ varant ssh

Shut down

$ vagrant halt

Delete

$ vagrant destory

Default credentials

Clipboard

You need to install tools to enable it

# Run all these commands on your host machine
vagrant plugin install vagrant-vbguest
# maybe if it does not work after provisioning
vagrant vbguest install
# Vagrantfile
config.vm.provider 'virtualbox' do |vb|
  vb.customize ['modifyvm', :id, '--clipboard', 'bidirectional']
end

# on a fresh install, ubuntu does not know ANY packages
sudo apt-get update
sudo apt-get install clipit

Windows Display (for GUI)

By default echo $DISPLAY gives nothing.

Will not be work unless you install a window manager:

sudo apt install xfce4
startxfce4&

You must also assign sufficient video RAM for it to work:

config.vm.provider 'virtualbox' do |vb|
  # Display the VirtualBox GUI when booting the machine
  vb.gui = true
  vb.customize ["modifyvm", :id, "--vram", "<vramsize in MB>"]
end

Run commands on provisioning

config.vm.provision 'shell', inline: 'sudo apt-get update'

What is virtualbox?

Dev process

Work on the code in the host machine (i.e. edit files etc.), but use config.vm.synced to sync to virtual machine.

In another tab run commands within the virtual machine.