在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插件
说明:
rustup
会自动管理Rust版本和工具链,推荐使用。cargo-deb
工具:cargo install cargo-deb
参考来源: