在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或指定安装目录(如
/opt/rust):wget -qO - https://sh.rustup.rs | sudo RUSTUP_HOME=/opt/rust CARGO_HOME=/opt/rust sh -s -- --no-modify-path -y -
配置环境变量
- 将以下内容添加到
~/.bashrc或~/.zshrc:export PATH="$HOME/.cargo/bin:$PATH" - 重新加载配置:
source ~/.bashrc
若使用自定义安装目录,需将路径替换为
/opt/rust/bin - 将以下内容添加到
-
验证安装
rustc --version # 查看Rust编译器版本 cargo --version # 查看Cargo版本 -
创建并运行项目
cargo new hello_world # 创建新项目 cd hello_world cargo build # 编译项目 cargo run # 运行项目 -
可选:安装IDE插件
- VSCode:安装“Rust Analyzer”插件
- IntelliJ IDEA:安装“Rust”插件
说明:
rustup会自动管理Rust版本和工具链,推荐使用。- 若需打包为Debian格式(.deb),可安装
cargo-deb工具:cargo install cargo-deb
参考来源: