Scoop 快速搭建开发环境

Scoop 是一个 Windows 下基于 PowerShell 编写的的第三方包管理器,能够自动下载、解压、设置环境变量、添加 shim、持久化数据。我们可以通过 Scoop 来安装一些工具,简化开发环境搭建。

本文提供的方法无需特殊网络环境即可直接下载安装,并配置好国内镜像。

安装 Scoop

这里使用我们的特别版Scoop,加入了一些特性,能够在国内环境自动切换镜像使用。

打开 PowerShell,执行以下命令安装 Scoop。无需管理员权限。

1
irm c.xrgzs.top/c/scoop | iex

执行完上面的命令,你的电脑中已经安装好了 Git for Windows、7-Zip、Aria2,并添加了常用的仓库,可以基本满足使用。

TIPS:正常情况下 Scoop 安装完成的软件不会创建桌面快捷方式,可以在开始菜单的 Scoop Apps 文件夹中找到,将其拖到桌面即可。如果你希望自动创建快捷方式到桌面,可以使用桌面整理软件给 %APPDATA%\Microsoft\Windows\Start Menu\Programs\Scoop Apps 映射到格子即可。

配置 Git

配置好 Git 以便能够拉取提交代码。如果不需要,可以跳过此步骤。

需要准备一个电子邮箱,且绑定到 GitHub / Gitee 等代码托管平台。

打开 Git Bash:

1
git-bash.exe

配置 Git 的用户名和邮箱:

1
2
git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"

(可选)配置客户端记住密码,避免每次都输入密码:

1
git config --global credential.helper store

(可选)配置默认文本编辑器(如果不想用默认的Vim):

1
git config --global core.editor "code --wait"

查看配置信息:

1
git config --list

配置 SSH 推拉代码

配置能够正确推拉如下格式的仓库:

1
git clone git@gitee.com/user/repo.git

生成 SSH 密钥:

1
ssh-keygen -t ed25519

根据提示输入路径(回车即可)、密码(可为空)。

密钥和公钥默认存放到 %USERPROFILE%\.ssh 目录下,其中 id_ed25519 为私钥,id_ed25519.pub 为公钥。

显示 SSH 公钥:

1
cat .ssh/id_ed25519.pub

将 SSH 公钥的内容复制到 GitHub / Gitee 等平台的 SSH 管理中。

TIPS:如果你有服务器的话,可以将这个文件也上传到服务器上的 ~\.ssh\id_ed25519.pub,这样就可以实现 SSH 免密登录。

此时即可正常推拉代码,且提交具有身份验证,网页端会显示 Verified

配置 HTTPS

配置能够正确推拉如下格式的仓库:

1
git clone https://gitee.com/user/repo.git

这种情况下,拉取/推送代码时可以配置登录信息。一般情况下到这里已经够用。

一些仓库要求强制 Verified,需要配置 GPG 签名验证身份。

配置 GPG 签名

生成 GPG 私钥:

1
2
3
4
# Ensure gpg is installed
gpg --version
# Generate GPG key
gpg --full-generate-key

根据提示输入用户名、电子邮箱(要求同上),还有私钥的密码(请妥善保管,提交 commit 时要输入)。

生成 GPG 公钥:

1
2
3
4
# Get your GPG key ID
gpg --list-secret-keys
# Generate GPG public key
gpg --armor --export {key_id}

将得到的 GPG 公钥复制到 GitHub / Gitee 等平台的 GPG 管理中。

配置 Git 的默认 GPG 签名:

1
2
3
git config --global user.signingkey {key_id}
# Use GPG signature for commit by default
git config --global commit.gpgsign true

配置完成后每次 commit 时都会自动签名,并在网页端显示 Verified

(可选)导入平台 GPG 公钥

信任 GitHub 平台的默认公钥:

1
2
3
4
5
curl https://github.com/web-flow.gpg | gpg --import
# GitHub (web-flow commit signing) <noreply@github.com>
gpg --sign-key 4AEE18F83AFDEB23
# GitHub <noreply@github.com>
gpg --sign-key B5690EEEBB952194

信任 Gitee 平台的默认公钥:

1
2
3
curl https://gitee.com/gitee.gpg | gpg --import
# Gitee (Gitee web-flow commit signing.) <noreply@gitee.com>
gpg --sign-key 173E9B9CA92EEF8F

