在 Ubuntu 上配置 Rust 出错是很常见的问题,原因可能来自网络、权限、工具链缺失或环境变量。下面我按「常见错误 → 解决办法」的方式给你一个排错清单,你可以对照看看。
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
如果你之前用 apt install rustc 装过,建议卸载,避免冲突:
sudo apt remove rustc cargo
command not found: cargo / rustc原因:环境变量没加载
解决:
source $HOME/.cargo/env
或添加到 ~/.bashrc / ~/.zshrc:
export PATH="$HOME/.cargo/bin:$PATH"
然后:
source ~/.bashrc
典型报错:
network timeoutfailed to download解决:
# 使用国内镜像
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
linker cc not found报错示例:
error: linker `cc` not found
解决(安装编译工具):
sudo apt update
sudo apt install -y build-essential
sudo apt install -y ca-certificates
现象:
version 'GLIBC_2.XX' not found
解决:
rustup toolchain install 1.70.0
rustup default 1.70.0
不要用 sudo 装 Rust(rustup 设计如此)
错误示例:
sudo curl ... | sudo sh
✅ 正确:
curl ... | sh
rustc --version
cargo --version
你可以直接把完整报错截图或文字发给我,我帮你精确定位。
例如:
lsb_release -a)我可以一步一步带你修 ✅