Step 3: Installing CUDA drivers on the GPU instance

First, update/install the NVIDIA graphics drivers:

$ sudo add-apt-repository ppa:graphics-drivers/ppa -y
$ sudo apt-get update
$ sudo apt-get install -y nvidia-xxx nvidia-settings

Here, xxx can be replaced with the graphics hardware version installed on your instance, which can be found in the instance details.

Next, download the CUDA deb file (this code is for the latest version at the time of writing, from Jan, 2019):

$ wget https://developer.download.nvidia.com/compute/cuda/10.0/secure/Prod/local_installers/cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb

Then, proceed with the following commands:

$ sudo dpkg -i cuda-repo-ubuntu1804-10-0-local-10.0.130-410.48_1.0-1_amd64.deb
$ sudo apt-key add /var/cuda-repo-<version>/7fa2af80.pub
$ sudo apt-get update
$ sudo apt-get install -y cuda nvidia-cuda-toolkit

To verify whether everything was installed successfully, run the following commands:

$ nvidia-smi
$ nvcc -version

If both the commands produce output without any warnings or errors, then the installation is successful.