在 Ubuntu 上配置 Rust 开发环境,一般步骤如下:
使用官方脚本(最常用)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装过程中会让你选择:
1) Proceed with installation (default)安装完成后,加载环境变量:
source "$HOME/.cargo/env"
或重新打开终端。
验证是否安装成功:
rustc --version
cargo --version
更新 Rust:
rustup update
卸载 Rust:
rustup self uninstall
rustup component add rustfmt # 格式化工具
rustup component add clippy # lint 工具
sudo apt update
sudo apt install -y build-essential pkg-config libssl-dev
如果是做 系统/嵌入式/GUI:
sudo apt install -y cmake llvm clang
编辑 ~/.cargo/config.toml:
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
或清华源:
[source.crates-io]
replace-with = "tuna"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
cargo new hello_rust
cd hello_rust
cargo run
如果你是要:
可以告诉我你的具体用途,我可以给你更针对性的配置方案。