One tweet from https://twitter.com/finbarrtimbers says:
I enjoyed the CUDA driver installation for 2 days plus another day to reinstall the whole system around 2 years ago.
Now in 2023, with the correct steps, you can only enjoy CUDA drivers installation for just 5 mins in Ubuntu, here are the steps:
Step 1. If you have Nvidia’s driver already installed, you’d better uninstall all Nvidia drivers first to ensure minimum errors.
sudo apt-get purge 'nvidia*'
sudo apt-get autoremove
Then reboot your system:
You may want to disable the UEFI secure boot from the BIOS, if not doing it, you will be asked to input a password and then enroll the key, it will work, but require additional steps and may lead to driver installation failure.
Step 2. Install GCC if you don’t have one
sudo apt install gcc
Step 3. Install NVIDIA GPU driver
sudo apt update
sudo apt upgrade
sudo apt install build-essential dkms
sudo add-apt-repository ppa:graphics-drivers/ppa
sudo apt update
# list all avaliable drivers
sudo ubuntu-drivers devices
# auto install
sudo ubuntu-drivers autoinstall
# or with a version
# sudo apt install nvidia-driver-525
Note that driver above 535 could lead to fail suspend, in other words, can’t go sleep, if you are using Ubuntu as your work desktop.
Step 4. Select the right CUDA version for your system on this CUDA download page:https://developer.nvidia.com/cuda-downloads
and you will get the bash commands that do everything of installation:
Here is a version of my choice:
sudo mv cuda-ubuntu2204.pin /etc/apt/preferences.d/cuda-repository-pin-600
sudo dpkg -i cuda-repo-ubuntu2204-12-1-local_12.1.1-530.30.02-1_amd64.deb
sudo cp /var/cuda-repo-ubuntu2204-12-1-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda
After this, you should be able to see the CUDA version by
If the nvcc is not found, just add this into your terminal rc file (~/.bashrc or ~/.zshrc)
Step 5. Reboot and stop enjoying CUDA Driver installation.