How to Install NVIDIA CUDA and AMD ROCm on Ubuntu 26.04 and 24.04 for Local AI

Share

For local AI on Ubuntu 26.04 or 24.04 LTS, set up a compatible GPU driver and test your app before installing the NVIDIA CUDA or AMD ROCm development toolkit. If your app already uses the GPU, you can stop there. Install the toolkit for your GPU if your project needs to compile CUDA or HIP code.

Before you begin

Do You Need the Driver Only, or the Full Toolkit?

  1. Run a prebuilt app. Ollama, supported Ubuntu Inference Snap engines, and GPU-enabled PyTorch wheels can supply their own runtime. Canonical’s CUDA 12.9 Inference Snap engine needs NVIDIA driver 575 or newer. Other runtimes have their own minimum. On AMD, use a supported GPU and kernel and give the app access to the GPU devices. If you installed Ollama manually on AMD, install its ROCm bundle as well.
  2. Build GPU code. Use the CUDA Toolkit for nvcc or the ROCm development stack for HIP. You need these when compiling the CUDA or HIP backend of llama.cpp, writing GPU kernels, or building Python or C++ extensions that compile GPU code. A CPU-only build can skip them.
  3. Plan for the reboot. If the NVIDIA installation prompts for a Secure Boot Machine Owner Key (MOK) password, keep it handy. Choose Enroll MOK at reboot and enter the password. A missed enrollment can leave the NVIDIA module unloaded and the desktop using fallback graphics.

NVIDIA driver and CUDA Toolkit

Step 1. Identify the GPU and install the NVIDIA driver

Check the GPU, Ubuntu release and package architecture before choosing an install path. On a minimal system, install pciutils if lspci is missing.

Ubuntu terminal
lspci | grep -Ei 'vga|3d|display'
. /etc/os-release
printf '%s (%s)\n' "$VERSION_ID" "$VERSION_CODENAME"
dpkg --print-architecture

If ubuntu-drivers is missing, install ubuntu-drivers-common. On both LTS releases, the Ubuntu tool can select the recommended package for your GPU. Check the available branches first.

Ubuntu terminal
sudo apt update
sudo ubuntu-drivers list
sudo ubuntu-drivers install --recommended

If your version of the tool rejects --recommended, use sudo ubuntu-drivers install. The Ubuntu 26.04 release notes also show sudo ubuntu-drivers install nvidia:595. Choose 595 explicitly only if the tool offers that branch for your hardware. On 26.04 Desktop, the Software & Updates app is optional. To restore it, install software-properties-gtk.

Reboot, complete MOK enrollment if prompted, then run nvidia-smi. Expect a table with your GPU name and driver version. If your AI app uses the GPU, skip to the smoke test.

Step 2. Install CUDA Toolkit from one source

Ubuntu 26.04 archive (CUDA 13.1)

Use this path when your project works with CUDA 13.1. On minimal Ubuntu 26.04 Server, if APT cannot locate the toolkit after an update, enable Multiverse. Install software-properties-common first if add-apt-repository is missing.

Ubuntu terminal
sudo add-apt-repository multiverse
sudo apt update

Confirm that the candidate comes from Ubuntu’s resolute archive before installing. The compiler check uses Ubuntu’s versioned path, so it works even if your shell cannot find nvcc. cuda-toolkit supplies CUDA 13.1 on 26.04. The separate nvidia-cuda-toolkit package supplies CUDA 12.4 on 26.04 and CUDA 12.0 on 24.04.

Ubuntu terminal
apt-cache policy cuda-toolkit nvidia-cuda-toolkit
sudo apt install cuda-toolkit
/usr/local/cuda-13.1/bin/nvcc --version

NVIDIA network repository (CUDA 13.5)

Use this path on Ubuntu 24.04 or when your project needs a newer CUDA release on 26.04. Use one source for CUDA Toolkit packages. If you already installed an Ubuntu archive toolkit, review the removal section before switching. NVIDIA pairs CUDA 13.5 with R620 for new features and newly supported platforms. Some existing CUDA 13.x applications work on R580 or newer through minor-version compatibility. Check the project’s GPU and driver requirements before installing. CUDA 13 removed offline compilation for Maxwell, Pascal and Volta. Those cards may need a CUDA 12.x build environment.

