在Debian上配置Rust环境推荐使用rustup工具,步骤如下:
更新系统并安装依赖
sudo apt update
sudo apt install curl build-essential gcc make -y
安装Rustup
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
按提示选择默认安装(通常输入1),工具链会安装到~/.cargo目录。
配置环境变量
~/.bashrc(或~/.zshrc):echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh
source /etc/profile
验证安装
rustc --version # 显示版本号即成功
cargo --version
安装额外工具(可选)
rustup component add rustfmt clippy # 代码格式化与质量检查工具
使用Cargo管理项目
cargo new hello_world # 创建新项目
cd hello_world
cargo build # 编译
cargo run # 运行
说明:
rustup是Rust官方推荐的安装工具,支持多版本管理和工具链切换。.deb格式,可安装cargo-deb工具。