在 Windows 上安装 Rust

下载 rust-init ,下载完成后双击 rustup-init.exe 打开, 输入 y 后会看到如下页面:

Current installation options:

   default host triple: x86_64-pc-windows-msvc
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

可以看到默认安装的是 x86_64-pc-windows-msvc, 这个 host triple 需要安装 Visual Studio 中的 C++ build tools,十分占用空间,否则编译时会报错如下:

error: linker `link.exe` not found
  |
  = note: 系统找不到指定的文件。 (os error 2)
 
note: the msvc targets depend on the msvc linker but `link.exe` was not found
 
note: please ensure that VS 2013, VS 2015, VS 2017 or VS 2019 was installed with the Visual C++ option

我们可以将 x86_64-pc-windows-msvc 替换为 x86_64-pc-windows-gnu,方便省事,不用额外安装其他工具包。
输入 2 自定义安装,剩余步骤如下所示:

I'm going to ask you the value of each of these installation options.
You may simply press the Enter key to leave unchanged.

Default host triple? [x86_64-pc-windows-msvc]
x86_64-pc-windows-gnu

Default toolchain? (stable/beta/nightly/none) [stable]
(默认回车即可)

Profile (which tools and data to install)? (minimal/default/complete) [default]
(默认回车即可)

Modify PATH variable? (Y/n)
y

接下来可见页面显示如下。

Current installation options:


   default host triple: x86_64-pc-windows-gnu
     default toolchain: stable
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation

输入 1 安装。安装完成后使用 rust --version检查是否安装成功。

D:\>rustc --version
rustc 1.59.0 (9d1b2106e 2022-02-23)

已经安装了 x86_64-pc-windows-msvc 使用如下命名卸载即可
rustup toolchain uninstall x86_64-pc-windows-msvc

你可能感兴趣的:(在 Windows 上安装 Rust)