NVIDIA CUDA WSL2
WSL2 lets Windows run the native Linux CUDA toolchain, giving you both the Windows desktop and a Linux development environment. The key distinction: the driver is installed only on the Windows side; inside WSL you install only the toolkit and must not install the native Linux driver packages. This guide covers both installation paths: system-wide apt (requires sudo) and the fully root-free user-level runfile.
If you want native Windows (not WSL) CUDA and cuDNN configuration instead, see the Windows CUDA & cuDNN Development Environment Setup Guide.
1. Prerequisites
On the Windows host, install a WSL-capable NVIDIA driver (Game Ready or Studio both work; recent versions include WSL CUDA support). The driver is installed only on the Windows side.1
Update WSL and the kernel
In Windows PowerShell, confirm and update WSL:
2
Confirm the GPU is visible inside WSL
This step needs no CUDA toolkit; it only verifies the driver mapping:
If the GPU is not detected here, go back and fix the Windows-side driver and WSL kernel version first. Do not proceed to install the toolkit.
2. System-wide install (apt, requires sudo)
An account with sudo runs this once, and all users share the same toolkit.1
Install the WSL keyring and the toolkit
/usr/local/cuda-13.3, default permissions 755, readable and executable by all users.2
Set global environment variables (sudo users only)
3
Switch between coexisting versions
With multiple versions installed, use update-alternatives to switch the
/usr/local/cuda symlink:3. User-level install (runfile, no sudo)
An account without sudo installs via runfile into a custom directory, with no root required at any point.1
Download and run the runfile
2
Set personal environment variables
4. Comparing the two installation methods
Click any cell for details. Use apt when you have sudo and multiple users share one stable version; use runfile when permissions are restricted or each project pins its own version.5. Switching users
WSL identity switching comes in three forms: one-time, permanent default, and temporary inside WSL.- One-time (does not change default)
- Change the permanent default login user
- Temporary switch inside WSL
6. Troubleshooting a missing nvidia-smi
Under WSL, nvidia-smi is mounted from the Windows driver at/usr/lib/wsl/lib/nvidia-smi; it has nothing to do with the native Linux nvidia-utils package.
1
Check whether the mounted file exists
2
If it exists, add it to PATH
Without sudo, write it into If the directory is empty, go back and check the Windows-side driver and WSL kernel version.
~/.bashrc:7. Notes on sudo
The insults easter egg is not a failureIf entering the wrong sudo password or using an unauthorized account shows something like
I'm sorry <user>. I'm afraid I can't do that, that is a humorous rejection message from a sudoers Defaults insults setting (a nod to HAL 9000). It is normal behavior, not a system fault.8. Common errors
Verification
After installing, run the full verification flow to confirm all four layers work: the driver mapping (nvidia-smi), the compiler (nvcc), the framework layer (PyTorch), and thatlibcuda.so was not overwritten by the toolkit. Press play to watch it run line by line:
The CUDA Version shown by nvidia-smi is the maximum CUDA version the driver supports (e.g. 13.3), not the toolkit version you installed; the toolkit version comes from nvcc --version. CUDA has backward compatibility: a driver newer than the toolkit is fine, the reverse is not.