How to Install Cuda Driver for Nvidia on Ubuntu


If you have just upgraded Ubuntu on your AWS g4dn instance and need to install/reinstall Cuda drivers for your Nvidia chipset, then you can run the following:

Install Cuda drivers for Nvidia on Ubuntu

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/cuda-ubuntu1804.pin
sudo mv cuda-ubuntu1804.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo apt-key adv --fetch-keys https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/7fa2af80.pub
sudo add-apt-repository "deb https://developer.download.nvidia.com/compute/cuda/repos/ubuntu1804/x86_64/ /"
sudo apt-get update
sudo apt-get -y install cuda

How to get the versions for your own setup

Or follow the wizard here to generate the correct version numbers for your specific environment/platform:

CUDA Toolkit 11.5 Update 1 Downloads | NVIDIA Developer

How to check the installation was successful

You can check that the installation was successful by running the Nvidia SMI tool:

nvidia-smi