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
I'm afraid I can't do that is not the insults easter egg, and not a failureThis HAL 9000 line is the fixed denial message of sudo-rs (the Rust rewrite of sudo; the default since Ubuntu 25.10 and kept in 26.04 LTS, while 24.04 still defaults to the original sudo). It appears whenever sudoers does not allow you to run the command: the account is not in the sudo group, or it has sudo but not for this command or target user. It means the permission was denied, which is normal behavior, not a system fault. A wrong password takes a separate authentication-failure path and does not print this line.Defaults insults is the real easter egg, but it exists only in the original sudo: on a wrong password it answers with a random humorous line, and it is off by default. sudo-rs ignores the setting (marked ignored in its source). For an account with no permission, the original sudo prints <user> is not in the sudoers file instead.sudo -l -U <username> lists; groups alone is not enough, because a grant can also come from a separate file in /etc/sudoers.d/:
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.