温馨提示×

Rust在Debian怎么设置

小樊
40
2026-09-29 07:49:33
栏目: 编程语言

你的问题比较简短,“Rust在Debian怎么设置”一般可以理解为 如何在 Debian 系统上安装并配置 Rust 开发环境。下面给你一套常见、推荐的做法。


一、在 Debian 上安装 Rust(推荐方式)

1. 更新系统

sudo apt update
sudo apt upgrade -y

2. 安装必要依赖

sudo apt install -y curl build-essential gcc make

3. 使用官方脚本安装 Rust(rustup)

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

安装过程中会让你选择:

  • 默认(推荐):1) Proceed with installation (default)
  • 直接回车即可

4. 使 Rust 环境变量生效

source "$HOME/.cargo/env"

或者重新打开终端。

5. 验证安装

rustc --version
cargo --version

二、更新与卸载 Rust

更新 Rust

rustup update

卸载 Rust

rustup self uninstall

三、使用 apt 安装(不推荐但可用)

Debian 仓库中也有 Rust,但版本通常较旧:

sudo apt install -y rustc cargo

⚠️ 不建议用于实际开发,版本落后。


四、基本开发环境配置(可选但常用)

1. 安装常用组件

rustup component add rustfmt clippy
  • rustfmt:代码格式化
  • clippy:代码检查

2. 创建第一个项目

cargo new hello
cd hello
cargo run

五、常见问题

1. 网络问题(国内用户)

可设置镜像(如 ustc / tuna):

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

然后再运行安装脚本。

2. Debian 缺少 C 编译器

Rust 编译某些 crate 需要 gcc:

sudo apt install -y gcc

如果你指的是 Rust 的某个具体用途(比如 Web 服务、嵌入式、WASM、系统编程),可以告诉我,我可以给你更针对性的 Debian 配置方案。

0 踩