温馨提示×

Debian配置Rust卡住怎么办

小樊
65
2026-10-22 18:04:52
栏目: 编程语言

在 Debian 上配置(安装/编译/运行)Rust 时“卡住”很常见,通常并不是 Rust 本身死掉了,而是网络、源、依赖或系统资源问题。下面按「最常见 → 最有用」的顺序给你排查思路。


一、先看卡在哪一步(很重要)

1️⃣ 卡在 curl https://sh.rustup.rs | sh

通常是 网络问题(访问 rustup / static.rust-lang.org 慢或被墙)

✅ 解决:

# 使用国内镜像
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

或中科大镜像:

export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

2️⃣ 卡在 cargo build(一直在 Downloading / Compiling)

这是最常见情况

✅ 原因 1:crates.io 访问慢

# 配置国内 crates 镜像
mkdir -p ~/.cargo
cat >> ~/.cargo/config.toml <<EOF
[source.crates-io]
replace-with = "rsproxy"

[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
EOF

中科大:

[source.crates-io]
replace-with = "ustc"

[source.ustc]
registry = "sparse+https://mirrors.ustc.edu.cn/crates.io-index/"

注意:Debian + 新版 cargo 推荐用 sparse 协议,速度明显更快


✅ 原因 2:依赖太多 / 机器性能差

  • 老机器、低内存(< 2G)编译会“假死”
  • 风扇不转、CPU 100% 但没输出

✅ 解决:

cargo build -j 1

或限制内存:

CARGO_BUILD_JOBS=1 cargo build

3️⃣ 卡在 sudo apt install rustc

Debian 自带 Rust 非常旧,不推荐

✅ 建议:

sudo apt remove rustc cargo
curl https://sh.rustup.rs -sSf | sh

二、通用排错命令(必会)

看 cargo 在干嘛

cargo build -v

看是否只是慢

top
# 或
htop

如果 rustc / cargo 占 CPU,说明没卡,只是慢


三、Debian 特别注意事项

1️⃣ 必须装的依赖

sudo apt update
sudo apt install -y build-essential curl gcc libssl-dev pkg-config

缺少这些会编译时卡死或报错


2️⃣ 低版本 Debian(如 10)问题

  • glibc 太旧
  • Rust 新版可能不兼容

✅ 建议:

  • Debian 11+ 最佳
  • 或安装旧 Rust:
rustup install 1.70.0

四、快速自检清单 ✅

  • [ ] 是否用了国内镜像
  • [ ] 是否 cargo build -j 1
  • [ ] 是否安装 build-essential
  • [ ] 是否在 top 中看到 rustc 在跑
  • [ ] 是否 Debian 自带旧 Rust

五、如果你愿意,我可以进一步帮你

你可以直接贴:

  1. 卡住时的完整命令
  2. 最后几行输出
  3. Debian 版本(cat /etc/os-release)
  4. 是否在容器 / VPS / 树莓派

我可以精准告诉你是哪一步、为什么、怎么解决。

0 踩