参考文档
- The Rust Programming Language https://doc.rust-lang.org/stable/book/ch01-01-installation.html
- Rust 安装官方指导: https://rust-lang.github.io/rustup/installation/index.html
- rustup 安装包下载地址: https://forge.rust-lang.org/infra/other-installation-methods.html
1 Window 11
1.1 安装 VisualStudio C++ 实现
(1)安装 Visual Studio 提供的 C++ 库,参考 https://rust-lang.github.io/rustup/installation/windows-msvc.html#manual-install
1.2 下载 rustup-init.exe
点击 https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe
下载 rustup-init.exe
rustupinstallsrustc,cargo,rustupand other standard tools to Cargo’sbindirectory.
1.3 配置RUSTUP_HOME 和 CARGO_HOME设置安装目录
set RUSTUP_HOME=C:\work\soft\rust\rustup
set CARGO_HOME=C:\work\soft\rust\cargo
- RUSTUP_HOME - rustup 根目录,用于保存安装的工具链(rustc、配置选项)
- CARGO_HOME - 包含缓存从 cargo 拉取的文件
1.4 执行 rustup-init.exe 安装
(1)执行 rustup-init.exe
This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.
Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:
C:\work\soft\rust\rustup
This can be modified with the RUSTUP_HOME environment variable.
The Cargo home directory is located at:
C:\work\soft\rust\cargo
This can be modified with the CARGO_HOME environment variable.
The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:
C:\work\soft\rust\cargo\bin
This path will then be added to your PATH environment variable by
modifying the PATH registry key at HKEY_CURRENT_USER\Environment.
You can uninstall at any time with rustup self uninstall and
these changes will be reverted.
Current installation options:
default host triple: x86_64-pc-windows-msvc
default toolchain: stable (default)
profile: default
modify PATH variable: yes
1) Proceed with standard installation (default - just press enter)
2) Customize installation
3) Cancel installation
(2)选择 2 回车后进行安装配置:
>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]
Default toolchain? (stable/beta/nightly/none) [stable]
Profile (which tools and data to install)? (minimal/default/complete) [default]
Modify PATH variable? (Y/n)
Y
(3)选择 1 进行安装(下载相关工具包速度有点慢):
Current installation options:
default host triple: x86_64-pc-windows-msvc
default toolchain: stable
profile: default
modify PATH variable: yes
1) Proceed with selected options (default - just press enter)
2) Customize installation
3) Cancel installation
>1
控制台显示正在下载安装包:
info: profile set to 'default'
info: setting default host triple to x86_64-pc-windows-msvc
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
1012.7 KiB / 1012.7 KiB (100 %) 21.9 KiB/s in 43s
info: latest update on 2025-12-11, rust version 1.92.0 (ded5c06cf 2025-12-08)
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
20.5 MiB / 20.5 MiB (100 %) 26.7 KiB/s in 17m 49s
info: downloading component 'rust-std'
20.8 MiB / 20.8 MiB (100 %) 31.6 KiB/s in 18m 8s
info: downloading component 'rustc'
68.6 MiB / 68.6 MiB (100 %) 1.9 MiB/s in 17m 36s
info: downloading component 'rustfmt'
2.5 MiB / 2.5 MiB (100 %) 262.4 KiB/s in 30s
info: installing component 'cargo'
9.4 MiB / 9.4 MiB (100 %) 7.5 MiB/s in 1s
info: installing component 'clippy'
info: installing component 'rust-docs'
20.5 MiB / 20.5 MiB (100 %) 2.6 MiB/s in 12s
info: installing component 'rust-std'
20.8 MiB / 20.8 MiB (100 %) 9.0 MiB/s in 2s
info: installing component 'rustc'
68.6 MiB / 68.6 MiB (100 %) 10.3 MiB/s in 7s
info: installing component 'rustfmt'
info: default toolchain set to 'stable-x86_64-pc-windows-msvc'
stable-x86_64-pc-windows-msvc installed - rustc 1.92.0 (ded5c06cf 2025-12-08)
Rust is installed now. Great!
To get started you may need to restart your current shell.
This would reload its PATH environment variable to include
Cargo's bin directory (C:\work\soft\rust\cargo\bin).
Press the Enter key to continue.
1.5 安装 RustRover
-
用浏览器打开 https://www.jetbrains.com/rust/download/?section=windows 下载 RustRover,
-
安装到本地即可。
-
使用邮箱注册一个 JetBrains 账号,然后选择非商用用途,这样就可以免费使用 RustRover 进行 rust 学习和开发了。
1.6 RustRover 配置 cargo 和 rustup
【Settings】 - 【Rust】-【Toolchain Location】 选择 rust 工具链安装路径(%CARGO_HOME%\bin),这里是 C:\work\soft\rust\cargo\bin。
通常使用 rust-init.exe 安装完成后,RustRover 会自动检测到,如果没有检测到,需要通过上面进行配置。
1.7 使用 RustRover 创建 rust 工程
- 点击菜单栏【File】-【New】-【Project...】 弹出新建 Rust 项目窗口。
- 在弹出窗口内的【Project Templates】区域选择 Binary (application) 后,点击【Create】
创建的工程结构:
rust-demo
|
| -- src\
| -- main.rs
| -- Cargo.lock
| -- Cargo.toml
打开 main.rs ,
fn main() {
println!("Hello, world!");
}
点击右键-【Run 'Run rust-demo'】,控制台输出
C:/work/soft/rust/cargo/bin/cargo.exe run --color=always --package rust-demo --bin rust-demo --profile dev
Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.02s
Running `target\debug\rust-demo.exe`
Hello, world!
到此,rust 开发环境搭建成功。可以开始 rust 开发了。
本文来自博客园,作者:不安分的黑娃,转载请注明原文链接:https://www.cnblogs.com/lihw-study/articles/19403618
浙公网安备 33010602011771号