温馨提示×

如何配置debian下的rust

小樊
46
2026-09-08 05:02:17
栏目: 编程语言

在 Debian 系统下配置 Rust 开发环境,通常推荐使用官方工具链管理器 rustup。下面是完整步骤:


一、更新系统

sudo apt update
sudo apt upgrade -y

二、安装必要依赖

Rust 编译需要一些基础工具:

sudo apt install -y build-essential curl git

三、安装 Rust(推荐方式:rustup)

1. 下载并运行官方安装脚本

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

安装过程中会提示:

  • 默认选 1) Proceed with installation (default)

2. 加载环境变量

安装完成后执行:

source $HOME/.cargo/env

或者重新打开终端。


3. 验证安装

rustc --version
cargo --version

四、配置国内镜像(可选,加速下载)

编辑环境变量文件:

nano ~/.cargo/config.toml

示例(使用清华镜像):

[source.crates-io]
replace-with = "rsproxy-sparse"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"

[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"

[net]
git-fetch-with-cli = true

也可使用:

  • 中科大:https://mirrors.ustc.edu.cn/crates.io-index
  • 字节:https://rsproxy.cn

五、更新与管理 Rust

rustup update
rustup default stable
rustup toolchain list

六、创建第一个项目

cargo new hello_world
cd hello_world
cargo run

七、常见问题

1. 找不到 rustc

确保:

source $HOME/.cargo/env

或把下面内容加到 ~/.bashrc

export PATH="$HOME/.cargo/bin:$PATH"

2. Debian 旧版本

建议使用 Debian 11+,Rust 对 glibc 有要求。


如果你有 特定用途(如嵌入式、WASM、Linux 内核开发、GUI),可以告诉我,我可以给你更针对性的配置方案。

0