在 Debian 上配置 Rust 环境,有几个常见坑和注意点,按使用场景给你梳理一下:
rustupcurl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
或离线安装 rustup-init。
原因
rustc / cargo 版本严重过时⚠️ 不要优先用 apt 装 Rust 做开发
sudo apt install rustc cargo # 不推荐(除非只跑旧程序)
安装完后:
source $HOME/.cargo/env
建议写入:
echo 'source $HOME/.cargo/env' >> ~/.bashrc
# 或 ~/.zshrc
否则会出现:
cargo: command not found
很多 crate 依赖 C 编译:
sudo apt install build-essential
否则报错:
failed to run custom build command for `xxx`
cc not found
| 功能 | 包 |
|---|---|
| SSL | libssl-dev |
| 数据库 | libsqlite3-dev |
| 图像 | libpng-dev |
| 压缩 | zlib1g-dev |
rustup target add x86_64-unknown-linux-musl
rustup target add armv7-unknown-linux-gnueabihf
rust-analyzer(必须)sudo apt install rust-analyzer # 可选,但建议用扩展装
rustup update
cargo clean
定期清理:
cargo cache # 第三方工具
sudo apt update
sudo apt install build-essential curl
curl https://sh.rustup.rs -sSf | sh
source $HOME/.cargo/env
如果你告诉我:
我可以给你更精确的配置方案。