温馨提示×

debian配置rust报错怎么解

小樊
37
2026-09-20 12:34:14
栏目: 编程语言

在 Debian 上配置 Rust 时常见的报错及解决办法如下,你可以对照看看是哪种情况。


一、用 apt 安装 Rust 报错

1. 找不到 rust / cargo 包

E: Unable to locate package rust

原因:Debian 仓库里叫 rustc 和 cargo,不是 rust

解决:

sudo apt update
sudo apt install rustc cargo

2. 版本太旧

Debian 稳定版的 Rust 通常很老,容易出兼容问题。

建议:不要直接用 apt,用官方方式安装。


二、用 rustup 安装报错(最常见)

1. 网络问题(curl 失败)

curl: (7) Failed to connect to sh.rustup.rs port 443

解决:

  • 检查网络 / 代理
  • 使用国内镜像:
export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup
curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh

2. 缺少依赖

报错类似:

error: failed to run custom build command

或

cc not found

解决(Debian 必备依赖):

sudo apt install -y build-essential pkg-config libssl-dev

如果是 GUI / 系统库相关:

sudo apt install -y libclang-dev clang

3. cargo 命令找不到

command not found: cargo

原因:环境变量没生效

解决:

source $HOME/.cargo/env

或加入 .bashrc:

echo 'source $HOME/.cargo/env' >> ~/.bashrc

三、编译项目时报错

1. error: linker cc not found

collect2: error: ld returned 1 exit status

解决:

sudo apt install build-essential

2. OpenSSL 相关错误

Could not find OpenSSL

解决:

sudo apt install libssl-dev pkg-config

四、推荐的标准安装方式(Debian)

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source $HOME/.cargo/env
rustc --version
cargo --version

如果你能贴出具体的报错信息(命令 + 完整错误),我可以直接帮你定位并给出精确解决方案。

0 踩