温馨提示×

debian怎样安装rust环境

小樊
39
2026-09-08 05:03:14
栏目: 编程语言

在 Debian 上安装 Rust 环境,最推荐、也是最官方的方式是使用 rustup。下面给你几种常见做法。


一、使用 rustup 安装(推荐 ✅)

1. 更新系统

sudo apt update
sudo apt upgrade -y

2. 安装必要依赖

sudo apt install -y curl build-essential gcc make

3. 下载并运行 rustup 安装脚本

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

安装过程中会让你选择:

  • 1) Proceed with standard installation(默认,推荐)
  • 2) Customize installation
  • 3) Cancel installation

直接回车选 1 即可。

4. 使环境变量生效

source "$HOME/.cargo/env"

或重新打开终端。

5. 验证安装

rustc --version
cargo --version

二、通过 Debian apt 安装(不推荐 ⚠️)

Debian 仓库里的 Rust 版本通常较旧:

sudo apt install -y rustc cargo

查看版本:

rustc --version

⚠️ 如果你要用最新特性或第三方库,建议用 rustup。


三、常见后续操作

更新 Rust

rustup update

卸载 Rust

rustup self uninstall

安装特定版本

rustup install stable
rustup install nightly
rustup default stable

四、写个hello world测试

cargo new hello
cd hello
cargo run

如果你是用于 开发、嵌入式、WebAssembly、Linux 服务 等场景,我也可以给你更具体的环境配置建议。

0 踩