在 Debian 上配置 Rust 开发环境整体比较简单,但有一些容易踩坑的点和推荐做法。下面按「安装方式 → 系统依赖 → 常见坑 → 推荐配置」来说明。
rustup不要直接用 apt install rustc(版本通常很旧)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rust-lang.org | sh
source "$HOME/.cargo/env"
验证:
rustc --version
cargo --version
很多 Rust 项目(尤其涉及网络、加密、GUI)需要系统库。
sudo apt update
sudo apt install -y \
build-essential \
pkg-config \
libssl-dev \
ca-certificates
| 场景 | 包 |
|---|---|
| 数据库(postgres) | libpq-dev |
| MySQL | libmysqlclient-dev |
| SQLite | libsqlite3-dev |
| 图像 | libpng-dev, libjpeg-dev |
| GUI(gtk) | libgtk-3-dev |
| 音频 | libasound2-dev |
Debian 稳定版(stable) glibc 较旧:
version 'GLIBC_2.XX' not found
✅ 解决建议:
musl 静态编译:rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-musl
rustup,不要用 aptRust 编译缓存很大:
~/.cargo
target/
建议:
cargo clean
编辑 ~/.cargo/config.toml:
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
或中科大 / 清华源也可以。
rustup toolchain install stable beta nightly
rustup default stable
rust-analyzerrust-analyzercargo install cargo-watch
cargo install cargo-edit
cargo install clippy
cargo new hello
cd hello
cargo run
✅ 用 rustup
✅ 装 build-essential + pkg-config + libssl-dev
✅ 注意 glibc 兼容性
✅ 国内配置 cargo 镜像
如果你愿意,可以告诉我:
我可以给你更精确的配置方案。