wsl2 安装参考文档:http://t.csdnimg.cn/ClwJ9
演示安装ubuntu 22
列出可安装的子系统 命令:wsl --list --online
PS C:\Users\linyu> wsl --list --online
以下是可安装的有效分发的列表。
使用 'wsl.exe --install <Distro>' 安装。
NAME FRIENDLY NAME
Ubuntu Ubuntu
Debian Debian GNU/Linux
kali-linux Kali Linux Rolling
Ubuntu-18.04 Ubuntu 18.04 LTS
Ubuntu-20.04 Ubuntu 20.04 LTS
Ubuntu-22.04 Ubuntu 22.04 LTS
OracleLinux_7_9 Oracle Linux 7.9
OracleLinux_8_7 Oracle Linux 8.7
OracleLinux_9_1 Oracle Linux 9.1
openSUSE-Leap-15.5 openSUSE Leap 15.5
SUSE-Linux-Enterprise-Server-15-SP4 SUSE Linux Enterprise Server 15 SP4
SUSE-Linux-Enterprise-15-SP5 SUSE Linux Enterprise 15 SP5
openSUSE-Tumbleweed openSUSE Tumbleweed
安装ubuntu 命令:wsl --install -d Ubuntu-22.04
PS C:\Users\linyu> wsl --install -d Ubuntu-22.04
正在安装: Ubuntu 22.04 LTS
已安装 Ubuntu 22.04 LTS。
正在启动 Ubuntu 22.04 LTS...
Installing, this may take a few minutes...
Please create a default UNIX user account. The username does not need to match your Windows username.
For more information visit: https://aka.ms/wslusers
输入账号密码 安装完成
Enter new UNIX username:
New password:
Retype new password:
passwd: password updated successfully
Installation successful!
安装显卡驱动
两种方法 二选一即可
1. 第一种方法:
参考官网文档: WSL 上的 CUDA (nvidia.com)
或参考文档:http://t.csdnimg.cn/TVjCa
2.利用ubuntu官方源安装
执行nvidia-smi命令查看英伟达显卡信息,如果没有安装驱动会提示安装,开始安装默认源里面的最新版。
root@DESKTOP-TUR5ISE:~# nvidia-smi
Command 'nvidia-smi' not found, but can be installed with:
apt install nvidia-utils-510 # version 510.60.02-0ubuntu1, or
apt install nvidia-utils-510-server # version 510.47.03-0ubuntu3
apt install nvidia-utils-390 # version 390.157-0ubuntu0.22.04.2
apt install nvidia-utils-418-server # version 418.226.00-0ubuntu5~0.22.04.1
apt install nvidia-utils-450-server # version 450.248.02-0ubuntu0.22.04.1
apt install nvidia-utils-470 # version 470.223.02-0ubuntu0.22.04.1
apt install nvidia-utils-470-server # version 470.223.02-0ubuntu0.22.04.1
apt install nvidia-utils-525 # version 525.147.05-0ubuntu0.22.04.1
apt install nvidia-utils-525-server # version 525.147.05-0ubuntu0.22.04.1
apt install nvidia-utils-535 # version 535.129.03-0ubuntu0.22.04.1
apt install nvidia-utils-535-server # version 535.129.03-0ubuntu0.22.04.1
安装命令:apt install nvidia-utils-535
root@DESKTOP-TUR5ISE:~# apt install nvidia-utils-535
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
libnvidia-compute-535
Suggested packages:
nvidia-driver-535
The following NEW packages will be installed:
libnvidia-compute-535 nvidia-utils-535
0 upgraded, 2 newly installed, 0 to remove and 84 not upgraded.
Need to get 41.1 MB of archives.
After this operation, 177 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 libnvidia-compute-535 amd64 535.161.07-0ubuntu0.22.04.1 [40.7 MB]
Get:2 http://archive.ubuntu.com/ubuntu jammy-updates/restricted amd64 nvidia-utils-535 amd64 535.161.07-0ubuntu0.22.04.1 [415 kB]
Fetched 41.1 MB in 10s (4005 kB/s)
Selecting previously unselected package libnvidia-compute-535:amd64.
(Reading database ... 24998 files and directories currently installed.)
Preparing to unpack .../libnvidia-compute-535_535.161.07-0ubuntu0.22.04.1_amd64.deb ...
Unpacking libnvidia-compute-535:amd64 (535.161.07-0ubuntu0.22.04.1) ...
Selecting previously unselected package nvidia-utils-535.
Preparing to unpack .../nvidia-utils-535_535.161.07-0ubuntu0.22.04.1_amd64.deb ...
Unpacking nvidia-utils-535 (535.161.07-0ubuntu0.22.04.1) ...
Setting up libnvidia-compute-535:amd64 (535.161.07-0ubuntu0.22.04.1) ...
Setting up nvidia-utils-535 (535.161.07-0ubuntu0.22.04.1) ...
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.4) ...
/sbin/ldconfig.real: /usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link
再次执行nvidia-smi 命令看是否能看到显卡信息,如何能看到则安装成功。
root@DESKTOP-TUR5ISE:~# nvidia-smi
Mon Mar 25 16:03:14 2024
+---------------------------------------------------------------------------------------+
| NVIDIA-SMI 535.161.07 Driver Version: 537.70 CUDA Version: 12.2 |
|-----------------------------------------+----------------------+----------------------+
| 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 4090 On | 00000000:01:00.0 On | Off |
| 30% 28C P8 19W / 450W | 1129MiB / 24564MiB | 5% Default |
| | | N/A |
+-----------------------------------------+----------------------+----------------------+
+---------------------------------------------------------------------------------------+
| Processes: |
| GPU GI CI PID Type Process name GPU Memory |
| ID ID Usage |
|=======================================================================================|
| No running processes found |
+---------------------------------------------------------------------------------------+
安装显卡cuda驱动
两种方法二选一即可
1.通过ubuntu官方源安装:apt install nvidia-cuda-toolkit
2.通过添加nvidia官方源的方式安装:
选好后下面会提供安装方法一条一条执行即可
wget https://developer.download.nvidia.com/compute/cuda/repos/wsl-ubuntu/x86_64/cuda-wsl-ubuntu.pin
sudo mv cuda-wsl-ubuntu.pin /etc/apt/preferences.d/cuda-repository-pin-600
wget https://developer.download.nvidia.com/compute/cuda/12.4.0/local_installers/cuda-repo-wsl-ubuntu-12-4-local_12.4.0-1_amd64.deb
sudo dpkg -i cuda-repo-wsl-ubuntu-12-4-local_12.4.0-1_amd64.deb
sudo cp /var/cuda-repo-wsl-ubuntu-12-4-local/cuda-*-keyring.gpg /usr/share/keyrings/
sudo apt-get update
sudo apt-get -y install cuda-toolkit-12-4
安装过程取决于网速,应该是需要下载4个G左右的文件,如果顺利的话
将看到如下界面,如果有版本或者其他问题请参考官网。
添加环境变量:
编辑vim ~/.bashrc 最后面添加上
export PATH=/etc/alternatives/cuda-12/bin:$PATH
export LD_LIBRARY_PATH=/etc/alternatives/cuda-12/lib64:$LD_LIBRARY_PATH
source ~/.bashrc 重新加载一下环境变量
执行nvcc -V 能看到版本信息说明安装成功
root@DESKTOP-TUR5ISE:/etc/alternatives/cuda-12# nvcc -V
nvcc: NVIDIA (R) Cuda compiler driver
Copyright (c) 2005-2024 NVIDIA Corporation
Built on Tue_Feb_27_16:19:38_PST_2024
Cuda compilation tools, release 12.4, V12.4.99
Build cuda_12.4.r12.4/compiler.33961263_0
标签:utils,ubuntu,apt,535,cuda,install,nvidia,wsl2
From: https://blog.csdn.net/m0_61069946/article/details/137027924