温馨提示×

怎样快配Debian的Rust

小樊
46
2026-09-29 08:01:33
栏目: 编程语言

在 Debian 上“快速配好 Rust”,最推荐、最省事的方式是用官方 rustup 安装,而不是用 apt(apt 里的 rust 版本通常偏旧)。

下面给你几种方式,按“最快 → 最稳”排列。


一、最快方式(推荐):rustup 一键安装

1. 安装依赖

sudo apt update
sudo apt install -y curl build-essential

2. 安装 Rust

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

按提示选 1) Proceed with standard installation

3. 立即生效

source "$HOME/.cargo/env"

或重新打开终端。

4. 验证

rustc --version
cargo --version

✅ 完成,通常 1–2 分钟。


二、换国内镜像(更快,尤其教育网/国内服务器)

安装前先设置环境变量:

export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup

然后再跑:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

Cargo 镜像(写入 ~/.cargo/config.toml):

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

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

三、不推荐但可用:apt 安装(慢且旧)

sudo apt install -y rustc cargo

⚠️ 版本通常落后,很多 crate 不支持。


四、常见补充(按需)

常用组件

rustup component add rustfmt clippy

交叉编译(示例:Windows)

rustup target add x86_64-pc-windows-gnu

更新 Rust

rustup update

一句话总结

Debian 上最快配 Rust = apt 装依赖 + rustup 官方脚本 +(国内用 rsproxy 镜像)

如果你告诉我:

  • 是 桌面还是服务器
  • 是否 国内网络
  • 是否要 交叉编译 / WASM / 嵌入式

我可以给你一份“最合适你环境”的精准配置。

0 踩