Setup VNC server on Raspberry Pi

In this post, I will go through with you on how to setup vnc server on the Raspberry Pi. While the Raspberry Pi has a full HDMI port for output, it might be more convenient to access it remotely via ssh or if you would like a graphical interface, you would need to install a virtual network connection (vnc) server.

TightVNC is a good option and I will be using it.

To install TightVNC, head over to the terminal on your Pi and use the below command. You would be prompted to set a password. The password would be required when you are accessing it.

sudo apt-get install tightvncserver

Once it is installed, you might launch it by the below.


Start a new session by typing the below

vncserver :1

To access the screen on macOS, go to Finder and press Cmd + K. The server address would be vnc://raspberrypi.local:5901

If you are having problem accessing it, replace “raspberrypi.local” with the pi ip address. 5901 refers to the port number being used and it typically start from 5900.

For example if you start a session by vncserver :2, then the port number to use would be 5902.

The next step is very important because you would want the tightvncserver to launch right after booting up your Pi. Otherwise the whole point of setting up the vnc server is pointless.

Now you would have to go over to /etc and edit the the “rc.local” file. This is the file that is executed during booting up.

Simply adding in the below code before the “exit 0”

# Start tightvncserver

su - pi -c /'usr/bin/tightvncserver :1'

This command switches user to be the ‘pi’ user with su – pi. The su stands for ‘switch user’ the dash (-) makes sure that the user pi’s environment (like all their settings) are used correctly and pi is the user.

The -c option declares that the next piece of the line is going to be the command that will be run and the part inside the quote marks (‘/usr/bin/tightvncserver :1’) is the command.

The command in this case executes the file tightvncserver which is in the /usr/bin directory and it specifies that we should start desktop session 1 (:1).

After this, you should see that the tightvncserver is automatically running after a reboot or start up.


Reference used:

raspberry stackexchange-auto starting vnc
raspberry stackexchange-port

This entry was posted in Raspberry Pi and tagged , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s