ArchWSL安装

启动win10的wsl2功能

1、要求

  • 对于 x64 系统:版本 1903 或更高,内部版本号 18362 或更高
  • 对于 ARM64 系统:版本 2004 或更高,内部版本号 19041 或更高
  • 对于 VMware Workstation Pro 16+ 用户:版本 2004 或更高
  • 对于 Oracle VM VirtualBox 6+ 用户:版本 2004 或更高

2、安装 WSL 2 之前,必须启用“虚拟机平台”可选功能

以管理员身份打开 PowerShell 并运行

1
2
3
dism.exe /online /enable-feature /featurename:Microsoft-Windows-Subsystem-Linux /all /norestart

dism.exe /online /enable-feature /featurename:VirtualMachinePlatform /all /norestart

3、下载 Linux 内核更新包

下载最新包

安装更新包

4、将 WSL 2 设置为默认版本

打开终端执行

1
wsl --set-default-version 2

重新启动计算机,以完成 WSL 安装并更新到 WSL 2

5、下载ArchWSL

6、完成安装后的操作

参考 ArchWSL文档

设置Root密码

1
2
>Arch.exe
[root@PC-NAME]# passwd

设置默认用户

参考 ArchWiki 的 SudoUser and groups 页。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>Arch.exe
[root@PC-NAME]# echo "%wheel ALL=(ALL) ALL" > /etc/sudoers.d/wheel
(设置 sudoers 文件。)

[root@PC-NAME]# useradd -m -G wheel -s /bin/bash {username}
(添加用户)

[root@PC-NAME]# passwd {username}
(设置默认用户密码)

[root@PC-NAME]# exit

>Arch.exe config --default-user {username}
(设置默认用户)

Arch配置

1、Arch 初始化

初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 更新密钥

sudo pacman-key --init
sudo pacman-key --populate
sudo pacman syy archlinux-keyring

# 换源
# vim /etc/pacman.conf
[archlinuxcn]
Server = https://mirrors.ustc.edu.cn/archlinuxcn/$arch
# vim /etc/pacman.d/mirrorlist
# 中科大
Server = https://mirrors.ustc.edu.cn/archlinux/$repo/os/$arch

# china: https://archlinux.org/mirrorlist/?country=CN&protocol=https&ip_version=4

更换中文语言

1
2
3
4
5
6
7
8
9
10
11
12
13
# vim /etc/locale.gen
# 找到 #zh_CM.UTF-8 把 "#" 删除
zh_CN.UTF-8

# 更新
> sudo locale-gen

# ~/.bashrc 加入
# export LANG=zh_CN.UTF-8
export LANGUAGE=zh_CN.UTF-8
export LC_ALL="zh_CN.UTF-8"
export LC_CTYPE="zh_CN.UTF-8"

中文乱码

推荐安装noto-fonts-cjk

1
2
# 安装中文字体
sudo pacman -S noto-fonts-cjk

2、安装常用软件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 安装最新版lib32-glibc
sudo pacman -S glibc lib32-glibc
# 基本 linux 命令集
sudo pacman -S base-devel
# yay
sudo pacman -S yay
# yay 换源
yay --aururl "https://aur.tuna.tsinghua.edu.cn" --save
# 其它一些常用的指令
sudo pacman -S neofetch lolcat bat tree
# git openssh man-pages
sudo pacman -S git openssh man-pages
# 安装 firacode 字体
sudo pacman -S nerd-fonts-fira-code
# Jetbrains Mono 字体
yay -S nerd-fonts-jetbrains-mono

3、终端zsh美化

zsh美化

安装 oh-my-zsh

1
2
3
4
# yay 安装
yay -S oh-my-zsh-git
# 安装在 /usr/share/oh-my-zsh

安装zsh插件

copy 知乎:常用的oh-my-zsh插件

zsh-autosuggestions

会记录你之前输入过的所有命令,并且自动匹配你可能想要输入命令,然后按→补全

1
2
# 切换到 oh-my-zsh/plugins 目录
git clone https://github.com/zsh-users/zsh-autosuggestions

zsh-syntax-highlighting

命令太多,有时候记不住,等输入完了才知道命令输错了,这个插件直接在输入过程中就会提示你,当前命令是否正确,错误红色,正确绿色

1
2
3
4
5
6
7
8
9
10
11
12
# 切换到 oh-my-zsh/plugins 目录
git clone https://github.com/zsh-users/zsh-syntax-highlighting

# .zshrc
plugins(
git
z
sudo
zsh-syntax-highlighting
zsh-autosuggestions
)

Linux的C/C++配置

安装调试与编译软件

参考 Build and Debug C++ with WSL 2 Distributions and Visual Studio 2022

1
sudo pacman -S gcc gdb make cmake ninja rsync zip

疑惑

报错libcuda.so.1

参考Windows10 通过linux子系统WSL2安装nvidia-docker

/usr/lib/wsl/lib/libcuda.so.1 is not a symbolic link

原因: /usr/lib/wsl/lib/目录下都是文件而不是链接,且该目录只读,需要在其他目录操作

1
2
3
4
5
6
7
8
9
10
11
12
13
cd /usr/lib/wsl
sudo mkdir lib2
sudo ln -s lib/* lib2
# 更改wsl配置文件
sudo vim /etc/ld.so.conf.d/ld.wsl.conf
# 将 /usr/lib/wsl/lib 改为 /usr/lib/wsl/lib2
# 测试修改是否生效
sudo ldconfig
# 永久修改
sudo cat >> /etc/wsl.conf << EOF
[automount]
ldconfig = fasle
EOF