温馨提示×

linux rust配置如何开始

小樊
44
2026-10-12 21:33:37
栏目: 编程语言

下面给你一个从零开始在 Linux 上配置 Rust 开发环境的简明流程,适合新手。


一、安装 Rust(推荐方式)

1. 安装 rustup(官方推荐)

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

安装过程中会让你选择:

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

2. 让环境变量生效

source $HOME/.cargo/env

或者重新打开终端。

3. 验证安装

rustc --version
cargo --version

看到版本号就说明成功了 ✅


二、更新与卸载

更新 Rust

rustup update

卸载 Rust

rustup self uninstall

三、创建第一个 Rust 项目

1. 用 Cargo 创建项目

cargo new hello_rust
cd hello_rust

目录结构:

hello_rust
├── Cargo.toml
└── src
    └── main.rs

2. 运行项目

cargo run

输出:

Hello, world!

四、常用开发工具(推荐)

1. 代码编辑器

推荐:

  • VS Code + 插件:
    • rust-analyzer(必装)
    • Better TOML

2. 安装常用组件

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

使用:

cargo fmt
cargo clippy

五、Linux 常见依赖(按需)

有些项目需要系统库:

Ubuntu / Debian

sudo apt install build-essential pkg-config libssl-dev

CentOS / Rocky / Alma

sudo dnf groupinstall "Development Tools"
sudo dnf install openssl-devel

六、学习资源(建议顺序)

  1. 官方教程(必看)
rustup doc --book

或在线:https://doc.rust-lang.org/book/

  1. 练习
  • https://exercism.org/tracks/rust
  • https://leetcode.com/

如果你告诉我:

  • 你用的是 哪个 Linux 发行版(Ubuntu / Arch / CentOS 等)
  • 想用 Rust 做什么(系统 / Web / 网络 / 嵌入式)

我可以给你更针对性的配置方案。

0 踩