在 Debian 系统下配置 Rust 开发环境,通常推荐使用官方工具链管理器 rustup。下面是完整步骤:
sudo apt update
sudo apt upgrade -y
Rust 编译需要一些基础工具:
sudo apt install -y build-essential curl git
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
安装过程中会提示:
1) Proceed with installation (default)安装完成后执行:
source $HOME/.cargo/env
或者重新打开终端。
rustc --version
cargo --version
编辑环境变量文件:
nano ~/.cargo/config.toml
示例(使用清华镜像):
[source.crates-io]
replace-with = "rsproxy-sparse"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true
也可使用:
https://mirrors.ustc.edu.cn/crates.io-indexhttps://rsproxy.cnrustup update
rustup default stable
rustup toolchain list
cargo new hello_world
cd hello_world
cargo run
确保:
source $HOME/.cargo/env
或把下面内容加到 ~/.bashrc:
export PATH="$HOME/.cargo/bin:$PATH"
建议使用 Debian 11+,Rust 对 glibc 有要求。
如果你有 特定用途(如嵌入式、WASM、Linux 内核开发、GUI),可以告诉我,我可以给你更针对性的配置方案。