Install NVIDIA drivers and CUDA on Ubuntu or Debian
Install the NVIDIA data center driver on a GPU server with ubuntu-drivers or NVIDIA's repository, add the CUDA toolkit, and confirm with nvidia-smi and nvcc.
- Intermediate
- 30 min read
- Updated
On this page
Your GPU server's NVIDIA GPU needs the NVIDIA driver before any software can use it. Most AI tools and containers need nothing else; the CUDA toolkit is for compiling CUDA code yourself. This guide installs both the way Canonical, Debian and NVIDIA document it.
Before you start
- A GPU VPS, GPU VDS or GPU dedicated server with a dedicated NVIDIA GPU. For a shared vGPU, see the note in GPU servers: getting started.
- Ubuntu 24.04 LTS or 26.04 LTS, or Debian 12 or 13, fully updated and rebooted:
sudo apt update && sudo apt full-upgrade
sudo reboot- Check that the GPU is visible:
lspci | grep -i nvidia. - Check Secure Boot:
mokutil --sb-state(installmokutilif needed).
Step 1: Install the driver
Ubuntu
Canonical's tool picks the right data center driver and installs pre-built, signed modules. List the candidates, then install one branch, for example the 535 branch Canonical uses in its documentation; pick a branch from your list:
sudo ubuntu-drivers list --gpgpu
sudo ubuntu-drivers install --gpgpu nvidia:535-serverRunning sudo ubuntu-drivers install --gpgpu without a name installs the recommended branch instead. Then install the utilities with nvidia-smi; their number must match the driver branch:
sudo apt install nvidia-utils-535-server
sudo rebootDebian 13
Enable the contrib, non-free and non-free-firmware components for trixie and trixie-security in your APT sources, then:
sudo apt update
sudo apt install linux-headers-amd64
sudo apt install nvidia-kernel-dkms nvidia-driver
sudo rebootDebian's wiki lists which GPU generations each driver series supports and the state of the open-module flavour (nvidia-open-kernel-dkms); check it for your GPU. For the newest GPU generations, use NVIDIA's repository instead (next tab).
NVIDIA repository
NVIDIA's own repository carries the newest drivers for Ubuntu and Debian. Use the distribution name ubuntu2404, ubuntu2604, debian12 or debian13:
sudo apt install linux-headers-$(uname -r)
wget https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
sudo dpkg -i cuda-keyring_1.1-1_all.deb
sudo apt update
sudo apt install nvidia-open
sudo rebootFor a headless compute server, NVIDIA also documents the smaller set sudo apt -V install libnvidia-compute nvidia-dkms-open. On Debian, enable the contrib component first.
Install the driver from one source only. Mixing Ubuntu's driver packages with NVIDIA's repository causes version conflicts.
Verify:
nvidia-smiThe table shows your GPU, the driver version and the highest CUDA version the driver supports.
Step 2: Install the CUDA toolkit (only to compile CUDA code)
The toolkit comes from NVIDIA's repository. If you have not added the keyring in Step 1, add it now (same wget and dpkg -i lines), then:
sudo apt update
sudo apt install cuda-toolkitThe toolkit does not install a driver. Add its compiler to your path; the folder name carries the version, so check it first:
ls -d /usr/local/cuda*
echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
source ~/.bashrcIf /usr/local/cuda does not exist, use the versioned folder that ls printed instead.
Verify: nvcc --version prints the CUDA compiler version.
Step 3: Keep the driver updated
- Ubuntu driver packages update with
sudo apt update && sudo apt upgrade. Reboot after a driver update. - With NVIDIA's repository, NVIDIA documents version-pinning packages (
nvidia-driver-pinning-…) if you need to stay on one branch.
Troubleshooting
Failed to initialize NVML: Driver/library version mismatch. The driver was updated but the old kernel module is still loaded. Reboot.
NVIDIA-SMI has failed because it couldn't communicate with the NVIDIA driver. The module did not load. On Secure Boot systems with DKMS drivers, enroll the MOK key or use Ubuntu's signed drivers; also check dkms status and dmesg | grep -i nvidia. More in GPU troubleshooting.
apt reports conflicts between NVIDIA packages. Drivers from two sources are mixed. List them with dpkg -l | grep -i nvidia, remove the packages of one source with sudo apt purge and their names, reboot, and keep one source.
nvcc: command not found. The toolkit is installed but not on your PATH; see Step 2.
Next steps
- GPU containers: GPUs in Docker containers.
- Serve a model: install vLLM or install Ollama.
Frequently asked questions
Do I need the CUDA toolkit to run AI applications?
Usually not. Most applications and container images bring their own CUDA libraries and need only the driver. Install the toolkit when you compile CUDA code yourself.
Which driver version should I install?
The one ubuntu-drivers recommends for compute, or the current branch from NVIDIA's repository. Check the requirements of your software: newer CUDA versions need newer drivers.
Does this apply to a shared vGPU?
No. A shared vGPU uses the vGPU guest driver that matches the host's vGPU software; our images ship with it. Do not install the driver from this guide over it. To reinstall it, use the version listed in your service details or provided by HyperDC support.
Does Secure Boot matter?
On systems with Secure Boot on, kernel modules must be signed. Ubuntu's ubuntu-drivers installs pre-built signed drivers; drivers built with DKMS need a machine owner key (MOK) enrolled.