在 Debian 上更新 Rust 版本,常见有 三种方式,推荐第一种(官方工具链)。
rustup(推荐 ✅)如果你当初是通过 rustup 安装的 Rust:
# 更新 rustup 自身
rustup self update
# 更新到最新稳定版
rustup update stable
# 查看当前版本
rustc --version
cargo --version
如果你想升级到特定版本:
rustup update 1.78.0
如果你还没装 rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
Debian 仓库里的 Rust 通常很旧:
sudo apt update
sudo apt install rustc cargo
更新:
sudo apt upgrade rustc cargo
⚠️ 版本通常落后官方很多,不建议用于开发。
从官网下载预编译包:
https://www.rust-lang.org/tools/install
或使用 cargo + rustup 管理多版本。
which rustc
如果指向 /usr/bin/rustc,说明是 apt 装的;
如果指向 ~/.cargo/bin/rustc,是 rustup 装的。
确保 ~/.cargo/bin 在 PATH 最前面:
source ~/.cargo/env
或检查 .bashrc / .zshrc。
如果你告诉我:
我可以给你更精确的命令。