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

相关推荐
王道长服务器 | 亚马逊云26 分钟前
AWS CloudWatch Logs Insights:实时日志分析,让服务器问题无所遁形
服务器·云计算·aws
AKAMAI43 分钟前
Linebreak赋能实时化企业转型:专业系统集成商携手Akamai以实时智能革新企业运营
人工智能·云原生·云计算
JoannaJuanCV4 小时前
error: can‘t find Rust compiler
开发语言·后端·rust
开发者导航5 小时前
【开发者导航】支持多存储方式的开源文件列表程序:OpenList
人工智能·学习·阿里云·信息可视化
熙客7 小时前
阿里云监控:SLS的使用
运维·阿里云·云原生·云计算
聚名网7 小时前
阿里云和聚名网的域名注册安全性如何?
阿里云·云计算
TG_yunshuguoji8 小时前
阿里云渠道商:哪些方法能给服务器加速?
服务器·阿里云·云计算
企鹅侠客9 小时前
阿里云ACK多个Service绑定单个SLB实践
阿里云·云计算·service·ack
D11_9 小时前
在阿里云CentOS服务器上使用Certbot为Nginx配置SSL证书
服务器·阿里云·centos
小小小糖果人12 小时前
Linux云计算基础篇(27)-NFS网络文件系统
linux·网络·云计算