在 Windows 上安装 Rust

Step1:安装 Windows terminal

打开 Windows 应用商店,搜索 terminal 并选择第一个搜索结果,然后点击下载即可:

Step2:安装 Chocolatey

以管理员的身份打开 Windows terminal,然后输入下面的命令:

1
Set-ExecutionPolicy Bypass -Scope Process -Force; [System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072; iex ((New-Object System.Net.WebClient).DownloadString('https://community.chocolatey.org/install.ps1'))

安装完成后输入 choco -v 检查版本,如果输出了具体的版本号则表示安装成功。

Step3:安装 mingw

以管理员的身份打开 Windows terminal,然后输入下面的命令:

1
choco install mingw -y

安装完成后输入 gcc --versiong++ --version,如果出现如下的输出则表示安装成功:

1
2
3
4
5
6
7
8
9
10
11
PS C:\Users\25864> gcc --version
gcc.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

PS C:\Users\25864> g++ --version
g++.exe (MinGW-W64 x86_64-posix-seh, built by Brecht Sanders) 11.2.0
Copyright (C) 2021 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

Step4:安装 Rust

打开 Rust 的官网:https://www.rust-lang.org/zh-CN/tools/install ,点击下载 RUSTUP-INIT.EXE(64位):

打开刚刚下载完的可执行文件:

选择 3) Don’t install the prerequisites:

选择 2) Customize installation:

接下来会输入四个可选项:

然后输入 1 即可开始安装。

Step5:验证是否安装成功

打开 Windows terminal,输入 rustc --version --verbose,如果出现如下输出则表示安装成功:

1
2
3
4
5
6
7
8
PS C:\Users\25864> rustc --version --verbose
rustc 1.65.0-nightly (95a992a68 2022-09-16)
binary: rustc
commit-hash: 95a992a68694d8bf3959bd2c0ac27ce9e9208b59
commit-date: 2022-09-16
host: x86_64-pc-windows-gnu
release: 1.65.0-nightly
LLVM version: 15.0.0

最后通过安装一个 Rust 命令行工具来查看 Cargo 是否正常工作。在 Windows terminal 中输入 cargo install onefetch,如果出现如下输出则表示 Cargo 能够正常工作:

1
2
3
4
5
6
7
8
9
10
11
 ......
......
Compiling ansi_term v0.12.1
Compiling owo-colors v3.5.0
Compiling zstd v0.11.2+zstd.1.5.2
Compiling askalono v0.4.6
Compiling git2 v0.14.4
Compiling onefetch v2.12.0
Finished release [optimized] target(s) in 5m 59s
Installing C:\Users\25864\.cargo\bin\onefetch.exe
Installed package `onefetch v2.12.0` (executable `onefetch.exe`)

参考


在 Windows 上安装 Rust
https://night-cruise.github.io/2022/09/17/rust-install-windows/
作者
Night Cruise
发布于
2022年9月17日
许可协议