使用阿里云镜像加速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。

相关推荐
Tomhex18 小时前
Rust数组与Vec的核心差异解析
rust
easy_coder21 小时前
AI Agent 真正的上限,不在 Skill 数量,而在边界设计
人工智能·云计算
TG_yunshuguoji1 天前
阿里云代理商:百炼大模型技术解析与应用指南
服务器·阿里云·云计算
G31135422731 天前
零门槛实现 TRTC 音视频流转推各大直播 CDN
大数据·人工智能·ai·云计算
橘子编程1 天前
编程语言全指南:从C到Rust
java·c语言·开发语言·c++·python·rust·c#
bingyan03711 天前
squid-基于rockylinux8配置内网代理访问阿里云软件源
阿里云·代理·squid·软件源
Huy-C1 天前
云计算案例排错(云上4)
linux·运维·云计算
亿牛云爬虫专家1 天前
学术文献爬虫 OOM 崩溃与 403 风暴
爬虫·rust·爬虫代理·403·oom killer·学术文献·403 forbidden
土豆12501 天前
Tauri 入门与实践:用 Rust 构建你的下一个桌面应用
前端·rust