Skip to content

Instantly share code, notes, and snippets.

@jai-o
Created February 18, 2019 20:59
Show Gist options
  • Save jai-o/29082a84eb7e5cd7e0e1b55fe92783dd to your computer and use it in GitHub Desktop.
Save jai-o/29082a84eb7e5cd7e0e1b55fe92783dd to your computer and use it in GitHub Desktop.
Setup Ubuntu Desktop VirtualBox on macOS

Setup Ubuntu Desktop VirtualBox on macOS

Start

  • install virtualbox
  • install vagrant

Install an OS in virtualbox

There are several ways to do this, but a quick easy way to get a base install with a development environment already configured would be to use an already configured box.

For e.g. laravel/homestead https://laravel.com/docs/5.7/homestead - Follow the instructions to install Homestead.

  • Edit the Homestead.yaml file so you can share folders between the Virtualbox and your host macOS

  • e.g. for the rest of the instructions, it is assumed that you've placed your Homestead directory in ~/Servers/Homestead

Setup the virtualbox with Ubuntu Desktop software

Once the above is all set up and you can vagrant ssh into your virtualbox:

  • sudo apt-get update

  • sudo apt-get install ubuntu-desktop

  • check in this file sudo nano /etc/ssh/sshd_config that the line X11Forwarding yes is set to yes

Install VNC for the server

  • sudo apt install xfce4 xfce4-goodies

  • sudo apt install tightvncserver

  • Startup the VNC Server, type vncserver

  • It will ask you to setup a password for when you try to connect to this

  • It will ask you to setup a view-only password, can say no

It will then create config files and set the new 'X' desktop as homestead:1

Example, something like this:

New 'X' desktop is homestead:1

Creating default startup script

Configure VNC Server

  • Kill the :1 instance that is running for now by typing in: vncserver -kill :1
  • Backup the original xstartup mv ~/.vnc/xstartup ~/.vnc/xstartup.bak
  • Edit the file nano ~/.vnc/xstartup and add these lines to the file:
~/.vnc/xstartup
#!/bin/bash
xrdb $HOME/.Xresources
startxfce4 &
  • Make the file executable: sudo chmod +x ~/.vnc/xstartup
  • Now startup the VNC server again: vncserver

Install VNC Viewer on local host machine (macOS)

Connect from local host machine to the VNC Server

  • Open up the VNC Viewer and connect to: 192.168.10.10:1 Or whatever IP address you set for Homestead

Additional Notes

  • It will log you in as root and you may want logout and login as vagrant

  • To reboot the system, can use the GUI to Shut down or reboot

  • If the GUI is having problems, in terminal, if you're in Homestead and the terminal prompt looks like vagrant@homestead, then you can type sudo reboot to reboot the system.

  • If you're at the macOS terminal prompt, and want to get into vagrant@homestead, then type: vagrant ssh

  • If you've rebooted the system, from the macOS terminal prompt: type vagrant ssh, then type vncserver to start up the server again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment