First, a disclaimer: Ubuntu is not my favorite distribution. I prefer rolling releases to versioned distros with scheduled upgrades, and Ubuntu is a typical example of the latter. That said, it is the default in my lab, so computers come with it preinstalled, and I would rather not redo the partitioning and LDAP setup myself. A few things I run into regularly:

  • Some CLI programs are not available in the default apt repositories and must be installed with snap, as AppImages, or with their own installers (the latter is fine, I just need to add them to my update script).
  • Packages available through apt can be months or years behind the latest release, which matters when other programs depend on them or when I need a specific feature.

But the part that has cost me the most time is graphics card management, at least when you need the GPU to train or use neural networks. On Arch Linux, it is very simple:

sudo pacman -Syu cuda

You get an up-to-date CUDA and the NVIDIA driver in a single meta-package, available in the default extra repository. For old or incompatible graphics cards, the wiki tells you which version to use, and you can install it with your AUR helper.

On Ubuntu, the default repositories do not provide suitable packages, so you need to use NVIDIA’s own. The documentation is very complete, but since it covers many architectures and distributions, it can be hard to find the right path. The most direct route is the download page. Once I enter my computer information and select deb (network), I get these commands:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt-get update
sudo apt-get -y install cuda-toolkit-13-5

There are three things I want from an installation:

  • Install the required repositories through a package, to stay up to date and keep installation easy. That is why I selected the network option: the package manager keeps track of how the repositories were added.
  • Install the toolkit at the latest version. If needed, because the graphics card is too old or the AI framework (e.g. PyTorch) is not compatible, I want to be able to downgrade the version myself.
  • Install the compatible driver, because the toolkit is not the only thing needed.

These commands are a good starting point, but they did not fully meet those goals on my machine:

  • They use apt-get, which works, but apt is the usual choice for interactive use.
  • With the default dpkg options, the NVIDIA repository was not enabled on my computer, so the packages did not show up, even after apt update.
  • The CUDA version is already pinned, even though the page never asked for my GPU model, so compatibility is not guaranteed.
  • The driver has to be installed using another download page.

Since I spent many hours figuring this out, here is the complete, annotated script that works for me:

wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/cuda-keyring_1.1-1_all.deb # Just mind the Ubuntu version in the URL
sudo dpkg -i --force-confmiss cuda-keyring_1.1-1_all.deb # --force-confmiss restores the missing repository config file
sudo apt update                                          # Load the new repository, use apt
sudo apt install nvidia-driver-pinning-620               # Pin the driver version to avoid breaking the graphical session
sudo apt install nvidia-open                             # Install the actual CUDA-compatible GPU driver
sudo apt install cuda                                    # Install the unpinned, larger meta-package

This works for GPUs that are still supported. Older ones need more care, and I have not covered them here.

Other commands that can be useful:

  • This checks which repositories and keys are configured, in case you want to remove them for a clean installation.
ls /etc/apt/sources.list.d/ | grep cuda
grep -ril nvidia /etc/apt/sources.list /etc/apt/sources.list.d/ /etc/apt/trusted.gpg.d/ /usr/share/keyrings/ 2>/dev/null
  • To use your GPU in containers (e.g. Docker), you will need an additional package, with its own specific documentation.
sudo apt install nvidia-container-toolkit
sudo nvidia-ctk runtime configure --runtime=docker
sudo systemctl restart docker