信任完成后即可在本地验证网页提交的签名。

1
git log --show-signature

配置终端

安装 Windows Terminal

Windows 11 已经默认安装,除非你是 LTSC 版本。

建议通过商店安装 Windows Terminal,并配置为默认终端。

亦可使用 Scoop 执行便携安装:

1
2
scoop install extras/windows-terminal
reg import "$(scoop prefix windows-terminal)\install-context.reg"

必须要安装一个终端软件,不要使用系统内置的 conhost.exe,不然折磨死人。

升级到 PowerShell Core

由于 Windows 自带的 PowerShell 5.1 速度慢、兼容性差、功能少,且默认输出带 BOM,这里建议升级到跨平台的 PowerShell Core。在其他 Shell 中,Scoop 会自动切换为 PowerShell Core。

1
2
3
4
# Install PowerShell Core Non-portable
scoop install gsudo
gsudo scoop install sdoog/pwsh-np
scoop uninstall pwsh-np

为了避免文件编码错误,我们重启到 PowerShell 完成后续的操作。

优化 Windows Terminal 配置

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# 获取 WT 配置路径
$wtSettingsPath = "$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\apps\windows-terminal\current\settings", "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState" | Where-Object { Test-Path "$_\settings.json" } | Select-Object -First 1

# 读取配置
$wtSettings = Get-Content "$wtSettingsPath\settings.json" | ConvertFrom-Json -AsHashtable

# 设置启动居中
$wtSettings.centerOnLaunch = $True

# 打开背景透明模糊效果
# $wtSettings.useAcrylicInTabRow = $True
$wtSettings.profiles.defaults.opacity = 90
$wtSettings.profiles.defaults.useAcrylic = $True

# 应用
# $wtSettings | ConvertTo-Json -Depth 100 | Set-Content "$wtSettingsPath\settings.json" -Encoding UTF8

(可选)设置 CMD 为默认 Shell

由于 PowerShell 中部分体验和 CMD 不一致,个人喜欢将 CMD 设为默认 Shell,然后再安装 Clink 来增强 CMD 的体验。

1
$wtSettings.profiles.defaultProfile = "{0caa0dad-35be-5f56-a8ff-afceeeaa6101}"

安装 Nerd Font

这里我们需要安装 Nerd Font 并将其设为默认,避免一些字符无法显示。个人喜欢使用 Cascadia Code。

Cascadia Code
1
2
3
4
scoop install nerd-fonts/Cascadia-Code

# Apply to Windows Terminal
$wtSettings.profiles.defaults.font = @{ face = "Cascadia Code NF" }

新装的字体需要重启 Windows Terminal 才能被使用,但先不着急重启。

添加 Git Bash 到 Windows Terminal

1
2
3
4
5
6
7
$wtSettings.profiles.list += @{ 
commandline = "$(scoop prefix git)\bin\bash.exe -i -l"
guid = "{2ece5bfe-50ed-5f3a-ab87-5cd4baafed2b}"
icon = "$(scoop prefix git)\mingw64\share\git\git-for-windows.ico"
name = "Git Bash"
startingDirectory = "%USERPROFILE%"
}

添加 MSYS2 到 Windows Terminal

如果后面你想使用 MSYS2,可以添加到 Windows Terminal 中。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# UCRT64
$wtSettings.profiles.list += @{
commandline = "$(scoop prefix msys2-cn)\msys2_shell.cmd -defterm -here -no-start -ucrt64"
guid = "{17da3cac-b318-431e-8a3e-7fcdefe6d114}"
icon = "$(scoop prefix msys2-cn)\ucrt64.ico"
name = "UCRT64 / MSYS2"
startingDirectory = "$(scoop prefix msys2-cn)\home\%USERNAME%"
}
# MSYS
$wtSettings.profiles.list += @{
commandline = "$(scoop prefix msys2-cn)\msys2_shell.cmd -defterm -here -no-start -msys"
guid = "{71160544-14d8-4194-af25-d05feeac7233}"
icon = "$(scoop prefix msys2-cn)\msys2.ico"
name = "MSYS / MSYS2"
startingDirectory = "$(scoop prefix msys2-cn)\home\%USERNAME%"
}
# MinGW64
$wtSettings.profiles.list += @{
commandline = "$(scoop prefix msys2-cn)\msys2_shell.cmd -defterm -here -no-start -mingw64"
guid = "{f0fc850d-4a2a-4bac-bf9c-96958e1d6246}"
icon = "$(scoop prefix msys2-cn)\mingw64.ico"
name = "MinGW64 / MSYS2"
startingDirectory = "$(scoop prefix msys2-cn)\home\%USERNAME%"
}
# Clang64
$wtSettings.profiles.list += @{
commandline = "$(scoop prefix msys2-cn)\msys2_shell.cmd -defterm -here -no-start -clang64"
guid = "{0b71a086-0652-4e48-b9d4-d4b674eab96a}"
icon = "$(scoop prefix msys2-cn)\clang64.ico"
name = "Clang64 / MSYS2"
startingDirectory = "$(scoop prefix msys2-cn)\home\%USERNAME%"
}

