在 Debian 上配置(安装/编译/运行)Rust 时“卡住”很常见,通常并不是 Rust 本身死掉了,而是网络、源、依赖或系统资源问题。下面按「最常见 → 最有用」的顺序给你排查思路。
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
cargo build(一直在 Downloading / Compiling)这是最常见情况
# 配置国内 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协议,速度明显更快
✅ 解决:
cargo build -j 1
或限制内存:
CARGO_BUILD_JOBS=1 cargo build
sudo apt install rustcDebian 自带 Rust 非常旧,不推荐
✅ 建议:
sudo apt remove rustc cargo
curl https://sh.rustup.rs -sSf | sh
cargo build -v
top
# 或
htop
如果 rustc / cargo 占 CPU,说明没卡,只是慢
sudo apt update
sudo apt install -y build-essential curl gcc libssl-dev pkg-config
缺少这些会编译时卡死或报错
✅ 建议:
rustup install 1.70.0
cargo build -j 1build-essentialtop 中看到 rustc 在跑你可以直接贴:
cat /etc/os-release)我可以精准告诉你是哪一步、为什么、怎么解决。