Debian系统Rust配置步骤是什么
导读:Debian 系统 Rust 配置步骤 一 准备与安装 更新系统并安装基础依赖(如 curl 与编译工具),以便顺利安装与构建 Rust 项目: sudo apt update sudo apt install -y curl buil...
Debian 系统 Rust 配置步骤
一 准备与安装
- 更新系统并安装基础依赖(如 curl 与编译工具),以便顺利安装与构建 Rust 项目:
- sudo apt update
- sudo apt install -y curl build-essential gcc make
- 安装方式一(推荐)—使用 rustup 管理工具链(可多版本切换、获取最新稳定版):
- curl --proto ‘=https’ --tlsv1.2 -sSf https://sh.rustup.rs | sh
- 安装完成后执行:source “$HOME/.cargo/env”
- 安装方式二—使用 Debian 官方仓库的稳定版(版本通常较旧,适合保守环境):
- sudo apt install -y rustc cargo
- 验证安装:
- rustc --version
- cargo --version
二 基础配置与常用命令
- 设置默认工具链(稳定版/测试版/夜间版):
- rustup default stable
- 或:rustup default nightly
- 安装常用组件(代码格式化、静态检查等):
- rustup component add rustfmt clippy
- 更新工具链:
- rustup update
- 创建与运行项目:
- cargo new hello & & cd hello
- cargo run
- 交叉编译目标示例(如 ARM 32 位):
- rustup target add armv7-unknown-linux-gnueabihf
三 Cargo 与镜像配置
- 全局配置路径为 ~/.cargo/config.toml,可用于设置构建与下载行为(如更换 crates.io 镜像源以加速国内下载)。示例:
- [source.crates-io]
- replace-with = ‘tuna’
- [source.tuna]
- registry = “https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git”
- [source.crates-io]
-
说明:将镜像地址写入该文件后,后续 cargo 操作会自动使用配置的镜像源。
四 常见问题与进阶
- 环境变量未生效:手动将 $HOME/.cargo/bin 加入 PATH,并重新加载 shell 配置:
- echo ‘export PATH=“$HOME/.cargo/bin:$PATH”’ > > ~/.bashrc
- source ~/.bashrc
- 多项目多版本:在项目根目录创建 .rustup/toolchain 文件指定工具链,进入目录会自动切换:
- echo “stable” > .rustup/toolchain
- 构建 Debian 包:安装 cargo-deb 并打包
- cargo install cargo-deb
- cargo deb
- sudo dpkg -i target/debian/*.deb
- 需要调试符号时,在 Cargo.toml 的发布配置中开启:
- [profile.release]
- debug = true
- [profile.release]
声明:本文内容由网友自发贡献,本站不承担相应法律责任。对本内容有异议或投诉,请联系2913721942#qq.com核实处理,我们将尽快回复您,谢谢合作!
若转载请注明出处: Debian系统Rust配置步骤是什么
本文地址: https://pptw.com/jishu/769316.html
