下面给你一份在 Linux 上安装 Rust 开发环境的完整指南,包含最常见、最推荐的方式,以及验证和常见问题处理。
rustup(官方方式)sudo apt update
sudo apt install -y curl build-essential
如果是 CentOS / Rocky / Alma:
sudo dnf install -y curl gcc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装过程中会让你选择:
1) Proceed with standard installation(推荐)安装完成后:
source "$HOME/.cargo/env"
或直接重启终端。
rustc --version
cargo --version
输出类似:
rustc 1.80.0 (xxxxx)
cargo 1.80.0 (xxxxx)
rustup update
rustup component add rustfmt clippy
rustfmt:代码格式化clippy:代码静态检查cargo new hello_rust
cd hello_rust
cargo run
输出:
Hello, world!
rustup install stable
rustup default stable
或安装 nightly:
rustup install nightly
rustup default nightly
可使用国内镜像:
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
然后再执行安装脚本。
rustup self uninstall
✅ Ubuntu / Debian
✅ CentOS / Rocky / Alma
✅ Arch
✅ WSL(Windows Subsystem for Linux)
如果你告诉我:
我可以给你更定制的安装方案。