Thursday, July 29, 2010

How to install TightVNC Server on Ubuntu

The TightVNC server provided by the universe repository of Ubuntu doesn't work well in a xdmcp/gnome environment.

The server frequently crashes (segfaults), keyboard mappings are broken and X forwarding doesn't work out of the box. To let the server crash on Ubuntu 10.04 you had to open a few applications and eventually it would crash when opening or closing an application. Using Ubuntu 9.10 it would always crash when having two apps open like firefox and open office.

If you aren't tied to TightVNC, I would suggest using the vnc4server package that doesn't seem to suffer the same issues. I did find it slightly slower and I couldn't run a 8 bit environment effectively. It lost too much information in 8 bit to be usable. When using vnc4server I would suggest a minimum colour depth of 15 bit.

Compile and install the new version of TightVNC from source
The stability is fixed in TightVNC server 1.3.10. The version 1.3.9 currently included in Ubuntu doesn't work.

Unzip the archive and review the README file on how to compile the source. I had to install the following dependencies to build the source:
  • xorg-dev
  • libjpeg62-dev
  • zlib1g-dev
  • xmkmf
It is important to note that you do need to build the viewer and other libraries before going into the XVnc folder and building it.

After the build was successful, use the vncinstall script to copy the required binaries. I installed to /usr/local/bin and had to create the /usr/local/man/man1 directory for the man pages to be copied successfully.

Update alternatives
Since you installed the binaries manually you have to set up the alternatives for XVnc to point to your new libraries.

I always forget the syntax, so here it is for a quick reference:
update-alternatives --install /usr/bin/Xvnc Xvnc /usr/local/bin/Xvnc 80
where /usr/local/bin/Xvnc is your newly built tightvnc viewer.

Make sure your new installation is selected by executing "update-alternatives --config Xvnc"

Configure xdmcp in gdm.
/etc/gdm/custom.conf was missing from my installation and xdmcp wasn't enabled.

Create a /etc/gdm/custom.conf file and add the following content:





Setup TightVNC
While setting up VNC it is important to note that your newly built TightVNC server tries to fetch X fonts from a different location to what Ubuntu uses. When you configure the service you have to append the following to the Xvnc command:
-fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/

A service entry will then look something like this:
service vnc-1024x768x8-tightvnc
protocol = tcp
socket_type = stream
wait = no
user = nobody
server = /usr/bin/Xvnc
server_args = -inetd -query localhost -once -geometry 1024x768 -depth 8 -fp /usr/share/fonts/X11/misc/,/usr/share/fonts/X11/Type1/,/usr/share/fonts/X11/75dpi/,/usr/share/fonts/X11/100dpi/

Follow the instructions on:, skipping the sections on how to install TightVNC and remember to add the font path (-fp) section from above to the server_args.

Test the server
At this point the server should be up and running and you should be able to connect to the server. If you can't, verify that the font path is correct in your service setup. If TightVNC can't find the font, the server closes the connection without a warning or message. Also check your firewall to see if it is blocking the connection.

At this point X forwarding won't work and your keyboard mappings may be stuffed in gnome.

Keyboard mapping fix
This issue only appears to be affecting gnome. I couldn't find a fix, but there is a workaround where you tell gnome to not do any keyboard mappings.

Add the following line to /etc/gdm/Xsession:
and restart the gdm service. The gdm service now uses upstart, so type "restart gdm" to restart it. That line is executed every time a X session starts for a user logging in using gdm.

Enabling X forwarding

Add the following line to /etc/gdm/Xsession:
xhost +localhost
That allows anybody logged into the machine access the the local X server. Have a look at for more details.

Your server should be up and running with no crashing, no keyboard issues and with X forwarding enabled.

I hope you found this post useful and saved some time trying to get TightVNC to work properly.

Until later,