跳转到内容

设置 WSL Ubuntu 初始环境 ​

提示

TL;DR

这就是正常软件在 Linux 上的安装方式。

不要把 WSL 当作一个虚拟机瞎玩,下面的 gh auth 等会在 WSL 里面保存你的凭据!

安装 ​

pwsh
wsl --install Ubuntu --location "<目录路径>" -n --name "<显示的名称>"

其中,--location、-n、--name 参数可省略,这些参数的意思请见 wsl --help 输出。

然后,启动发行版,设置用户名和密码。

网络问题 ​

pwsh
无法从 'https://raw.githubusercontent.com/microsoft/WSL/master/distributions/DistributionInfo.json' 提取通讯组列表。与服务器的连接被重置
错误代码: Wsl/InstallDistro/0x80072eff

换个网络,或者手机开热点。

更新 ​

bash
sudo apt update && sudo apt upgrade

Python ​

bash
curl -LsSf https://astral.sh/uv/install.sh | sh

见:https://docs.astral.sh/uv/getting-started/installation/

bash
uv python install 3.15

见:https://docs.astral.sh/uv/guides/install-python/

Vite+ ​

安装配置 ​

bash
nano ~/.bashrc

添加这些:

bash
# Vite+
# https://viteplus.dev/guide/global-cli#installation-variables
export VP_SETUP_NODE_VERSION="latest"
export VP_NODE_MANAGER="yes"
export VP_PM_MANAGER="yes"
# VP_HOME / VP_BIN_DIR / VP_DATA_DIR / VP_CACHE_DIR / VP_NPM_MANAGER / VP_PNPM_MANAGER / VP_YARN_MANAGER / VP_BUN_MANAGER = unset

保存。

安装 ​

bash
curl -fsSL https://vite.plus | bash

见:https://viteplus.dev/guide/global-cli#install

现在,node、npm、pnpm、yarn、bun 这些都有了,你可以直接使用前面提到的工具管理项目,也可以使用 vp 命令管理。

fish shell ​

bash
sudo add-apt-repository ppa:fish-shell/release-4
sudo apt update
sudo apt install fish

见:https://fishshell.com/ 和 https://launchpad.net/~fish-shell/+archive/ubuntu/release-4

just ​

bash
sudo apt update && sudo apt install just

# 或
snap install --edge --classic just

见:https://just.systems/man/en/packages.html 或 https://just.systems/man/zh/安装包.html

GitHub cli ​

安装见:https://github.com/cli/cli/blob/trunk/docs/install_linux.md#debian

bash
$ gh auth login --expiring

? Where do you use GitHub? GitHub.com
? What is your preferred protocol for Git operations on this host? HTTPS
! You asked for an expiring token, which gh refreshes automatically. For that to work, gh must be your Git credential helper for github.com. Otherwise Git will not learn about refreshed tokens and your HTTPS Git operations will start to fail once the current token expires, within hours.
? How would you like to proceed? Set up gh as your Git credential helper (recommended)

! One-time code (XXXX-XXXX) copied to clipboard
Press Enter to open https://github.com/login/device in your browser...
! Failed opening a web browser at https://github.com/login/device
  exec: "xdg-open,x-www-browser,www-browser,wslview": executable file not found in $PATH
  Please try entering the URL in your browser manually
✓ Authentication complete.
- gh config set -h github.com git_protocol https
✓ Configured git protocol
! Authentication credentials saved in plain text
✓ Received expiring refreshable token
✓ Logged in as XXX

关于 --expiring 参数,见 GitHub Blog | GitHub CLI: Opt in to expiring, auto-refreshing OAuth tokens。

gh stack ​

bash
gh extension install github/gh-stack

见:https://github.com/github/gh-stack

在没安装时直接 gh stack 也会让你安装。

Visua Studio Code (VSCode) ​

在 Windows 上的 VSCode 安装 ms-vscode-remote.remote-wsl 扩展。

然后左下角远程到 WSL 发行版(使用发行版连接到 WSL……)。

Git ​

通常是内置的。

默认主分支名 ​

bash
git config --global init.defaultBranch main

对提交签名 ​

见 GitHub Docs | Generating a new GPG key。

修复签名失败 ​

bash
error: gpg failed to sign the data:
...
gpg: 签名时失败: 对设备不适当的 ioctl 操作
[GNUPG:] FAILURE sign ...
gpg: signing failed: 对设备不适当的 ioctl 操作

fatal: 无法写提交对象

在 ~/.bashrc 中添加:

bash
# GPG
export GPG_TTY=$(tty)

迁移 GPG 密钥 ​

从旧系统导出:

bash
gpg --list-keys
gpg --export-secret-keys -a "<keyid>" > private_key.asc
gpg --export -a "<keyid>" > public_key.asc
mv -v "./private_key.asc" "/mnt/<Windows上的路径>/private_key.asc"
mv -v "./public_key.asc" "/mnt/<Windows上的路径>/public_key.asc"

在新系统导入:

bash
cp -v "/mnt/<Windows上的路径>/private_key.asc" "./private_key.asc"
cp -v "/mnt/<Windows上的路径>/public_key.asc" "./public_key.asc"
gpg --import private_key.asc
gpg --import public_key.asc

在新系统信任:

bash
gpg --edit-key "<keyid>"

gpg (GnuPG) 2.4.8; Copyright (C) 2025 g10 Code GmbH
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

私钥可用。

...

gpg> trust
...

请决定您对这名用户能否正确地验证其他用户密钥
(通过查看护照,检查不同来源的的指纹等等)的相信程度

  1 = 我不知道或不作答
  2 = 我不相信
  3 = 我勉强相信
  4 = 我完全相信
  5 = 我绝对相信
  m = 回到主菜单

您的决定是什么? 5

gpg> quit

使用 VitePress + Catppuccin (Latte + Mocha) 主题构建 ❤️