“Debian 上 Rust 报错”这个范围比较大,不同场景报错原因不一样。我先给你最常见的几类 Debian Rust 报错及解决办法,你可以对号入座;如果还不行,把完整报错贴出来我帮你精确定位。
Debian 稳定版自带的 Rust 经常很旧,容易编译失败。
建议方案:用官方 rustup 安装
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
然后卸载 apt 版本(可选):
sudo apt remove rustc cargo
报错类似:
failed to run custom build command for `xxx`
cc not found
解决:
sudo apt update
sudo apt install -y build-essential
例如 openssl-sys 报错:
Failed to find OpenSSL development headers
解决:
sudo apt install -y pkg-config libssl-dev
其他常见依赖:
sudo apt install -y libclang-dev clang
报错类似:
/lib/x86_64-linux-gnu/libc.so.6: version `GLIBC_2.33' not found
原因:Debian 稳定版 glibc 太旧。
解决:
# Cargo.toml
[profile.release]
static = true
报错:
Permission denied: /root/.cargo
不要 sudo cargo
解决:
sudo chown -R $USER:$USER $HOME/.cargo
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export CARGO_REGISTRIIES_CRATES_IO_PROTOCOL=sparse
或配置 ~/.cargo/config.toml:
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
sudo apt update && sudo apt upgrade
sudo apt install build-essential pkg-config libssl-dev
请贴出:
cat /etc/os-release)我可以直接给你针对你机器的解决命令。