保存配置

1
$wtSettings | ConvertTo-Json -Depth 100 | Set-Content  "$wtSettingsPath\settings.json" -Encoding UTF8

配置 Shell

PowerShell

由于加了美化会拖慢 PowerShell 速度,这里我一个美化都不安装,仅创建一下 $PROFILE

1
2
3
4
# Create profile
if (!(Test-Path -Path $PROFILE)) {
New-Item -ItemType File -Path $PROFILE -Force
}

美化:Oh My Posh

Oh My Posh 是一个适用于任何 shell 的提示主题引擎。

1
2
3
4
5
6
# Install oh-my-posh
scoop install oh-my-posh
# Add to profile
"# Enable oh-my-posh`noh-my-posh init pwsh --config '$(scoop prefix oh-my-posh)\themes\powerlevel10k_modern.omp.json' | Invoke-Expression`n" | Out-File $PROFILE -Append
# Add to Windows PowerShell profile (Slow)
# 'oh-my-posh init pwsh | Invoke-Expression' | Set-Content "$env:USERPROFILE\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1"

可以到主题文档查看并选择一个合适的主题来替换掉上面的 powerlevel10k_modern.omp.json

美化:Starship

如果不喜欢 oh-my-posh,我们可以使用 Starship 来代替。

1
2
3
4
5
scoop install starship
# Add to profile
"# Enable starship`nInvoke-Expression (&starship init powershell)`n" | Out-File $PROFILE -Append
# Export preset
starship preset plain-text-symbols > ~\.config\starship.toml

安装自动补全 / 命令预测

由于 PSReadLine 新版 PowerShell 已经自带(虽然版本号稍有落后),因此我们只需要再安装一下对应的补全即可。

1
2
3
4
5
6
7
8
9
# Any Completion
Install-Module CompletionPredictor -Force
"# Object Completion`nImport-Module CompletionPredictor`n" | Out-File $PROFILE -Append
# Scoop Completion
scoop install extras/scoop-completion
"# Scoop Completion`nImport-Module `"$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\scoop-completion`"`n" | Out-File $PROFILE -Append
# Git Completion
scoop install extras/posh-git
"# Git Completion`nImport-Module `"$($(Get-Item $(Get-Command scoop.ps1).Path).Directory.Parent.FullName)\modules\posh-git`"`n" | Out-File $PROFILE -Append

用法:按 Tab 键补全,按 F2 键切换为竖屏模式。

其他

你可以添加其他的配置来自定义 shell 环境

1
code $PROFILE

CMD

CMD 是 Windows 传统的命令行,功能简陋。

BusyBox

为了拓展 CMD 的命令,我们可以安装 BusyBox

1
scoop install busybox

安装完成你就可以使用 lscatgrepdd 等一些 Linux 命令了,虽然是精简版的,但有总比没用强。

注意安装 BusyBox 会覆盖掉一些已经安装的 shims,所以尽量提前安装。

我们可以安装 Clink 来优化 CMD 的体验。个人感觉优化下来比 PowerShell 好用。

1
2
3
4
scoop install clink clink-completions
clink autorun install
@rem Disable auto update (use scoop)
clink set clink.autoupdate off

现在启动 CMD 就可以看到 Clink 的提示信息了。

如果想要配置一下外观,可以执行:

