下面按新手友好的顺序,教你从零在 Debian 上配置 Rust 开发环境,不绕弯。
sudo apt update
sudo apt upgrade -y
Rust 编译需要这些:
sudo apt install -y build-essential curl git pkg-config libssl-dev
不要用 apt 装 rustc(版本旧)
用官方脚本:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装时选:
1) Proceed with standard installation
source "$HOME/.cargo/env"
(每次开新终端都要,或者重启终端)
rustc --version
cargo --version
看到版本号就成功了 ✅
编辑 ~/.cargo/config.toml:
mkdir -p ~/.cargo
nano ~/.cargo/config.toml
内容(清华源示例):
[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
输出:
Hello, world!
cargo build # 编译
cargo run # 编译并运行
cargo check # 只检查错误(快)
cargo update # 更新依赖
❌ command not found: cargo
✅ 没 source ~/.cargo/env
❌ apt 装的 rust 很旧
✅ 用 rustup
❌ 编译慢
✅ 用镜像 + cargo check
rustlings如果你愿意,我可以:
你打算用 Rust 干什么?