背景
因为众所周知的原因
Rust的crates.io在国内速度不佳,有时候甚至直接404
经过一番查找,字节跳动旗下的镜像在速度、稳定性以及同步方面做的比较好。
步骤
步骤一:设置 Rustup 镜像
Linux和Mac修改配置 ~/.zshrc or ~/.bashrc
export RUSTUP_DIST_SERVER="https://rsproxy.cn" export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
Windows在环境变量中增加
RUSTUP_DIST_SERVER="https://rsproxy.cn" RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
步骤二:安装 Rust
Linux和Mac
curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh
Windows
在官网下载可执行文件
步骤三:设置 crates.io 镜像
Rust版本>=1.68 版本建议使用 sparse-index,速度会更快。
Linux和Mac的配置位于
~/.cargo/config
Windows的配置位于(如果没有config.toml则自己新建即可)
C:\Users\你的用户名\.cargo\config.toml
config的内容
[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
如果Rust版本<1.68版本则使用下面的配置
[source.crates-io] replace-with = 'rsproxy' [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
至此就可以进行下载加速