1
2
3
4
5
@rem Make the startup message shorter
clink set clink.logo short
@rem Enable flex prompt (not necessary if you want to use oh-my-posh / starship)
scoop install clink-flex-prompt
flexprompt configure

根据提示完成向导即可。

Bash

由于 Git Bash 自带 Bash 配置,且有性能问题,一般情况下无需优化。

X CMD

可以安装 X CMD,增强 Bash 的体验。

打开 Git Bash 执行以下命令即可。

1
eval "$(curl https://get.x-cmd.com)"

安装 Visual Studio Code

一款强大的编辑器。

1
2
3
4
5
scoop install vscode
# 执行关联
reg import "$(scoop prefix vscode)\install-context.reg"
reg import "$(scoop prefix vscode)\install-associations.reg"
reg import "$(scoop prefix vscode)\install-github-integration.reg"

你可能需要自行安装一下中文语言包和一些插件。

安装 JetBrains 全家桶

1
2
3
4
5
6
7
8
9
10
11
12
13
# scoop install extras/idea
scoop install extras/idea-ultimate
# scoop install extras/pycharm
scoop install extras/pycharm-professional
scoop install extras/phpstorm
scoop install extras/goland
scoop install extras/rider
scoop install extras/clion
scoop install extras/rustrover
scoop install extras/webstorm
scoop install extras/rubymine
scoop install extras/datagrip
scoop install sdoog/jetbra

配置 C/C++ 开发环境

这里不使用Visual Studio(MSVC),而是配置 unix-like 的开发环境,原理是在 Windows 上提供一个 POSIX 环境,如 Cygwin、MSYS2 等。

最好先安装/更新一下 VC 运行库:

1
2
scoop install extras/vcredist2022
scoop uninstall vcredist2022

方法一:Winlibs

与下一种方案不同的是,这种方法更加简单,直接使用 Scoop 管理开发工具链,不需要安装 MSYS2。缺点是丢失了包管理器,不过对于初学者来说足够了。

1
2
3
4
scoop install mingw-winlibs
# Test GCC
gcc --version
cmake --version

现在 GCC 工具链已经安装好了,可以在 VSCode 等工具中使用了。

如需 LLVM 工具链,可以将上面的安装命令中的包名改为:versions/mingw-winlibs-llvm-ucrt

方法二:MSYS2 (建议)

MSYS2 是一个适用于 Windows 的软件分发和构建平台,由 minttybash 命令行终端,gitsubversion 等版本控制系统,tarawk 等工具,autotools 等构建系统组成。可以理解为一个的“子系统”,让 Windows 也能享受 GNU 和开源工具,提供类似于 WSL 的功能。

我们可以在 MSYS2 里面安装 GCC、LLVM 等一些 C/C++ 开发工具链,以及一些使用对应工具链编译出来的二进制文件(不用你手动折腾编译),且可以通过 pacman (Arch Linux 也在用)这个包管理器进行方便的安装和管理。

MSYS2 的 unixy 工具直接基于 Cygwin,对原生 Windows API 支持更好。这里不直接使用 Cygwin 因为其提供的包比较少,且安装使用起来不太友好。

我们平时使用的 Git for Windows 就使用到了 MSYS2 的 MINGW64 环境。虽然 Git for Windows 提供了 MSYS2 的 MINGW64 环境,但 Git Bash 默认包含 Windows 的用户环境(不干净),默认家目录为 Windows 的用户目录,且没有内置 pacman 包管理器,仅用于跑 git。而 MSYS2 更倾向于提供“子系统”,设计上会有些不同,不会继承 Windows 的用户环境,家目录也与 Windows 的用户目录不同,不适合作为日常终端环境使用。

MSYS2 提供了 MSYS、UCRT64、CLANG64、MINGW64 等环境。关于这些环境的区别可以点击链接查看文档中的表格。这里使用 MSYS2 的 UCRT64 环境,与 MSVC 兼容性更好,且使用 gcc 工具链方便使用。如果你需要使用 llvm 工具链,可以使用 MSYS2 的 CLANG64 环境。

这里我们使用 scoop 安装 MSYS2 会将其安装到用户目录下,通常情况下我们会将 MSYS2 安装到 C:\msys64 目录下方便使用,需要注意一下可能和你看的教程不同。通过以下命令安装会自动配置好国内加速镜像,并安装 GCC 工具链和 CMake:

