温馨提示×

新手如何搞debian rust配置

小樊
38
2026-09-17 08:54:42
栏目: 编程语言

下面按新手友好的顺序,教你从零在 Debian 上配置 Rust 开发环境,不绕弯。


一、更新系统(必做)

sudo apt update
sudo apt upgrade -y

二、安装基础依赖

Rust 编译需要这些:

sudo apt install -y build-essential curl git pkg-config libssl-dev

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

不要用 apt 装 rustc(版本旧)

用官方脚本:

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

安装时选:

1) Proceed with standard installation

四、让 Rust 命令生效

source "$HOME/.cargo/env"

(每次开新终端都要,或者重启终端)


五、验证安装

rustc --version
cargo --version

看到版本号就成功了 ✅


六、可选但推荐:配置国内镜像(快很多)

编辑 ~/.cargo/config.toml

mkdir -p ~/.cargo
nano ~/.cargo/config.toml

内容(清华源示例):

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

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

七、创建第一个 Rust 项目

cargo new hello
cd hello
cargo run

输出:

Hello, world!

八、常用命令速查

cargo build      # 编译
cargo run        # 编译并运行
cargo check      # 只检查错误(快)
cargo update     # 更新依赖

九、新手常见坑

command not found: cargo
✅ 没 source ~/.cargo/env

❌ apt 装的 rust 很旧
✅ 用 rustup

❌ 编译慢
✅ 用镜像 + cargo check


十、下一步学什么

  • 基础语法:rustlings
  • Web:Axum / Actix
  • 系统:cli 工具
  • 编辑器:VS Code + rust-analyzer

如果你愿意,我可以:

  • 给你最小入门路线
  • 帮你配 VS Code Rust 环境
  • 或按你目标(后端 / 嵌入式 / 刷题)给建议

你打算用 Rust 干什么?

0