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

相关推荐
SomeOtherTime7 小时前
第 11 讲(大结局):编译期元编程与零拷贝架构——卫生声明宏(macro_rules!)、过程宏 AST 手术刀与 Serde 零反射序列化的终极合龙
rust
2601_9679801112 小时前
Python 与云计算:AWS、GCP、Azure 实践
python·云计算·azure·aws·gcp
SomeOtherTime12 小时前
番外篇(第 12 讲):走向工业界深水区——从物理定律看 Rust 在真实工程中的“降维打击”与“阿喀琉斯之踵”
开发语言·rust
Kapaseker13 小时前
Rust 桌面开发到底怎么选?先看这篇文章!
rust
奶油话梅糖14 小时前
容器启停 2.5 毫秒:11 天 1,700 Star 的 Kiri,用一个 900 KB 的 PID 1 干掉了 runc 和 dockerd
前端·人工智能·rust
cc5725026531 天前
云计算技术应用专业大学期间考证怎么安排?
云计算
wflynn1 天前
GitHub 今日推荐|kiri:clone3 系统调用直达容器,2.5 毫秒启动无 runc 中间层
docker·rust·kubernetes·开源·github·containers
SomeOtherTime1 天前
第 4 讲:突破静态枷锁——智能指针(Box/Rc/Arc)与内部可变性(Cell/RefCell/UnsafeCell)的内存暗道
rust
SomeOtherTime1 天前
第 9 讲:异步并发与 Pin 的底层解剖——async/await 无栈协程状态机脱糖、自引用死锁的终极救赎与 Future/Waker 驱动模型
rust