1
2
3
4
5
6
7
8
9
10
scoop install dorado/msys2-cn
# Add UCRT64 to User's PATH permanently
[Environment]::SetEnvironmentVariable("PATH", $("$(scoop prefix msys2-cn)\ucrt64\bin;" + [Environment]::GetEnvironmentVariable("PATH", "User")), "User")
# Refresh Current PATH
$Env:Path = [System.Environment]::GetEnvironmentVariable('Path', 'Machine') + ';' + [System.Environment]::GetEnvironmentVariable('Path', 'User')
# Install mingw-w64 GCC toolchain and CMake
ucrt64 -c "pacman --noconfirm -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-cmake"
# Test GCC
gcc --version
cmake --version

此时 GCC 环境已经配置好,可以在 VSCode 等工具中使用了。

由于 MSYS2 能自己通过 pacman -Syu 升级,可以关闭 Scoop 的升级:

1
scoop hold msys2-cn

(可选)让 MSYS2 能够访问 Windows 的环境

默认情况下 MSYS2 无法访问 Windows 的环境,需要加上参数 -use-full-path 运行,或者设置环境变量:

1
[Environment]::SetEnvironmentVariable("MSYS2_PATH_TYPE", "inherit", "User")

设置完成后,家目录仍不互通。

(可选)让 Windows 能够访问 MSYS2 的环境

默认情况下 Windows 无法调用 MSYS2 中安装的工具,可以将它添加到 PATH:

1
[Environment]::SetEnvironmentVariable("PATH", $([Environment]::GetEnvironmentVariable("PATH", "User") + ";$(scoop prefix msys2-cn)\usr\bin"), "User")

危险:这种行为可能会造成系统不稳定,这里将其添加到最后尽量避免出现问题,家目录也不互通。一般加 UCRT64 解决编译问题就够了。

配置 Python 开发环境

这里我们使用 scoop 安装最新版 Python(MSVC),并配置好国内镜像。

安装最新版 Python

1
2
3
4
5
scoop install python
# Allow applications and third-party installers to find python
reg import "$(scoop prefix python)\install-pep-514.reg"
# Use TUNA's mirror
pip config set global.index-url https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple

安装不同版本的 Python

1
2
scoop install python38
reg import "$(scoop prefix python38)\install-pep-514.reg"

切换 Python 版本

1
2
3
4
5
scoop reset python
python --version # Output: Python 3.13.1

scoop reset python38
python --version # Output: Python 3.8.10

安装 Miniconda

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
scoop install dorado/miniconda
# Use TUNA's mirror
'channels:
- defaults
show_channel_urls: True
envs_dirs:
- ~/.conda/envs
pkgs_dirs:
- ~/.conda/pkgs
default_channels:
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/r
- https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/msys2
custom_channels:
conda-forge: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
pytorch: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
auto: https://mirrors.tuna.tsinghua.edu.cn/anaconda/cloud
' | Set-Content -Path "$env:USERPROFILE\.condarc"

配置 NodeJS 开发环境

安装最新版

1
scoop install nodejs

安装长期支持版本

1
scoop install nodejs-lts

NPM 换源

1
npm config set registry https://registry.npmmirror.com

安装 PNPM

1
npm install -g pnpm

配置 MySQL 开发环境

1
2
3
4
5
6
7
8
9
10
11
12
scoop install mysql mysql-shell
# Start MySQL
mysqld --console
# Launch MySQL Shell
mysqlsh
\connect root@127.0.0.1:3306
# Register MySQL as a service
sudo mysqld --install MySQL --defaults-file="C:\Users\Admin\scoop\apps\mysql\current\my.ini"
# Stop MySQL
sc stop MySQL
# Delete MySQL
sc delete MySQL

配置 Java 开发环境

安装 OpenJDK

1
2
3
scoop install java/openjdk
# Test Java
java --version

安装 Maven

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
scoop install maven

# Use NJU mirror
'<?xml version="1.0" encoding="UTF-8"?>
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
<mirrors>
<mirror>
<id>nju_mirror</id>
<mirrorOf>*</mirrorOf>
<url>https://repo.nju.edu.cn/maven/</url>
</mirror>
</mirrors>
</settings>
' | Set-Content -Path "$env:USERPROFILE\.m2\settings.xml"
# Test Maven
mvn --version
mvn help:effective-settings

