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

相关推荐
怪我冷i19 小时前
Rust错误处理之unwrap
rust·cloudflare·unwrap
Echo-J21 小时前
WinDbg 双机调试(调试机为Windows11系统,被调试机为Windows7系统)
安全·网络安全·云计算·系统安全
翼龙云_cloud1 天前
亚马逊云代理商:如何在 AWS Lightsail 上一键部署 OpenClaw 私有化 AI 助手?
人工智能·云计算·aws·openclaw
Database_Cool_1 天前
OpenClaw-Observability:基于 DuckDB 构建 OpenClaw 的全链路可观测体系
数据库·阿里云·ai
楚国的小隐士1 天前
为什么说Rust是对自闭症谱系人士友好的编程语言?
java·rust·编程·对比·自闭症·自闭症谱系障碍·神经多样性
Virtual_human08061 天前
在VMware workstation上,部署3节点ceph测试,及加入openstack
ceph·云计算·openstack·osd·ceph集群
s听风忆雪2 天前
aliyun 阿里云服务器 mysql 开启安全组 3306 依然访问不了
服务器·安全·阿里云
Tomhex2 天前
Rust智能指针使用指南
rust
Lim小刘2 天前
AWS IAM Identity Center 实战操作:从启用、用户、权限集到 SSO 登录
云计算·aws·云安全·sso
腾讯云大数据2 天前
腾讯云ES AI搜索最佳实践:基于ES与Dify的企业级RAG应用方案
大数据·人工智能·elasticsearch·云计算·腾讯云