The block selects ubuntu2404 or ubuntu2604 from your OS and maps amd64 to x86_64 or arm64 to sbsa. The ARM path is for supported SBSA systems. Jetson uses its own software stack.

Ubuntu terminal
sudo apt install wget
(
  . /etc/os-release
  case "$ID:$VERSION_ID" in
    ubuntu:24.04) repo=ubuntu2404 ;;
    ubuntu:26.04) repo=ubuntu2604 ;;
    *) echo "Use Ubuntu 24.04 or 26.04." >&2; exit 1 ;;
  esac
  case "$(dpkg --print-architecture)" in
    amd64) arch=x86_64 ;;
    arm64) arch=sbsa ;;
    *) echo "Unsupported APT architecture." >&2; exit 1 ;;
  esac
  workdir=$(mktemp -d) || exit 1
  trap 'rm -rf -- "$workdir"' EXIT
  cd "$workdir" || exit 1
  wget "https://developer.download.nvidia.com/compute/cuda/repos/$repo/$arch/cuda-keyring_1.1-1_all.deb" &&
    sudo apt install ./cuda-keyring_1.1-1_all.deb
)

Update APT and confirm that NVIDIA provides the versioned toolkit. Review the proposed package changes. The toolkit is installed separately from the display driver. The keyring package also adds an APT pin for NVIDIA’s repository. Check the source of any proposed driver change before approving an upgrade. If your workload requires R620, follow NVIDIA’s Ubuntu driver instructions for your GPU.

Ubuntu terminal
sudo apt update
apt-cache policy cuda-toolkit-13-5
sudo apt install cuda-toolkit-13-5

Check the toolkit symlink. If it points to 13.5, use /usr/local/cuda/bin in your shell. If you keep several versions, target /usr/local/cuda-13.5/bin directly. Add the export to ~/.bashrc when you want it in future Bash sessions.

Ubuntu terminal
readlink -f /usr/local/cuda
export PATH="/usr/local/cuda/bin:$PATH"
nvcc --version

nvcc --version reports the installed compiler. The CUDA version in nvidia-smi describes driver capability. It can appear even on a system with no toolkit installed.

AMD GPU permissions and ROCm

Step 1. Check the kernel driver and permissions

Ubuntu 26.04 and 24.04 include the amdgpu kernel driver. Check the driver attached to your GPU and look for /dev/kfd and a render node.

Ubuntu terminal
lspci -nnk | grep -Ei -A 3 'vga|3d|display'
ls -l /dev/kfd /dev/dri/renderD*
id -nG

Look for Kernel driver in use: amdgpu. If the devices exist but your account lacks the groups that own them, add the usual Ubuntu groups and log out and back in. Run id -nG again. If the app runs as a service, check the service account too. Changing your own groups only affects your own sessions.

Ubuntu terminal
sudo usermod -aG render,video "$USER"

For AMD upstream packages, check the GPU, Ubuntu point release, kernel and driver together in the compatibility matrix below. Where AMD requires a vendor driver for your hardware, follow its driver instructions for noble or resolute. The vendor driver installer lives at repo.radeon.com. Supported Ryzen APUs can use the in-kernel driver when the matrix lists it.

Step 2. Install ROCm from one source

Ubuntu 26.04 archive (ROCm 7.1)

Use this path for Ubuntu’s integrated stack on supported hardware. On a minimal server, if APT cannot locate rocm after an update, enable Universe. Install software-properties-common if the repository command is missing.

Ubuntu terminal
sudo add-apt-repository universe
sudo apt update

Check that the candidate is from Ubuntu’s resolute archive. Install rocm for the full stack. If you only need development tools and headers, choose rocm-dev. Install the diagnostic packages separately if your chosen package leaves them out.

Ubuntu terminal
apt-cache policy rocm rocm-dev
sudo apt install rocm
rocminfo

Look for a GPU agent with a gfx name in rocminfo. The command can list a CPU agent even when the GPU is unavailable. Use Ubuntu’s rocm-smi package to check the card when its driver supports those management queries.

AMD upstream repository (ROCm 10.2)