安装 Gradle

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
scoop install gradle

# Use NJU mirror
mkdir "$env:USERPROFILE\.gradle"
@"
allprojects {
buildscript {
repositories {
def NJU_REPOSITORY_URL = 'https://repo.nju.edu.cn/maven/'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository `${repo.url} replaced by `$NJU_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository `${repo.url} deleted."
remove repo
}
if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository `${repo.url} deleted."
remove repo
}
if (url.contains('plugins.gradle.org/m2')) {
project.logger.lifecycle "Repository `${repo.url} deleted."
remove repo
}
}
}
maven { url NJU_REPOSITORY_URL }
mavenLocal()
}
}

repositories {
def NJU_REPOSITORY_URL = 'https://repo.nju.edu.cn/maven/'
all { ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
def url = repo.url.toString()
if (url.startsWith('https://repo1.maven.org/maven2')) {
project.logger.lifecycle "Repository `${repo.url} replaced by `$NJU_REPOSITORY_URL."
remove repo
}
if (url.startsWith('https://jcenter.bintray.com/')) {
project.logger.lifecycle "Repository `${repo.url} deleted."
remove repo
}
if (url.startsWith('https://dl.google.com/dl/android/maven2/')) {
project.logger.lifecycle "Repository `${repo.url} deleted."
remove repo
}
if (url.contains('plugins.gradle.org/m2')) {
project.logger.lifecycle "Repository `${repo.url} deleted."
remove repo
}
}
}
maven { url NJU_REPOSITORY_URL }
mavenLocal()
}
}
"@ | Set-Content -Path "$env:USERPROFILE\.gradle\init.gradle"
# Test Gradle
gradle --version

配置 Go 开发环境

1
2
3
4
5
6
scoop install go
# Use Goproxy.cn
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct
# Test Go
go version

配置 Rust 开发环境

由于不安装 MSVC,这里使用 GCC 版的 Rust。

请先按照上文配置 C/C++ 开发环境。

方法一:使用 Rustup 安装

官方建议的方式。但需要注意 Rustup 能自己管理版本,rustup update 会把自己升级,所以请先使用 Scoop 更新 Rustup。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# Set Rustup mirror
$env:RUSTUP_UPDATE_ROOT = "https://mirrors.cernet.edu.cn/rustup/rustup"
$env:RUSTUP_DIST_SERVER = "https://mirrors.cernet.edu.cn/rustup"
[Environment]::SetEnvironmentVariable("RUSTUP_UPDATE_ROOT", "https://mirrors.cernet.edu.cn/rustup/rustup", "User")
[Environment]::SetEnvironmentVariable("RUSTUP_DIST_SERVER", "https://mirrors.cernet.edu.cn/rustup", "User")

# Install Rustup
scoop install rustup-gnu

# Test Rust
rustc --version
cargo --version
cargo new --bin rust-test
cd rust-test
cargo build
cargo run

方法二:使用 Scoop 安装

1
scoop install rust-gnu

方法三:使用 MSYS2 安装

请先按照上文配置 C/C++ 开发 MSYS2 环境。

1
ucrt64 -c "pacman --noconfirm -S mingw-w64-ucrt-x86_64-rust"

配置 Ruby 开发环境

请先按照上文配置 C/C++ 开发 MSYS2 环境。

1
2
3
scoop install ruby
# Install MSYS2 and MINGW development toolchain
ridk install 3

配置 WSL2 + Docker 开发环境

如果您想使用 VMware / VirtualBox 等虚拟机,请不要使用此方案,此方案会启用 Hyper-V,CPU 硬件虚拟化指令被 Hyper-V 独占,会导致第三方虚拟机运行卡顿。

以下命令需要使用管理员权限执行,可以按 Win + X 打开 终端管理员。

1
2
3
4
5
6
# Install WSL2
scoop install sdoog/wsl2
# Install Ubuntu (Optional)
scoop install sdoog/wsl-ubuntu
# Install docker-desktop
scoop install sdoog/docker-desktop

安装完成后重启电脑即可使用 Docker Desktop 客户端。