rust中如何配置字节源

前言

本文的目的是在windows上安装或更新rust的时候通过配置字节的国内源来提高安装/更新速度。非windows系统就可以直接参考rsproxy

配置说明

在powershell中设置 Rustup 镜像

1
2
$ENV:RUSTUP_DIST_SERVER='https://rsproxy.cn'
$ENV:RUSTUP_UPDATE_ROOT='https://rsproxy.cn/rustup'

安装或者更新Rust

如果是安装rust,直接点击rust-init.exe

如果是更新rust,直接运行rustup update命令

1
rustup update

设置 crates.io 镜像

在当前用户的主目录(以我本地为例:D:\Users\daming)下的.cargo文件夹中创建config文件。

1
2
3
4
5
6
7
8
9
10
[source.crates-io]
replace-with = 'rsproxy-sparse'
[source.rsproxy]
registry = "https://rsproxy.cn/crates.io-index"
[source.rsproxy-sparse]
registry = "sparse+https://rsproxy.cn/index/"
[registries.rsproxy]
index = "https://rsproxy.cn/crates.io-index"
[net]
git-fetch-with-cli = true

参考资料

  1. rsproxy
  2. Windows 11 上通过国内源安装 Rust
  3. rustup-init.exe 安装失败及其解决方案