WSL配置

WSL安装与对应linux发行版下载

WSL实际是WSL2,按照Microsoft官方教程操作即可

linux发行版如Ubuntu在Microsoft Store中下载即可

常用操作

查看 WSL 的运行状态

1
wsl -l -v

关闭wsl

1
wsl --shutdown

导出当前的 Linux 系统镜像:

1
wsl --export Ubuntu d:\image_ubuntu.tar

移除之前注册的 WSL,此操作可以不需要重新在Microsoft Store中重新下载linux发行版

1
wsl --unregister Ubuntu

换源

Ubuntu的系统自带的配置文件在/etc/apt/source.list中

首先进入配置文件目录,如下命令:

1
cd /etc/apt

备份source.list

1
sudo cp sources.list sources.list.bak

根据Ubuntu版本修改source.list为如下的版本,可用ggdG快速删除内容

阿里云Ubuntu20.04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
deb https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ focal-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ focal-backports main restricted universe multiverse

阿里云Ubuntu22.04

1
2
3
4
5
6
7
8
9
10
11
12
13
14
deb https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-security main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-updates main restricted universe multiverse

# deb https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse
# deb-src https://mirrors.aliyun.com/ubuntu/ jammy-proposed main restricted universe multiverse

deb https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse
deb-src https://mirrors.aliyun.com/ubuntu/ jammy-backports main restricted universe multiverse

安装AnaConda

首先回到根目录下,下载安装包:在此地址 https://www.anaconda.com/download/success 中找到安装包的链接

1
wget https://repo.anaconda.com/archive/Anaconda3-2024.02-1-Linux-x86_64.sh

安装 anaconda,按照官方配置不需要设置~/.bashrc

1
bash Anaconda3-2024.02-1-Linux-x86_64.sh

在~/.bashrc中(可选)设置 Anaconda 快捷键,需要通过source ~/.bashrc激活

1
2
alias act='conda activate'
alias deact='conda deactivate'

配置cuda

Nvidia官方CUDA on WSL (nvidia.com)已经有了一定的支持,不过还需要增加一些额外配置

首先,按照官方guide,remove the old GPG key

1
sudo apt-key del 7fa2af80

接下来,在CUDA Toolkit Archive | NVIDIA Developer中选择需要的Cuda版本进行下载,有WSL-Ubuntu的官方支持

按照提供的Base Installer的指导安装即可

最后在~/.bashrc 中添加环境变量,以安装的cuda版本为11.3为例,需要添加如下的变量,终端执行 source ~/.bashrc即可生效

1
2
3
4
export CUDA_HOME="/usr/local/cuda-11.3"
export CUDA_INSTALL_PATH="/usr/local/cuda-11.3"
export PATH=$CUDA_INSTALL_PATH/bin:$PATH
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/cuda-11.3/lib64

参考

WSL2的安装与配置(创建Anaconda虚拟环境、更新软件包、安装PyTorch、VSCode)-CSDN博客

CUDA on WSL (nvidia.com)

CUDA on WSL2安装记录 - 知乎 (zhihu.com)

WSL不同版本的Ubuntu更换清华镜像,加速Ubuntu软件下载速度_wsl下载ubuntu速度慢-CSDN博客

Ubuntu配置CUDA环境变量究极解读_ubuntu中cuda环境变量设置-CSDN博客

CUDA与CUDNN在Windows下的安装与配置(超级详细版)_cudnn安装windows-CSDN博客