How to Install CUDA 11.x on Ubuntu 20.04/22.04

With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs. This article walks you through how to install Nvidia CUDA 11.x on Ubuntu.


CUDA (Compute Unified Device Architecture) is a parallel computing platform and application programming interface (API) model created by NVIDIA. With CUDA, developers are able to dramatically speed up computing applications by harnessing the power of GPUs.

In this article, we will guide you through the process of installing and verifying CUDA 11.x on Ubuntu 20.04.


To use CUDA on your system, you will need the following:
• A CUDA-capable GPU, no NVIDIA driver required
• Ubuntu 20.04 or Ubuntu 22.04 Linux OS

Note: The demonstration in this article will use the Dedicated A4000 GPU Server provided by GPUMart, equipped with a NVIDIA RTX A4000 graphics card, installed with Ubuntu 20.04 Linux system, and GCC 9.4.0. Also, make sure you have root or sudo access to the system.

6 Steps to Install CUDA 11.x on Ubuntu 20.04/22.04

Step 1. Upgrade your Ubuntu (Optional)

We will start by upgrading our Ubuntu to ensure we have all the latest software. Use the following command to upgrade your system:

sudo apt update
sudo apt upgrade 

Step 2. Check the NVIDIA driver installation (Optional)

We can check our installation with the NVIDIA System Management Interface, which is called with the nvidia-smi command.

check nvidia driver version

At the top of the table, we will see the driver version and CUDA driver API compatibility:

NVIDIA-SMI 525.78.01    Driver Version: 525.78.01    CUDA Version: 12.0

Note: CUDA has 2 primary APIs, the runtime and the driver API. Both have a corresponding version. In any event, the (installed) driver API version may not always match the (installed) runtime API version, especially if you install a GPU driver independently from installing CUDA (i.e. the CUDA toolkit).

Step 3. Find CUDA Tooklit Version You'll Install

Please visit the Archive of Previous CUDA Releases to find the version of the CUDA toolkit you want to install. Please select the version you want from the list below, and be sure to check for the latest production drivers for your hardware configuration.

cuda toolkit archive

Here we choose cuda 11.8 as an example to continue our installation demonstration.

Step 4. Download AND Install CUDA Toolkit 11.8

We will now head to the NVIDIA CUDA Toolkit 11.8 downloads page to get the proper CUDA toolkit for Ubuntu 20.04. The website will navigate you through the right package to download as well as the commands to execute to complete the CUDA toolkit installation.

cuda toolkit 11.8 downloads

Referring to the Installation Instructions on the page, we first use wget to download the runfile installation package, and then use the sudo sh command to perform the installation.

$ wget
$ sudo sh

After accepting the installation agreement, a selection screen will appear, please select what you want to install. If you do not need to install NVIDIA drivers, please leave it unchecked.

cuda installer selection

Step 5. Update Environment Variables

After the installation is complete, update the PATH and LD_LIBRARY_PATH environment variables by adding the following lines to your ~/.bashrc file:

$ export PATH=/usr/local/cuda-11.8/bin${PATH:+:${PATH}}
$ export LD_LIBRARY_PATH=/usr/local/cuda-11.8/lib64${LD_LIBRARY_PATH:+:${LD_LIBRARY_PATH}}

Replace “11.8” with the version number of CUDA you installed. The export command sets the environment variable. The PATH variable helps the system locate executables, and the LD_LIBRARY_PATH variable helps the system locate libraries. Save the changes to ~/.bashrc and reload the file by running the following command:

$ source ~/.bashrc

Step 6. Verify the Installation

To verify the CUDA installation, open a terminal and run the following command:

$ nvcc --version
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2022 NVIDIA Corporation
Built on Wed_Sep_21_10:33:58_PDT_2022
Cuda compilation tools, release 11.8, V11.8.89
Build cuda_11.8.r11.8/compiler.31833905_0

The nvcc command invokes the NVIDIA CUDA Compiler. The --version flag displays the version information for the CUDA compiler.

Additional Information

Usually, the version of the driver API is backward compatible with the version of the runtime API. That is, the version displayed by nvidia-smi is greater than the version of nvcc --version. Usually there will be no major problems.

CUDA Toolkit Installer usually integrates GPU driver Installer. If your CUDA and Driver are both installed through CUDA Toolkit Installer, then the versions of runtime api and driver api should be consistent, that is, nvcc --version and nvidia-smi The version shown should be the same. In the fourth step above, if you did not select the driver item (520.61.05) but later want to install it, you can execute the following command:

$ sudo sh --silent --driver

After the installation is complete, let us execute the NVIDIA-smi command again. You will find that the versions displayed by nvcc --version and nvidia-smi are the same.

nvidia-smi output for nvidia rtx a4000

CUDA 11.0 was released with an earlier driver version, but by upgrading to Tesla Recommended Drivers 450.80.02 (Linux) / 452.39 (Windows), minor version compatibility is possible across the CUDA 11.x family of toolkits. For more information, please visit: CUDA Toolkit and Minimum Required Driver Version for CUDA Minor Version Compatibility

The current GPU Driver version packaged in the CUDA11.8 toolkit is 520.61.05 (Linux), so the driver version seen in the picture above is this. For the NVIDIA GPU driver versions packaged in each CUDA toolkit version, please refer to the official link: CUDA Toolkit and Corresponding Driver Versions.