在 Debian 上运行 / 开发 Rust,一般分三步:安装工具链 → 配置环境 → 跑通示例。下面按「推荐做法 + 可选方案」给你一份清晰配置指南。
sudo apt update
sudo apt install -y curl build-essential gcc
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装过程中选择:
1) Proceed with standard installation(默认即可)source "$HOME/.cargo/env"
建议写入 ~/.bashrc 或 ~/.zshrc:
echo 'source "$HOME/.cargo/env"' >> ~/.bashrc
rustc --version
cargo --version
cargo new hello
cd hello
cargo run
输出:
Hello, world!
sudo apt install -y rustc cargo
⚠️ 缺点:
mkdir -p ~/.cargo
cat >> ~/.cargo/config.toml <<EOF
[source.crates-io]
replace-with = "rsproxy"
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
EOF
cargo install cargo-edit
cargo install rustfmt
cargo install clippy
如果编译报类似:
could not find openssl
安装:
sudo apt install -y pkg-config libssl-dev
其他常见:
sudo apt install -y libclang-dev clang
rustup update
rustup self uninstall
如果你是用于:
可以告诉我具体场景,我可以给你更针对性的配置。