“Debian 上 Rust 报错”可能有很多种情况,我先给你最常见的几类问题 + 对应修复办法。如果你能贴出具体报错内容,我可以更精准地帮你。
Debian 自带的 rustc 通常版本很老,容易出问题。
cargo build 报错rustc version too old不要用 apt 的 rust,改用官方 rustup
# 卸载 apt 版本
sudo apt remove rustc cargo
# 安装 rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# 重新加载环境
source $HOME/.cargo/env
验证:
rustc --version
cargo --version
很多 crate 需要 C 库。
failed to run custom build commandcould not find openssllibssl not foundsudo apt update
sudo apt install -y \
build-essential \
pkg-config \
libssl-dev \
ca-certificates \
curl \
git
如果是图形 / 音频 / 数据库相关,还可能需要:
sudo apt install -y libclang-dev clang
升级 Rust 工具链:
rustup update
rustup default stable
或指定新版本:
rustup install 1.78
rustup default 1.78
cargo: command not found确保 ~/.cargo/bin 在 PATH:
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
(zsh 用户改 ~/.zshrc)
| 错误 | 原因 | 修复 |
|---|---|---|
error: linker cc not found |
没装 gcc | sudo apt install build-essential |
openssl-sys build failed |
缺 libssl | sudo apt install libssl-dev pkg-config |
cannot find -lxxx |
缺系统库 | apt search libxxx-dev |
permission denied |
用 root 混用 cargo | 不要用 sudo 跑 cargo |
你可以直接把报错原文贴出来(哪怕一部分),例如:
cargo --versioncat /etc/os-release)我可以根据具体错误一步一步帮你修。