在 Debian 上配置 Rust 环境时,有几个常见坑点和推荐做法,下面按“注意事项 + 建议”来说明。
不要直接用 apt 安装 rustc / cargo(除非你只做简单测试):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
或:
wget https://sh.rustup.rs -O rustup.sh
sh rustup.sh
然后:
source "$HOME/.cargo/env"
✅ 优点:
⚠️ apt 中的 Rust 通常版本偏旧,且不易升级。
Rust 编译时需要一些系统库:
sudo apt update
sudo apt install -y \
build-essential \
pkg-config \
libssl-dev \
curl \
git
如果是:
libx11-dev、libxkbcommon-devlibpq-dev-dev 包rustup default stable
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
或使用清华:
replace-with = "tuna"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index.git"
如果遇到:
error: linker `cc` not found
✅ 安装:
sudo apt install gcc
cargo build 很慢原因:
解决:
cargo build --release 仅用于最终产物could not find openssl
解决:
sudo apt install libssl-dev pkg-config
或在 Cargo.toml 使用:
openssl = { version = "0.10", features = ["vendored"] }
rustup install nightly
rustup toolchain list
rustup target add aarch64-unknown-linux-gnu
sudo apt install gcc-aarch64-linux-gnu
安装:
rustup update
cargo install cargo-update
cargo install-update -a
✅ 用 rustup
✅ 装 build-essential + libssl-dev
✅ 国内一定换 cargo 源
❌ 别用 apt 的 rust 做开发
如果你告诉我:
我可以给你一套更精确的配置方案。