Debian 上搭建 Rust 工具链
一 安装方式与选择
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustc --version
cargo --version
rustup --version
sudo apt update
sudo apt install rustc cargo
rustc --version
cargo --version
二 基础配置与常用组件
rustup default stable
rustup component add rustfmt clippy rust-src
rustup install nightly
rustup default nightly # 或切回稳定版:rustup default stable
rustup update # 更新已安装工具链
rustup target add x86_64-unknown-linux-musl
rustup target add aarch64-unknown-linux-gnu
cargo fmt --version
cargo clippy --version
以上命令覆盖日常开发所需的主流组件与多目标配置。
三 系统依赖与构建环境
sudo apt update
sudo apt install build-essential pkg-config libssl-dev git clang
# Debian 常见路径示例(按实际安装位置调整)
export PKG_CONFIG_PATH="/usr/lib/x86_64-linux-gnu/pkgconfig"
export OPENSSL_DIR="/usr"
sudo apt install musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --release --target x86_64-unknown-linux-musl
上述依赖与变量能覆盖大多数需要 C 编译器、pkg-config、OpenSSL 的 Rust 项目。
四 项目构建与 IDE 配置
cargo build # 开发构建
cargo build --release # 发布构建
cargo install --path . # 安装到 ~/.cargo/bin(适合命令行工具)