在 Ubuntu 上快速配置 Rust 开发环境,最推荐、最省事的方式是使用官方工具 rustup。下面给你一套“最快可用”的步骤。
sudo apt update
sudo apt install -y curl build-essential 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
能看到版本号就说明成功了。
如果你在国内,建议配置镜像,否则下载很慢。
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
source ~/.bashrc
[source.crates-io]
replace-with = 'rsproxy'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
cargo new hello
cd hello
cargo run
输出 Hello, world! 即配置完成。
rustup update # 更新 Rust
rustup toolchain list # 查看工具链
cargo build # 编译
cargo run # 运行
cargo check # 快速检查
rustup component add rustfmt clippy
如果你是用于 嵌入式 / WASM / 服务器开发,或想用 VS Code,我也可以给你更针对性的配置方案。