使用阿里云镜像加速Rust与Cargo安装及更新

简介

Rustup 是 Rust 编程语言官方提供的跨平台安装工具,用于管理和更新 Rust 工具链、Cargo 组件以及 Rust 版本。为了在中国大陆地区获得更快的下载速度和更好的稳定性,我们可以选择使用阿里云提供的 Rust 镜像服务。

下载地址

https://mirrors.aliyun.com/rustup/

配置方法

设置 Rustup 镜像

临时替换镜像源
bash 复制代码
# 临时设置环境变量以替换默认更新源和分发服务器
export RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup
export RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup
永久替换镜像源

对于 bash 用户:

bash 复制代码
# 在 ~/.bash_profile 文件中添加以下内容
echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup' >> ~/.bash_profile
echo 'export RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup' >> ~/.bash_profile
# 更新当前终端会话的环境变量
source ~/.bash_profile

对于 zsh 用户:

bash 复制代码
# 在 ~/.zshrc 文件中添加以下内容
echo 'export RUSTUP_UPDATE_ROOT=https://mirrors.aliyun.com/rustup/rustup' >> ~/.zshrc
echo 'export RUSTUP_DIST_SERVER=https://mirrors.aliyun.com/rustup' >> ~/.zshrc
# 更新当前终端会话的环境变量
source ~/.zshrc

安装 Rust

使用阿里云安装脚本
bash 复制代码
curl --proto '=https' --tlsv1.2 -sSf https://mirrors.aliyun.com/repo/rust/rustup-init.sh | sh
或者使用官方安装脚本
bash 复制代码
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

当终端显示 "Rust is installed now. Great!" 时,说明 Rust 已经成功安装。

配置 crates.io 镜像

为了加速 Cargo 的依赖包下载,我们需要配置 crates.io 的镜像源。在 ~/.cargo/config 文件(Windows 系统配置文件地址默认为 %USERPROFILE%\.cargo\config)中,添加以下内容:

toml 复制代码
[registry]
index = "https://github.com/rust-lang/crates.io-index"

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

[source.aliyun]
registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"

请注意,目前阿里云镜像仅支持稀疏索引配置,需要您的 cargo 版本 >=1.68。

相关推荐
ssshooter1 小时前
Tauri 项目实践:客户端与 Web 端的授权登录实现方案
前端·后端·rust
AI智动派3 小时前
《深入 Rust Async/Await:如何实现一个带超时保护与安全沙箱的 LLM Agent 循环》
rust
Johny_Zhao1 天前
OpenClaw中级到高级教程
linux·人工智能·信息安全·kubernetes·云计算·yum源·系统运维·openclaw
范特西林2 天前
一次 to_bits() 引发的 Rust 与 C++ 底层思考
rust
冬奇Lab3 天前
一天一个开源项目(第42篇):OpenFang - 用 Rust 构建的 Agent 操作系统,16 层安全与 7 个自主 Hands
人工智能·rust·开源
Johny_Zhao3 天前
centos7安装部署openclaw
linux·人工智能·信息安全·云计算·yum源·系统运维·openclaw
量子位3 天前
Transformer论文作者重造龙虾,Rust搓出钢铁版,告别OpenClaw裸奔漏洞
rust·openai·ai编程
哈里谢顿3 天前
Rust 语言入门博客
rust
DongLi015 天前
rustlings 学习笔记 -- exercises/06_move_semantics
rust
ssshooter5 天前
Tauri 踩坑 appLink 修改后闪退
前端·ios·rust