AMD’s 10.2 APT repository supports amd64 on Ubuntu 24.04 and 26.04. It uses the ubuntu2404 or ubuntu2604 path and the stable suite. If a project explicitly pins ROCm 7.x, follow the documentation for that release and its supported kernel and GPU. Install the ROCm stack from one source at a time. If you already have an AMD repository for another ROCm release, review its source file and remove the old stack before switching.

Ubuntu terminal
sudo apt install ca-certificates wget gpg
(
  . /etc/os-release
  case "$ID:$VERSION_ID:$(dpkg --print-architecture)" in
    ubuntu:24.04:amd64) repo=ubuntu2404 ;;
    ubuntu:26.04:amd64) repo=ubuntu2604 ;;
    *) echo "Use a supported amd64 Ubuntu release." >&2; exit 1 ;;
  esac
  sudo install -d -m 0755 /etc/apt/keyrings || exit 1
  workdir=$(mktemp -d) || exit 1
  trap 'rm -rf -- "$workdir"' EXIT
  wget -O "$workdir/amdrocm.asc" https://stable.repo.amd.com/rocm/gpg/packages.gpg &&
    gpg --batch --dearmor -o "$workdir/amdrocm.gpg" "$workdir/amdrocm.asc" &&
    sudo install -m 0644 "$workdir/amdrocm.gpg" /etc/apt/keyrings/amdrocm.gpg || exit 1
  sudo tee /etc/apt/sources.list.d/amdrocm-stable.sources >/dev/null <<EOF
Types: deb
URIs: https://stable.repo.amd.com/rocm/core/packages/$repo/
Suites: stable
Components: main
Architectures: amd64
Signed-By: /etc/apt/keyrings/amdrocm.gpg
EOF
)

Choose the package for your GPU’s GFX target from AMD’s installation table. For example, a supported Radeon RX 7900 XTX uses gfx1100. The general amdrocm10.2 package pulls in multiple GPU targets and uses considerably more disk space. For compilation, choose amdrocm-core-dev10.2 or the equivalent target-specific development package. The development package includes the runtime dependencies.

Ubuntu terminal
sudo apt update
apt-cache policy amdrocm10.2-gfx1100 amdrocm-core-dev10.2-gfx1100
sudo apt install amdrocm10.2-gfx1100

AMD’s 10.2 packages install under /opt/rocm/core-10.2. Add its bin directory to the front of PATH so the shell picks this version over any Ubuntu tools in /usr/bin. Run these commands as your regular user. If you installed the development package, also run hipcc --version or amdclang++ --version. Use command -v hipcc to check which compiler your shell finds.

Ubuntu terminal
export PATH="/opt/rocm/core-10.2/bin:$PATH"
command -v rocminfo amd-smi
rocminfo
amd-smi list

Look for the expected GPU agent in rocminfo and the matching card in amd-smi list. To keep the same tool precedence in future Bash sessions, add the export to ~/.bashrc.

Run a local AI GPU smoke test

Step 3. Run one test for your GPU

If you already have an Ollama model running, run ollama ps in another terminal and check the PROCESSOR column. A GPU percentage confirms offload. A CPU/GPU split means Ollama placed part of the model on the GPU.

For PyTorch, use uv to run a small GPU calculation in a temporary Python environment. The first wheel download can be large. These examples use x86-64 Linux and Python 3.12. Choose the PyTorch wheel that supports your GPU and kernel or driver. For AMD, the explicit ROCm wheel index selects the HIP build instead of the CUDA wheel normally offered on PyPI for Linux x86-64. The ROCm 7.2 wheel tests its bundled runtime. It does not validate the system ROCm 10.2 SDK.

NVIDIA (CUDA 12.8 wheel):

Ubuntu terminal
uv run --no-project --isolated --python 3.12 --index-url https://download.pytorch.org/whl/cu128 --with torch python -c 'import torch; print("CUDA:", torch.version.cuda); assert torch.version.cuda and torch.cuda.is_available(), "CUDA GPU unavailable"; print(torch.cuda.get_device_name(0), (torch.ones(4, device="cuda") * 2).sum().item())'

AMD (ROCm 7.2 wheel):

Ubuntu terminal
uv run --no-project --isolated --python 3.12 --index-url https://download.pytorch.org/whl/rocm7.2 --with torch python -c 'import torch; print("HIP:", torch.version.hip); assert torch.version.hip and torch.cuda.is_available(), "ROCm GPU unavailable"; print(torch.cuda.get_device_name(0), (torch.ones(4, device="cuda") * 2).sum().item())'

Expect the backend version, the GPU name and 8.0. PyTorch exposes HIP through the torch.cuda API, including the "cuda" device name. If the wheel supports a different GPU family or reports no GPU, check its compatibility table or test a supported Ollama model before changing your system packages.

Fix common GPU setup problems

NVIDIA module missing or NVML version mismatch

If the desktop fell back to basic graphics after a DKMS install, check Secure Boot and complete any pending MOK enrollment. If nvidia-smi reports Driver/library version mismatch, reboot first so the running kernel can load the updated module. If it persists, check that the current kernel has the correct NVIDIA module and that the driver libraries are from the same branch.

Ubuntu terminal
mokutil --sb-state
uname -r
lsmod | grep '^nvidia'
modinfo -F version nvidia

AMD GPU missing from rocminfo

Check /dev/kfd, the render node and permissions from the same account that runs the workload. If the nodes are missing, confirm your GPU and kernel support before changing permissions. For a discrete card and a relevant platform or firmware issue, check the board’s settings for Above 4G Decoding and Resizable BAR. For some older unsupported Radeon targets, Ollama documents an app-scoped HSA_OVERRIDE_GFX_VERSION experiment. Use it only when an app documents the workaround for your hardware family. A GFX override cannot add missing support to the driver or the wheel.

APT sees the wrong toolkit

Check candidates and their origins with apt-cache policy. Disable the stale third-party entry, refresh APT, and simulate the next install or removal before approving it. Avoid combining Ubuntu and vendor builds of the same CUDA or ROCm toolkit. If your setup depends on a particular driver, make sure that package is still present in the proposed result.

Remove CUDA or ROCm safely

Remove the toolkit package you installed and keep the display driver. For example, choose one installed package name corresponding to your path: cuda-toolkit, cuda-toolkit-13-5, rocm, rocm-dev, or the exact amdrocm10.2 or amdrocm-core-dev10.2 variant package. Check the planned removal of dependencies separately and stop if APT proposes to remove a working driver or something another project uses.

Ubuntu terminal
apt-mark showmanual | grep -E '^(cuda-|nvidia-cuda-toolkit|rocm|amdrocm)'

Run only the simulation that matches your installation. The NVIDIA example uses CUDA 13.5 and the AMD example uses the ROCm 10.2 runtime for gfx1100. Substitute your exact installed package for another route.

Ubuntu terminal
apt -s remove cuda-toolkit-13-5
apt -s remove amdrocm10.2-gfx1100

If the preview looks right, repeat the matching command with sudo apt remove in place of apt -s remove. Then preview unused dependencies with apt -s autoremove before running sudo apt autoremove. For the Ubuntu archive paths, leave Universe and Multiverse enabled if other software uses them. For NVIDIA’s upstream path, remove cuda-keyring and any CUDA pin you added only if you no longer need that repository for the toolkit or the driver. For AMD’s upstream path, remove /etc/apt/sources.list.d/amdrocm-stable.sources and its dedicated key only if you added them for this setup and no other entry uses the key. Run sudo apt update after repository changes. Remove any toolkit-specific PATH line you added to your shell profile.

Frequently asked questions

Does nvidia-smi mean the CUDA Toolkit is installed?

No. It checks your NVIDIA driver and reports its CUDA capability. Run nvcc –version to see whether the CUDA compiler is installed and which version your shell finds.

Do I need ROCm to run a prebuilt AI app on AMD?

You need a supported GPU, kernel driver and device access. A compatible app can bundle its own ROCm runtime, so you may be able to run it without the system ROCm SDK.

Why does the AMD PyTorch test use cuda as the device name?

PyTorch exposes its HIP backend through the torch.cuda API. A populated torch.version.hip value and a successful GPU calculation confirm that the ROCm wheel is using your GPU.

Helpful Resources

r/ROCm ↗Community troubleshooting and setup discussions.
Ubuntu NVIDIA drivers ↗Ubuntu driver selection and Secure Boot.
NVIDIA CUDA installation ↗Toolkit repositories and platform support.
AMD ROCm compatibility ↗Supported GPUs, kernels and drivers.