在 Debian 上配置/使用 Rust 时报错,原因非常多,下面按最常见情况给你一个排查清单和对应解决办法。你可以对照看是哪一种。
Debian 稳定版里的 rustc / cargo 往往非常老,很多项目直接报错:
error: failed to parse manifest
error: unsupported Rust version
rustc --version
# 1.48 / 1.63 这种很老的版本
不要用 apt 的 rust,改用官方工具链:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source ~/.cargo/env
然后:
rustc --version
cargo --version
Rust 有些 crate 需要 cc / make / pkg-config
error: failed to run custom build command for `openssl-sys`
cc not found
sudo apt update
sudo apt install -y build-essential pkg-config libssl-dev
常用补丁包:
sudo apt install -y cmake clang
国内机器很常见:
error: failed to download replaced source
timed out
编辑或新建:
~/.cargo/config.toml
内容:
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
或使用清华:
[source.crates-io]
replace-with = "tuna"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index.git"
某些预编译 binary crate 会报错:
version `GLIBC_2.33' not found
cargo build --offline
或在 Cargo.toml 中避免预编译 crate
如果你用 root 跑 rustup,再切普通用户会炸。
sudo chown -R $USER:$USER ~/.cargo ~/.rustup
常见错误:
std::env::var 失败no such file or directoryecho $PATH
which cargo
确保:
export PATH="$HOME/.cargo/bin:$PATH"
如果你能贴 完整报错信息(最好 10–20 行),我可以直接告诉你:
✅ 是工具链问题
✅ 是系统依赖问题
✅ 还是代码本身问题
Debian 上 90% 的 Rust 报错,都是 apt 的旧 Rust + 缺 build-essential + 网络问题
如果你愿意,直接把报错复制过来,我帮你精确定位。