温馨提示×

Debian里Rust怎么配的

小樊
39
2026-09-29 07:59:33
栏目: 编程语言

在 Debian 上配置 Rust 一般有几种常见方式,下面按推荐程度给你讲清楚。


一、推荐方式:用官方 rustup(最常用)

1. 安装依赖

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

2. 安装 Rust(rustup)

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

二、更新与卸载

更新 Rust

rustup update

卸载 Rust

rustup self uninstall

三、Debian 自带方式(不推荐)

Debian 仓库里也有 Rust:

sudo apt install rustc cargo

⚠️ 缺点:

  • 版本很旧
  • 不适合实际开发
  • 很多 crate 用不了

只适合临时用用


四、常用配置(开发向)

1. 设置国内镜像(可选,国内推荐)

编辑 ~/.cargo/config.toml:

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

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

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

2. 安装常用组件

rustup component add rustfmt clippy

3. 安装 WASM 目标(可选)

rustup target add wasm32-unknown-unknown

五、简单测试

cargo new hello
cd hello
cargo run

如果你告诉我:

  • 是 Debian 几(11 / 12 / 13)
  • 用途(服务器 / 桌面 / 嵌入式 / WASM)

我可以给你更精确的配置方案。

0 踩