Install Cuda on WSL Ubuntu

I've been preparing my workstation for AI development and plan to build everything inside Windows Subsystem for Linux (WSL) using Ubuntu.

This is a quick guide on installing the CUDA toolkit on Ubuntu WSL. It assumes you already have your Ubuntu WSL instance up and running.

Verifying GPU Detection in WSL

First, let's verify that the NVIDIA drivers are working and actively detecting your graphics card inside WSL.

Run the NVIDIA System Management Interface tool:

nvidia-smi

It should print an output like this in Windows Terminal:

Fri Jul 10 13:21:05 2026
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 610.43.02              KMD Version: 610.62        CUDA UMD Version: 13.3     |
+-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA GeForce RTX 3090        On  |   00000000:21:00.0  On |                  N/A |
| 36%   37C    P8             40W /  420W |    8835MiB /  24576MiB |      4%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

+-----------------------------------------------------------------------------------------+
| Processes:                                                                              |
|  GPU   GI   CI              PID   Type   Process name                        GPU Memory |
|        ID   ID                                                               Usage      |
|=========================================================================================|
|    0   N/A  N/A              27      G   /Xwayland                             N/A      |
+-----------------------------------------------------------------------------------------+

As you can see, WSL is successfully detecting the RTX 3090.

Installing the CUDA Toolkit

To install CUDA, we need to add NVIDIA's official software repository to the Ubuntu package manager.

First, download the NVIDIA CUDA keyring. This securely authenticates the NVIDIA repository on your system so Ubuntu trusts the packages:

wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-keyring_1.1-1_all.deb

Next, install the downloaded keyring file using the Debian package manager:

sudo dpkg -i cuda-keyring_1.1-1_all.deb

Now update your local package list so your system recognizes the newly added repository:

sudo apt-get update

With the repository added and updated, download and install the CUDA toolkit:

sudo apt-get -y install cuda

Once the installation finishes, you need to add CUDA to your system PATH so the terminal recognizes its commands. Run these lines to append the directories to your bash profile and reload it:

echo 'export PATH=/usr/local/cuda/bin:$PATH' >> ~/.bashrc
echo 'export LD_LIBRARY_PATH=/usr/local/cuda/lib64:$LD_LIBRARY_PATH' >> ~/.bashrc
source ~/.bashrc

Verify the installation by checking the NVIDIA CUDA Compiler (nvcc) version:

nvcc --version

The output should confirm the installed version:

nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2026 NVIDIA Corporation
Built on Tue_Jun_09_02:43:40_PM_PDT_2026
Cuda compilation tools, release 13.3, V13.3.73
Build cuda_13.3.r13.3/compiler.38244171_0

The output confirms that CUDA version 13.3 is successfully installed.

Compiling and Running a CUDA Test File

Let's write a simple test program to ensure the compiler and GPU are communicating properly.

Create a new, empty file named test_cuda.cu:

touch test_cuda.cu

Open the file using the Nano text editor:

nano test_cuda.cu

Paste the following C++ code into the editor. This script defines a simple CUDA kernel (hello_cuda) that runs on the GPU and prints a message from five different execution threads. The main function runs on your CPU, prints the CUDA compiler version, and then launches the GPU threads:

#include <stdio.h>

__global__ void hello_cuda() 

{
    printf("Hello from CUDA thread %d!\n", threadIdx.x);
}

int main() 
{
    printf("CUDA major: %d\n", __CUDACC_VER_MAJOR__);
    printf("CUDA minor: %d\n", __CUDACC_VER_MINOR__);
    printf("CUDA build: %d\n", __CUDACC_VER_BUILD__);

    hello_cuda<<<1, 5>>>();
    cudaDeviceSynchronize();
    return 0;
}

Save and exit the editor (in Nano, press Ctrl+X, type Y, and hit Enter).

Now, compile the file using the NVIDIA CUDA compiler:

nvcc -o test_cuda test_cuda.cu

Finally, execute the compiled program:

./test_cuda

The output should look similar to this, showing messages from all five GPU threads:

CUDA major: 13
CUDA minor: 3
CUDA build: 73
Hello from CUDA thread 0!
Hello from CUDA thread 1!
Hello from CUDA thread 2!
Hello from CUDA thread 3!
Hello from CUDA thread 4!

CUDA is now installed and fully functional inside your WSL instance. If you have any questions, run into issues, or have tips to share, leave a comment below!

I'm Feeling Lucky
Darryl Dias

Written by Darryl Dias

The AI guy and founder of Caprycon, building AI-powered tools, exploring emerging technologies, and sharing insights from the world of artificial intelligence