下面按在 Debian 上用 Rust 进行开发这个场景,给你一个从系统配置到常用工具的一站式说明。
sudo apt update
sudo apt upgrade -y
Rust 需要 C 链接器和 make 等:
sudo apt install -y build-essential pkg-config libssl-dev
常用额外依赖(视项目而定):
sudo apt install -y cmake git curl
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
按提示选择:
1) Proceed with installation (default)安装完成后:
source $HOME/.cargo/env
验证:
rustc --version
cargo --version
编辑 ~/.bashrc 或 ~/.zshrc:
export PATH="$HOME/.cargo/bin:$PATH"
生效:
source ~/.bashrc
编辑 ~/.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"
或使用清华镜像:
[source.crates-io]
replace-with = "tuna"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/crates.io-index"
cargo new hello
cd hello
cargo run
rustup component add rust-analyzer
或在编辑器安装 rust-analyzer
rustup component add rustfmt clippy
使用:
cargo fmt
cargo clippy
报错:openssl not found
sudo apt install -y libssl-dev pkg-config
sudo apt install -y musl-tools
rustup target add x86_64-unknown-linux-musl
cargo build --target x86_64-unknown-linux-musl
rust-analyzerrust-tools / lspconfighx 原生支持 Rust)如果是写后端服务,可用:
systemdcargo install cargo-deb(打包成 .deb)cargo install cargo-deb
cargo deb
如果你有具体用途(比如 Web 服务 / 系统程序 / 嵌入式 / GUI),我可以给你更针对性的 Debian + Rust 配置方案。