温馨提示×

linux rust配置怎样开始

小樊
43
2026-10-27 15:30:29
栏目: 编程语言

下面按从零开始的思路,给你一份 Linux 下 Rust 开发环境配置的实用指南。


一、安装 Rust(推荐方式)

1. 使用 rustup(官方推荐)

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

安装完成后,按提示执行:

source "$HOME/.cargo/env"

或重新打开终端。

2. 验证安装

rustc --version
cargo --version

看到版本号说明安装成功。


二、更新与管理工具链

rustup update
rustup show

常用组件:

rustup component add rustfmt   # 代码格式化
rustup component add clippy   # lint 工具

三、创建第一个 Rust 项目

cargo new hello_rust
cd hello_rust
cargo run

项目结构:

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

四、Linux 常见依赖(按需)

1. 编译依赖(很重要)

# Debian / Ubuntu
sudo apt install build-essential pkg-config libssl-dev

# Fedora
sudo dnf install gcc openssl-devel

# Arch
sudo pacman -S base-devel openssl

2. 常见库示例

  • 网络 / HTTP:openssl
  • GUI:libgtk-3-dev
  • 音频 / 多媒体:对应 -dev 包

五、编辑器 / IDE 推荐

VS Code(最常用)

code .

安装扩展:

  • rust-analyzer(必装)
  • Even Better TOML

或 NeoVim / Vim

  • rust-analyzer + LSP

六、国内镜像(可选,加速)

编辑 ~/.cargo/config.toml:

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

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

或:

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

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index"

七、学习路线建议

  1. 官方教程(强烈推荐)
rustup doc --book

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

  1. 练习
  • 小工具(文件处理、CLI)
  • 网络请求(reqwest)
  • 并发(tokio)

如果你愿意,可以告诉我:

  • 你用的 Linux 发行版
  • 想做 什么方向(系统 / Web / 网络 / 嵌入式)

我可以直接给你一套更精准的配置方案。

0 踩