I moved my WordPress blog to a VPS from DigitalOcean and I wanted to have a local version of my VPS for testing. This guide will teach you how to install an Ubuntu server as a virtual machine using VirtualBox on a mac. To prepare you will need to download 2 files:

For this tutorial I will be using VirtualBox on a Mac and installing Ubuntu Server 14.04 LTS as a virtual machine. This tutorial also assumes you are familiar with the Nano Text Editor.

Install VirtualBox

Installing VirtualBox is a very simple process. Open the VirtualBox file you download and double-click the package to install. Accept all the default options and VirtualBox will be installed on your local computer. At this point you can launch VirtualBox to start the process of installing the Ubuntu server virtual machine.

Create Ubuntu Virtual Machine

Using the VirtualBox application select New from the Machine Menu. VirtualBox Ubuntu Virtual Machines Here is a list of the options that you should choose as you progress through the Ubuntu virtual machine creation process:

  • Name = Ubuntu 14.04 LTS
  • Type = Linux
  • Version = Ubuntu (32 bit)
  • Memory = 512MB (or higher if your VPS has more memory)
  • Create a virtual hard drive now
  • Hard Drive File Type = VDI
  • VDI Storage = Fixed
  • VDI Size = 8GB

The virtual machine creation will take a few minutes.

Mount the Ubuntu Server Install Image

  • Select your new Ubuntu virtual machine and click the Settings button
  • Click the Storage tab
  • Under Controller: IDE, click the disk image that shows Empty
  • Click the disk icon next to the CD/DVD Drive drop down menu and select Choose a virtual CD/DVD disk file

VirtualBox Virtual CD Disk File

  • Navigate the open file screen to select the Ubuntu server install image that you downloaded
  • Click OK to close the settings page

Ubuntu Virtual Machine Installation

You are now ready to start your Ubuntu virtual machine for the first time by clicking the Start button. Your Ubuntu virtual machine will start by launching from the Ubuntu server install image you selected and guide you through the typical Ubuntu installation.

Options to choose (adjust as needed)

  • English
  • Install Ubuntu Server
  • English
  • United States
  • Detect Keyboard Layout = No
  • English
  • English
  • Hostname = ubuntu
  • New User = username (use username that will be deleted)
  • Encrypt Home Directory = No
  • Time Zone = Denver/Mountain (adjust for your timezone)
  • Partitioning method = Manual
  • Select VBOX HARDDISK
  • Create new empty partition table on this device = Yes
  • Select FREE SPACE
  • Create a new partition
  • New Partition Size = max
  • Type = Primary
  • Use as = Ext4 journaling file system
  • Mount point = /
  • Mount options = defaults
  • Label = none
  • Reserved blocks = 5%
  • Typical usage = standard
  • Bootable flag = off
  • Done setting up the partition

Ubuntu Partition Disk

  • Finish partitioning and write changes to disk
  • Do you want to return to the partitioning menu = no (you don’t want a swap created)
  • Write the changes to disk = Yes
  • HTTP proxy = blank for none
  • No Automatic Updates
  • Software Selection = OpenSSH Server
  • Install GRUB Boot Loader = Yes

First Boot – commands in VirtualBox window after logging in with username from installation

[sourcecode language=“bash”]sudo passwd root #enables root account sudo nano /etc/network/interfaces #add second interface below to allow connection from host auto eth1 iface eth1 inet static address 192.168.56.101 netmask 255.255.255.0 network 192.168.56.0 broadcast 192.168.56.255 sudo nano /etc/ssh/sshd_config #modify to allow root login via SSH PermitRootLogin yes sudo poweroff #power off virtual machine[/sourcecode]

Create VirtualBox Host-only Network

  • From the VirtualBox menu select Preferences
  • Click the Network tab
  • Click the Host-only Networks tab
  • Click the Add button to Add a new Host-only Network
  • Clock OK

VirtualBox Host-only Network

  • Select your new Ubuntu virtual machine and click the Settings button
  • Click the Network tab
  • Click the Adapter 2 tab
  • Click the Checkbox to Enable Network Adapter
  • Select Attached to Host-only Adapter
  • Select the Network Name vboxnet0
  • Click OK

VirtualBox Adapter 2

Second Boot – commands in ssh terminal

Select your new Ubuntu virtual machine and click the Start button. If everything was done correctly you can now login using your ssh client (Terminal on a Mac). [sourcecode language=“bash”]ssh [email protected] username=username #username chosen at installation deluser $username #delete ubuntu setup user rm -rf /home/$username #delete ubuntu setup user directory poweroff[/sourcecode] Your VirtualBox Ubuntu Virtual Machine should now be configured like a new DigitalOcean VPS with a root user enabled.