在 Debian 系统上安装 Rust 及其依赖,通常有以下几种方式,根据你的使用场景选择即可。
Rust 官方推荐使用 rustup 安装,能方便管理版本和工具链。
sudo apt update
sudo apt install -y curl build-essential gcc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
rustc --version
cargo --version
适合只想运行 Rust 程序的人。
sudo apt update
sudo apt install -y rustc cargo
⚠️ 注意:
sudo apt install -y build-essential pkg-config libssl-dev
| 功能 | 安装命令 |
|---|---|
| OpenSSL | sudo apt install libssl-dev |
| SQLite | sudo apt install libsqlite3-dev |
| PostgreSQL | sudo apt install libpq-dev |
| MySQL | sudo apt install libmysqlclient-dev |
| Systemd | sudo apt install libsystemd-dev |
编辑 ~/.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"
cargo build 报错找不到 C 编译器sudo apt install -y gcc
rustup update
rustup self uninstall
如果你能说明 具体项目 / crate / 报错信息,我可以给你更精确的依赖安装建议。