Debian系统轻松安装Rust的步骤
在安装Rust前,需确保系统已更新并安装必要工具。打开终端,执行以下命令更新包列表并安装curl、build-essential、gcc、make(这些工具用于编译Rust代码及后续项目构建):
sudo apt update
sudo apt install curl build-essential gcc make -y
rustup是Rust官方推荐的版本管理工具,可便捷安装、更新和管理Rust环境。执行以下命令下载并运行rustup安装脚本(--no-modify-path选项避免修改系统PATH,提升安全性):
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sudo bash -s -- --no-modify-path -y
安装完成后,rustc(Rust编译器)和cargo(Rust包管理器)将自动添加至系统路径。
若安装时未自动配置环境变量,可通过以下命令手动添加(将Rust工具链路径写入系统profile):
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 # 立即生效配置
通过以下命令检查Rust及cargo是否安装成功(显示版本号则表示安装完成):
rustc --version # 查看Rust编译器版本
cargo --version # 查看cargo包管理器版本
~/.cargo/config文件,添加以下内容:[source.crates-io]
replace-with = 'ustc'
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
rustup completions bash > /usr/share/bash-completion/completions/rustup
source /etc/profile.d/bash_completion.sh
rustup update更新Rust工具链至最新版本。