温馨提示×

linux下rust怎么安装

小樊
42
2026-10-21 16:57:15
栏目: 编程语言

在 Linux 下安装 Rust,最推荐、也是官方推荐的方式是使用 rustup。


一、使用 rustup 安装(推荐)

1. 安装 rustup

在终端中执行:

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

按提示选择:

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

安装完成后,按提示执行:

source "$HOME/.cargo/env"

或者重新打开终端。


2. 验证安装

rustc --version
cargo --version

能看到版本号即说明安装成功。


二、更新 Rust

rustup update

三、卸载 Rust

rustup self uninstall

四、常见问题

1. 缺少依赖(编译失败)

Rust 编译需要 C 工具链,建议安装:

Debian / Ubuntu:

sudo apt update
sudo apt install build-essential

CentOS / Rocky / Alma:

sudo dnf groupinstall "Development Tools"

2. 换国内镜像(加速)

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

然后再执行安装脚本。


如果你告诉我:

  • 使用的 Linux 发行版(Ubuntu / CentOS / Arch 等)
  • 是否用于 嵌入式 / WASM / 服务器开发

我可以给你更具体的配置建议。

0 踩