Steps from https://stackoverflow.com/q/19856192 with minor changes to work on Ubuntu 16.04.
# Install the Nvidia driver
sudo apt-add-repository ppa:ubuntu-x-swat/updates
sudo apt-get update
sudo apt-get install nvidia-current
# Driver installation needs reboot
sudo reboot now
After rebooting, install and run X server:
# Install and configure X window with virtual screen
sudo apt-get install xserver-xorg libglu1-mesa-dev freeglut3-dev mesa-common-dev libxmu-dev libxi-dev
sudo nvidia-xconfig -a --use-display-device=None --virtual=1280x1024
Then update /etc/X11/xorg.conf
adding BusID "0:3:0"
in the Section "Device"
section:
Section "Device"
Identifier "Device0"
Driver "nvidia"
VendorName "NVIDIA Corporation"
BoardName "GRID K520"
BusID "0:3:0"
EndSection
And run the X server:
sudo /usr/bin/X :0 &
OpenGL programs are now workable:
DISPLAY=:0 glxinfo
DISPLAY=:0 glxgears