Windows 中安装 Rust
拉取 Rust 安装脚本:
powershell
Invoke-WebRequest -Uri "https://win.rustup.rs" -OutFile "rustup-init.exe"运行安装程序,会弹出命令行向导,无特殊情况直接 enter:
powershell
.\rustup-init.exe安装完成后,关闭当前 PowerShell 并重新打开,或者手动刷新环境变量:
powershell
$env:Path += ";$env:USERPROFILE\.cargo\bin"然后运行指令检查 rustc 和 cargo 版本,前者是官方编译器,后者是管理工具:
powershell
rustc --version
# rustc 1.96.0 (ac68faa20 2026-05-25)
cargo --version
# cargo 1.96.0 (30a34c682 2026-05-25)然后编写 HelloWorld 程序,确认能跑通即可:
rust
fn main() {
println!("Hello World");
}
保存退出,编译运行即可:
powershell
rustc main.rs