在Debian上配置Rust开发环境可按以下步骤操作:
更新系统并安装依赖
sudo apt update sudo apt install curl build-essential gcc make -y 安装Rust工具链(推荐使用rustup)
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh 按提示完成安装,可选择将Rust安装到系统目录(如/opt/rust)或用户目录。
配置环境变量
~/.bashrc或~/.zshrc:source $HOME/.cargo/env echo 'export PATH="$HOME/.cargo/bin:$PATH"' | sudo tee -a /etc/profile.d/rust.sh source /etc/profile 验证安装
rustc --version # 查看Rust编译器版本 cargo --version # 查看Cargo版本 (可选)安装额外工具
rustup component add rustfmtrustup component add clippy(可选)配置镜像加速
编辑~/.cargo/config.toml,添加国内镜像源(如清华源):
[source.crates-io] replace-with = "tuna" [source.tuna] registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git" 创建并运行Rust项目
cargo new hello_world cd hello_world cargo build cargo run 安装完成后,可使用VSCode等IDE配合Rust插件(如rust-analyzer)提升开发体验。