Skip to content

Instantly share code, notes, and snippets.

@xaliander
Last active April 18, 2024 03:34
Show Gist options
  • Save xaliander/2d7ffd6a662b0302fbe840c227cf7a4a to your computer and use it in GitHub Desktop.
Save xaliander/2d7ffd6a662b0302fbe840c227cf7a4a to your computer and use it in GitHub Desktop.
How to update your NVIDIA driver for CUDA on Ubuntu v20.04.2

Installing CUDA

Warning: Today's date is April 14th 2021, and therefore these instructions might no longer be applicable for you!

Too Long Didn't Read (TLDR): Getting the error message below after installing CUDA? Download the .run file and follow the non (optional) code snippets to update your NVIDIA driver.

I started off by installing Ubuntu and afterwards I PRECISELY followed these installation instructions from NVIDIA on how install CUDA. I recommend you do the same.

Warning: The <distro> and <version>... key's aren't always 100% consistent. In the 'Pin file to prioritize CUDA repository' section I had to find the correct file by typing a partial URL into the browser and manually searching for the correct file.

Resulting ERROR:

After the installation unfortunately, when going through the 'Verify the Installation' steps, the following message popped up.

CUDA driver version is insufficient for CUDA runtime version

So let's get that fixed by updating the NVIDIA driver.

Update NVIDIA Driver

First, head over to NVIDIA's download section and find your graphics card. Go ahead and download the driver. I have a GTX 3090, so I downloaded the 'NVIDIA-Linux-x86_64-460.73.01.run' containing the most recent driver (460.73.01).

Then, make the file executable and run it:

chmod +x NVIDIA-Linux-x86_64-460.73.01.run
(optional) sudo ./NVIDIA-Linux-x86_64-460.73.01.run

(optional) ERROR:

An NVIDIA kernel module 'nvidia-drm' appears to already be loaded in your kernel.

For me this results in an error message because Ubuntu already has detected my graphics card and has installed some driver to show off the shiny desktop.

SOLUTION: We can disable the graphical target, which is what keeps the display manager running. After providing your password you will see a full screen command prompt. Login - then, find your .run file.

systemctl isolate multi-user.target
cd ~/Downloads
(optional) sudo ./NVIDIA-Linux-x86_64-460.73.01.run

(optional) ERROR:

An NVIDIA kernel module 'nvidia-modeset' appears to already be loaded in your kernel.

As we haven't yet unloaded any kernel modules, this error message is to be expected.

SOLUTION: Let's try to unload the modules. I've tried various solutions, but here is what worked for me in the end.

sudo service nvidia-persistenced stop
sudo ./NVIDIA-Linux-x86_64-460.73.01.run

You should now see the NVIDIA Accelerated Graphics Driver installation screen. If you already had a driver installed this will be overwritten. I chose not to use DKMS as it was the only way to run the installer without any further errors. Also I ignored the CC version check as the NVIDIA website says cc 9.3.0 is required. I also chose the 32-bit option because why not. Automatically update the X configuration - yes please!

All done!

sudo reboot 0

(Optional) Verify everything is up and running:

nvidia-smi

Shows the corresponding Driver Version: 460.73.01. Run the example code that is provided with CUDA (Warning: Compiling takes a few minutes)

cd ~/Downloads
cuda-install-samples-11.2.sh test
cd test/NVIDIA_CUDA-11.2_Samples
make
cd bin/x86_64/linux/release/
./deviceQuery

You can try any of the other examples as well. The ./deviceQuery output now says 'Detected 1 CUDA Capable device(s)' - Sweet!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment