在 Windows 上安装 WSL2 并配置 Arch Linux 发行版,包括桌面环境、开发工具等。
打开 PowerShell(管理员权限)
安装WSL
设置默认WSL版本为WSL2
1
| wsl --set-default-version 2
|
查看可用发行版
安装完后需要重启 Windows
安装Linux
1
| wsl --install -d archlinux
|
常用命令
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| wsl --list --verbose wsl -l -v wsl --set-version <Distro> 2 wsl --set-default-version 2 wsl --shutdown wsl --terminate <Distro> wsl --unregister <Distro> wsl --import <Distro> <InstallDir> <TarFile> wsl --export <Distro> <TarFile> wsl wsl -d <Distro> wsl -u <User> wsl --user <User> wsl --exec <Command> wsl -e <Command> wsl --update wsl --update rollback wsl --help
|
ArchLinux配置
直接用的root用户,方便,每次执行命令也不用加sudo
archLinuxcn镜像
- 编辑/etc/pacman.conf在末尾参数加入
1 2 3
| [archlinuxcn] SigLevel = Optional TrustedOnly Server = http://repo.archlinuxcn.org/$arch
|
1 2
| pacman -Syyu pacman -S archlinuxcn-keyring
|
安装常用包
1
| pacman -S --needed tmux vim unzip proxychains-ng yazi openssh fastfetch ttf-dejavu wqy-zenhei noto-fonts-cjk bash-completion glibc-locales git paru base-devel docker docker-compose
|
https://learn.microsoft.com/zh-cn/windows/wsl/networking#identify-ip-address
https://www.cnblogs.com/netWild/p/18503950
配置参考
1 2 3 4 5 6 7 8 9
| pacman -S fnm eval "$(fnm env --use-on-cd --shell bash)"
sudo pacman -S jdk-openjdk jdk-17openjdk archlinux-java status sudo archlinux-java set java-17-openjdk java --version
curl --proto '=https' --tlsv1.2 https://sh.rustup.rs -sSf | sh
|
.wslconfig(放在 Windows 用户目录下)
1 2 3 4 5 6 7 8 9 10 11
| [wsl2] memory=4GB processors=2 [experimental] autoMemoryReclaim=gradual networkingMode=mirrored dnsTunneling=true firewall=true autoProxy=false sparseVhd=true
|
新增sudo用户(可选)
1 2
| useradd -m -G wheel -s /bin/bash zhuyuqinlan passwd zhuyuqinlan
|
允许wheel组使用sudo(可选)
编辑/etc/sudoers
找到%wheel ALL=(ALL) ALL取消注释
设置wsl
编辑/etc/wsl.conf
如果配置了其他用户可以把root换掉
1 2 3 4 5
| [boot] systemd=true
[user] default=root
|
设置语言环境
1 2 3
| vim /etc/locale.gen locale-gen echo "LANG=en_US.UTF-8" | sudo tee /etc/locale.conf
|
.bash_profile
1 2 3
| if [ -f ~/.bashrc ]; then source ~/.bashrc fi
|
.bashrc
1 2 3 4 5 6 7 8
| eval "$(fnm env --use-on-cd --shell bash)" alias dps='docker ps --format "table {{.ID}} {{.Names}} {{.Ports}} {{.Status}}"' alias dis='docker images' alias ta='tmux attach -t' alias tw='tmux split-window' alias twh='tmux split-window -h' alias f='fastfetch' alias ya='yazi'
|
docker开机自启
1
| systemctl enable --now docker
|
设置docker pull代理
1 2 3 4 5 6 7 8 9
| mkdir -p /etc/systemd/system/docker.service.d tee /etc/systemd/system/docker.service.d/http-proxy.conf > /dev/null <<'EOF' [Service] Environment="HTTP_PROXY=http://127.0.0.1:10808" Environment="HTTPS_PROXY=http://127.0.0.1:10808" Environment="NO_PROXY=localhost,127.0.0.1" EOF systemctl daemon-reload systemctl restart docker
|