rust安装

本文针对Rust官方服务器在国外导致安装困难的问题,提供了通过国内镜像快速安装Rust的步骤,包括配置cargo源,确保安装顺利完成。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题现状

        由于rustup官方服务器在国外,如果直接按照rust官网的安装方式安装非常容易失败,用国内的镜像则可以很快搞定。

官方安装

文档: Install Rust - Rust Programming Language

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

国内镜像安装

export RUSTUP_DIST_SERVER=https://mirrors.ustc.edu.cn/rust-static
export RUSTUP_UPDATE_ROOT=https://mirrors.ustc.edu.cn/rust-static/rustup

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

 安装过程中会提示选择安装模式,使用默认安装即可

info: downloading installer

Welcome to Rust!

This will download and install the official compiler for the Rust
programming language, and its package manager, Cargo.

Rustup metadata and toolchains will be installed into the Rustup
home directory, located at:

  /home/leo/.rustup

This can be modified with the RUSTUP_HOME environment variable.

The Cargo home directory located at:

  /home/leo/.cargo

This can be modified with the CARGO_HOME environment variable.

The cargo, rustc, rustup and other commands will be added to
Cargo's bin directory, located at:

  /home/leo/.cargo/bin

This path will then be added to your PATH environment variable by
modifying the profile files located at:

  /home/leo/.profile
  /home/leo/.bash_profile
  /home/leo/.bashrc

You can uninstall at any time with rustup self uninstall and
these changes will be reverted.

Current installation options:


   default host triple: x86_64-unknown-linux-gnu
     default toolchain: stable (default)
               profile: default
  modify PATH variable: yes

1) Proceed with installation (default)
2) Customize installation
3) Cancel installation
>1

下载完成后

  stable-x86_64-unknown-linux-gnu installed - rustc 1.56.1 (59eed8a2a 2021-11-01)


Rust is installed now. Great!

To get started you may need to restart your current shell.
This would reload your PATH environment variable to include
Cargo's bin directory ($HOME/.cargo/bin).

To configure your current shell, run:
source $HOME/.cargo/env

最后执行提示的source命令完成安装

配置cargo源

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

 将上述内容写到~/.cargo/config文件中

参考链接

Rust Toolchain 反向代理使用帮助 — USTC Mirror Help 文档

Rust Crates 源使用帮助 — USTC Mirror Help 文档

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值