How to install VNC on Ubuntu?


1. Create a security group rule for TCP for VNC ports 5900-5910 and add it to your instance. See the security group guide here.



2. Install a VNC server on your instance.

sudo apt install tigervnc-standalone-server -y


Please Note: 
See this wiki for advanced configurations.
Download and install a VNC client on your local system. See RealVNC Viewer.

Generic

How to install a Gnome or XFCE4 desktop on Ubuntu for VNC?

There are multiple desktop environments available to use with VNC, here we describe how to install Gnome or XFCE4.


Gnome


1. Install the Gnome desktop environment on your instance.

sudo apt update && sudo apt install gnome-shell -y


Generic
Please note: Do not install the ubuntu-gnome-desktop package. Doing so will install other unnecessary packages that will permanently break your instance.


2. Start a VNC server session (with a (barebones) gnome-shell).

vncserver :1 -xstartup gnome-shell
Generic
HTML
vncserver :1 -xstartup startxfce4

3. Connect to your desktop using the information provided by the VNC server command. For example, you should see a port number that you can connect to.

Generic
vncext:      Listening for VNC connections on local interface(s), port 5901

XFCE4


1. In order to create a xfce4 environment, install XFCE desktop environment on your instance:

sudo apt install xfce4 -y
sudo apt install xfce4-terminal -y
# The update-alternatives fixes the terminal icon on the desktop
sudo update-alternatives --set x-terminal-emulator /usr/bin/xfce4-terminal.wrapper

2. Start a VNC server session:

vncserver :1 -xstartup startxfce4


3. Connect to your desktop using the information provided by the VNC server command. For example, you should see a port number that you can connect to.

vncext:      Listening for VNC connections on local interface(s), port 5901