温馨提示×

Debian配置Rust要哪些依赖

小樊
50
2026-09-05 07:16:59
栏目: 编程语言

在 Debian 上配置 Rust 开发环境,通常需要以下系统依赖可选组件,具体取决于你要做什么(基础编译、系统编程、GUI、Web 等)。


一、基础依赖(必须)

先更新系统:

sudo apt update
sudo apt upgrade

安装 Rust 编译所需的基础工具链:

sudo apt install -y \
  build-essential \
  gcc \
  make \
  pkg-config \
  curl \
  git

说明:

  • build-essential:C/C++ 编译环境(Rust 很多时候需要链接 C 库)
  • pkg-config:用于查找系统库
  • curl:安装 rustup 用
  • git:很多 Rust 项目用 git 管理

二、安装 Rust(推荐方式)

官方推荐用 rustup

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

然后:

source "$HOME/.cargo/env"

验证:

rustc --version
cargo --version

三、常用可选依赖(按用途)

1️⃣ 使用 OpenSSL(如 reqwest、tokio、hyper)

sudo apt install -y libssl-dev

2️⃣ 数据库相关

  • PostgreSQL:
    sudo apt install -y libpq-dev postgresql
    
  • MySQL / MariaDB:
    sudo apt install -y libmysqlclient-dev
    
  • SQLite:
    sudo apt install -y libsqlite3-dev
    

3️⃣ GUI / 图形界面(如 gtkwinitegui

sudo apt install -y \
  libgtk-3-dev \
  libx11-dev \
  libxrandr-dev \
  libxinerama-dev \
  libxcursor-dev \
  libxi-dev

4️⃣ 音频 / 多媒体

sudo apt install -y \
  libasound2-dev \
  libpulse-dev

5️⃣ 交叉编译(如编译到 ARM / Windows)

sudo apt install -y gcc-arm-linux-gnueabihf

然后通过 rustup 添加 target:

rustup target add armv7-unknown-linux-gnueabihf

四、编辑器 / IDE 支持(推荐)

VS Code

sudo apt install -y code

插件:

  • rust-analyzer
  • CodeLLDB

或命令行工具

rustup component add rustfmt clippy

五、最小可用示例(仅编译 Rust)

如果你只写纯 Rust 程序

sudo apt install -y curl git
curl https://sh.rustup.rs -sSf | sh

✅ 不需要 C 库,也能跑。


如果你告诉我:

  • Debian 版本(11 / 12)
  • 用途(Web / 系统 / 游戏 / 嵌入式)
  • 是否需要交叉编译

我可以给你一份精确依赖清单

0