在Debian上配置Rust环境步骤如下:
更新系统并安装依赖包
sudo apt update
sudo apt install curl build-essential gcc make -y
使用rustup安装Rust
wget -qO - https://sh.rustup.rs | sudo bash -s -- --no-modify-path -y
(安装到/opt/rust目录,避免修改系统路径)
配置环境变量
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
验证:echo $RUSTUP_HOME和echo $PATH确认路径正确。
验证安装
rustc --version # 查看Rust编译器版本
cargo --version # 查看包管理器版本
(可选)配置工具链补全
rustup completions bash > /usr/share/bash-completion/completions/rustup
source /etc/profile.d/bash_completion.sh
(可选)配置国内镜像加速
编辑~/.cargo/config.toml,添加:
[source.crates-io]
replace-with = "tuna"
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
完成以上步骤后,即可使用cargo创建、构建Rust项目。如需打包为Debian包,可安装cargo-deb工具:cargo install cargo-deb。