CUDA Installation Tips for Ubuntu

As a rule of thumb, if all you need is an nvcc of a specific version, do not install CUDA in a system-wide way from the official NVIDIA website unless strictly necessary. It is generally tied to a specific version of the CUDA driver, which is not always compatible with your system. Worse still, it may break the drivers silently: the system works normally until it is rebooted and the X server fails to start. This post includes some ways to install CUDA in a conda environment and installing the driver if it breaks.

Installing CUDA in a Conda Environment

For CUDA version older than 12.0, use the cudatoolkit-dev package:

conda install cudatoolkit-dev=11.3 -c conda-forge

For CUDA version 12.0 or newer, use the cuda-nvcc package:

conda install cuda-nvcc cuda -c "nvidia/label/cuda-12.0.0"

Don't write cuda-nvcc=12.0. It usually comes with other CUDA-related packages with incompatible versions.

Installing the Driver on Ubuntu

It's generally easier (and safer) to install the driver from Ubuntu source. If the driver is already not working, switch to a text TTY (which does not require graphics driver) by Ctrl+Alt+F2.

Check what versions are available by

ubuntu-drivers devices

Then, install the version you want by

# replace 525 with the version you want
sudo ubuntu-drivers install nvidia:525