在Debian系统中,推荐使用rustup
工具来安装和管理Rust编程语言。以下是详细的步骤和建议:
sudo apt update
sudo apt install curl build-essential gcc make -y
rustup
:curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sudo sh -s -- --no-modify-path -y
按照提示完成安装过程。通常,你需要接受许可协议并选择安装路径。
echo 'export RUSTUP_HOME=/opt/rust' | sudo tee -a /etc/profile.d/rust.sh
echo 'export PATH=$PATH:/opt/rust/bin' | sudo tee -a /etc/profile.d/rust.sh
source /etc/profile
rustc --version
如果显示了版本信息,说明安装成功。
rustup default stable
rustup default beta
rustup default nightly
Cargo.toml
文件中指定Rust版本,以确保项目使用特定版本的Rust进行构建。例如:[dependencies]
rand = "0.8"
[package.metadata.rustc]
channel = "stable" # 或者 "beta" 或 "nightly"
rustup update
通过以上步骤,你可以在Debian系统上选择和管理适合你需求的Rust版本。