温馨提示×

linux rust配置需要啥环境

小樊
39
2026-10-12 21:34:37
栏目: 编程语言

在 Linux 上配置 Rust 开发环境,一般只需要几个基础步骤和依赖。下面按「最小可用」和「推荐完整」来说明。


一、基础系统依赖(必须)

Rust 编译需要 C 工具链(用于链接等):

Debian / Ubuntu / Linux Mint

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

CentOS / Rocky / Alma

sudo dnf groupinstall -y "Development Tools"
sudo dnf install -y curl git

Arch Linux

sudo pacman -S base-devel curl git

build-essential / Development Tools 包含 gcc、make 等


二、安装 Rust(官方推荐方式)

使用 rustup(Rust 官方版本管理器):

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

安装完成后:

source $HOME/.cargo/env

或重新打开终端。

验证:

rustc --version
cargo --version

三、常用组件(推荐)

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

四、可选但常见的环境

1. 交叉编译(例如编译到 Windows / ARM)

rustup target add x86_64-pc-windows-gnu

2. 系统库依赖(视项目而定)

常见示例:

sudo apt install -y libssl-dev pkg-config

常见于:

  • 网络(reqwest、openssl)
  • GUI(gtk、qt)
  • 数据库(sqlite、postgres)

五、编辑器 / IDE(推荐)

VS Code(最常见)

code

安装扩展:

  • Rust Analyzer(官方推荐)
  • Better TOML

或命令行

  • vim + rust.vim
  • neovim + rust-tools

六、最小验证示例

cargo new hello
cd hello
cargo run

看到 Hello, world! 就说明环境 OK 了。


如果你告诉我:

  • 用的 哪个 Linux 发行版
  • 是 学习 / 后端 / 嵌入式 / GUI / WASM

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

0 踩