下面按从零开始的思路,给你一份在 Debian 上准备 Rust 开发环境 的实用指南,涵盖安装、工具链、常用组件和排错。
sudo apt update
sudo apt upgrade -y
建议安装基础编译工具(Rust 某些 crate 需要 C 编译器):
sudo apt install -y build-essential pkg-config libssl-dev curl git
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
按提示选择:
1) Proceed with standard installation安装完成后:
source "$HOME/.cargo/env"
或重新打开终端。
验证:
rustc --version
cargo --version
编辑 ~/.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"
或使用 ustc / tuna 镜像也可。
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
可写入 ~/.bashrc 或 ~/.zshrc。
rustup component add rustfmt clippy
rustfmt:代码格式化clippy:代码静态检查可选:
cargo install cargo-edit
cargo install cargo-watch
cargo new hello_rust
cd hello_rust
cargo run
确保安装:
sudo apt install libssl-dev pkg-config
sudo apt install musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-musl
rustup toolchain install stable
rustup toolchain install nightly
rustup default stable
cargoapt install build-essential curl git libssl-dev pkg-config
curl https://sh.rustup.rs -sSf | sh
rustup component add rustfmt clippy
如果你告诉我:
我可以给你更精确的环境方案。