温馨提示×

如何安装linux rust环境

小樊
36
2026-10-27 15:31:29
栏目: 编程语言

下面给你一份在 Linux 上安装 Rust 开发环境的完整指南,包含最常见、最推荐的方式,以及验证和常见问题处理。


一、推荐方式:使用 rustup(官方方式)

1. 安装依赖

sudo apt update
sudo apt install -y curl build-essential

如果是 CentOS / Rocky / Alma:

sudo dnf install -y curl gcc

2. 安装 Rust(官方脚本)

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

安装过程中会让你选择:

  • 1) Proceed with standard installation(推荐)

安装完成后:

source "$HOME/.cargo/env"

或直接重启终端。


二、验证安装是否成功

rustc --version
cargo --version

输出类似:

rustc 1.80.0 (xxxxx)
cargo 1.80.0 (xxxxx)

三、更新 Rust

rustup update

四、安装常用组件(推荐)

rustup component add rustfmt clippy
  • rustfmt:代码格式化
  • clippy:代码静态检查

五、创建第一个 Rust 项目

cargo new hello_rust
cd hello_rust
cargo run

输出:

Hello, world!

六、可选:指定 Rust 版本

rustup install stable
rustup default stable

或安装 nightly:

rustup install nightly
rustup default nightly

七、常见问题

1. 国内网络慢

可使用国内镜像:

export RUSTUP_DIST_SERVER=https://rsproxy.cn
export RUSTUP_UPDATE_ROOT=https://rsproxy.cn/rustup

然后再执行安装脚本。

2. 卸载 Rust

rustup self uninstall

八、适用发行版说明

✅ Ubuntu / Debian
✅ CentOS / Rocky / Alma
✅ Arch
✅ WSL(Windows Subsystem for Linux)


如果你告诉我:

  • 具体 Linux 发行版(Ubuntu?CentOS?)
  • 是否用于 嵌入式 / 服务器 / 学习

我可以给你更定制的安装方案。

0 踩