C.W.K.
Stream
Lesson 04 of 05 · published

Setting Up CUDA on WSL or Linux

~14 min · cuda, wsl, linux, ubuntu, setup

Level 0Beginner
0 XP0/38 lessons0/12 achievements
0/100 XP to next level100 XP to go0% complete

The Linux path: same NVCC, different package layer

Two flavors of Linux setup matter:

  • Native Linux (Ubuntu 22.04 / 24.04) — what cloud VMs and dedicated AI rigs run. Best performance, full Nsight access.
  • WSL 2 on Windows — a true Linux kernel inside Windows that can call your real GPU through NVIDIA's WSL driver. Same Linux toolkit, slightly worse profiling, but lets a Windows dev have a Unix shell + dev tools.

Both use the same Linux CUDA toolkit packages. WSL is special only in that the GPU driver is shared with Windows — you don't install a Linux driver inside WSL, you install the Windows driver outside, and CUDA Linux userland talks to it through a passthrough.

Why nvcc is missing on a fresh WSL install

The Windows-side CUDA installer drops files under Windows paths only. Inside WSL you have a separate filesystem; you must install the Linux-side toolkit packages. They live in NVIDIA's apt repo.

Code

Install CUDA 13.2 toolkit on Ubuntu 22.04 (works for native + WSL)·bash
# Inside Ubuntu (native or WSL)
sudo apt update
sudo apt install build-essential gnupg curl -y

# Add NVIDIA's package key + repo
sudo mkdir -p /etc/apt/keyrings
curl -fsSL https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/3bf863cc.pub \
  | sudo tee /etc/apt/keyrings/nvidia.asc > /dev/null

echo 'deb [signed-by=/etc/apt/keyrings/nvidia.asc] \
https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2204/x86_64/ /' \
| sudo tee /etc/apt/sources.list.d/cuda.list

sudo apt update
sudo apt install cuda-toolkit-13-2 -y

# Wire up PATH + library path system-wide
echo 'export PATH=/usr/local/cuda-13.2/bin:$PATH' | sudo tee /etc/profile.d/cuda.sh
echo 'export LD_LIBRARY_PATH=/usr/local/cuda-13.2/lib64:$LD_LIBRARY_PATH' \
  | sudo tee -a /etc/profile.d/cuda.sh
source /etc/profile.d/cuda.sh

nvcc --version  # release 13.2
Common WSL pitfalls + fixes·bash
# 'nvidia-smi: command not found' inside WSL
#   → Make sure the Windows-side NVIDIA driver is recent enough
#     (CUDA on WSL needs driver 470+).

# 'nvcc: command not found' even after install
#   → source /etc/profile.d/cuda.sh, or just open a new shell.

# 'cuda.h: No such file or directory' when compiling third-party code
#   → Add -I/usr/local/cuda/include to your compile flags.

# Slow first kernel launch (~1-2s)
#   → That's the JIT warming up. Pre-compile for your sm_XX to skip it.

External links

Exercise

Pick whichever Linux flavor you have access to (native, WSL, or Colab) and get to a green nvcc --version. On Colab, that means opening a notebook, switching runtime to GPU, and running !nvcc --version in a cell. The bar is identical: a version string back. Stop here — the next lesson uses what you just installed.

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.