debian

Debian如何搭建Rust开发环境

小樊
38
2025-04-20 06:13:45
栏目: 编程语言

在Debian上搭建Rust开发环境,可以按照以下步骤进行:

安装Rust

  1. 更新包列表
sudo apt update
  1. 安装必要的工具
sudo apt install git curl build-essential
  1. 下载并安装Rust
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --default-toolchain none -y --profile minimal
  1. 添加Rust到环境变量
echo 'export PATH="$HOME/.cargo/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
  1. 验证安装
rustc --version
cargo --version

配置Cargo镜像源(可选)

为了加快下载速度,可以配置国内镜像源,例如清华源:

  1. 创建或编辑.cargo/config.toml文件
mkdir -p ~/.cargo
nano ~/.cargo/config.toml
  1. 添加以下内容
[source.crates-io]
replace-with = 'tuna'

[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
  1. 保存并退出编辑器

安装开发工具(可选)

为了更方便地进行Rust开发,可以安装一些有用的工具:

  1. rustfmt:代码格式化工具。
rustup component add rustfmt
  1. Clippy:Rust的代码质量检查工具。
rustup component add clippy

创建并运行一个简单的Rust项目

  1. 创建新项目
cargo new hello_world
cd hello_world
  1. 编译并运行项目
cargo build
cargo run

如果一切顺利,你应该能够在终端中看到“Hello, world!”的输出。

通过以上步骤,你就可以在Debian上成功搭建一个Rust开发环境。如果有任何问题,可以参考Rust官方文档或相关社区资源。

0
看了该问题的人还看了