Setup a Lightweight Desktop Environment on your Raspberry Pi

In this tutorial we will setup a lightweight desktop environment on our raspberry pi, and setup a vnc server so that we can access our desktop interface over remote connection.

Our Setup:

  • RaspberryPi 2 with Raspbian Stretch Lite

Setup the Desktop Environment:

As I installed the lite version, we have no desktop or graphical user interface, therefore we will need to setup our desktop environment:

$ sudo apt update && sudo apt upgrade -y
$ sudo apt install --no-install-recommends xserver-xorg -y
$ sudo apt install --no-install-recommends xinit -y
$ sudo apt install raspberrypi-ui-mods -y
$ sudo apt install lightdm -y

Setup the VNC Server:

Install the VNC Server:

$ sudo apt install tightvncserver -y

Start the VNC Server:

$ vncserver :1

You will require a password to access your desktops.

Password:  
Verify:  
Would you like to enter a view-only password (y/n)? n  
xauth:  file /home/pi/.Xauthority does not exist

New 'X' desktop is raspberrypi:1

Creating default startup script /home/pi/.vnc/xstartup  
Starting applications specified in /home/pi/.vnc/xstartup  
Log file is /home/pi/.vnc/raspberrypi:1.log  

Verify that the service is running:

$ sudo netstat -tulpn | grep vnc
tcp        0      0 0.0.0.0:5901            0.0.0.0:*               LISTEN      2448/Xtightvnc  
tcp        0      0 0.0.0.0:6001            0.0.0.0:*               LISTEN      2448/Xtightvnc 

To have this server started every time the raspberry pi boots, you can enable it by setting the command to /etc/rc.local

Connect to your Desktop via VNC:

Head to https://www.realvnc.com/en/connect/download/viewer/ and get the VNC Viewer for your OS.

Once installed, open VNC Viewer and connect to your VNC Server by entering the address of your raspberry pi, in my case: 10.0.4.5:1

Once you have entered your password and it passes validation, you should see your desktop more or less like this:

Stop the VNC Server:

To stop the VNC Server on your raspberrypi:

$ vncserver -kill :1