Rust 学习笔记:使用 Rust 国内镜像代理
Rust 学习笔记:使用 Rust 国内镜像代理
由于国内拉取 crates.io 以及安装 Rust 会面临流量出境不稳定的问题,字节跳动 Rust 团队提供了一个国内镜像代理以帮助国内 Rust 生态发展,欢迎大家使用。
网页:https://rsproxy.cn/
服务每分钟更新一次,目前支持以下功能请求:
- Crates 依赖下载
- Rustup 工具链和 rustup-init.sh 下载
- Crates 搜索 (cargo search)
- Crates 发布 (cargo publish)
Mac 配置方法
步骤一:设置 Rustup 镜像, 修改配置 ~/.zshrc or ~/.bashrc
export RUSTUP_DIST_SERVER="https://rsproxy.cn"
export RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
步骤二:安装 Rust(请先完成步骤一的环境变量导入并 source rc 文件或重启终端生效)
curl --proto '=https' --tlsv1.2 -sSf https://rsproxy.cn/rustup-init.sh | sh
步骤三:设置 crates.io 镜像, 修改配置 ~/.cargo/config,已支持 git 协议和 sparse 协议,>=1.68 版本建议使用 sparse-index,速度更快。
sparse:
[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
rsproxy:
[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
Windows 配置方法
环境变量 -> 系统变量:

CARGO_HOME 中添加文件 config。如果没有配置,默认路径为 C:\Users${UserName}.cargo。

内容:
[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
测试
命令行执行 rustup update:
info: syncing channel updates for 'stable-x86_64-pc-windows-msvc'
info: latest update on 2025-06-26, rust version 1.88.0 (6b00bc388 2025-06-23)
info: downloading component 'rust-src'
info: downloading component 'cargo'
info: downloading component 'clippy'
info: downloading component 'rust-docs'
info: downloading component 'rust-std'
info: downloading component 'rustc'
75.7 MiB / 75.7 MiB (100 %) 10.3 MiB/s in 8s
info: downloading component 'rustfmt'
2.6 MiB / 2.6 MiB (100 %) 412.8 KiB/s in 7s
info: removing previous version of component 'rust-src'
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'rust-src'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
20.1 MiB / 20.1 MiB (100 %) 2.1 MiB/s in 9s
info: installing component 'rust-std'
20.3 MiB / 20.3 MiB (100 %) 14.3 MiB/s in 1s
info: installing component 'rustc'
75.7 MiB / 75.7 MiB (100 %) 15.8 MiB/s in 4s
info: installing component 'rustfmt'
info: syncing channel updates for 'nightly-x86_64-pc-windows-msvc'
info: latest update on 2025-07-01, rust version 1.90.0-nightly (f26e58023 2025-06-30)
info: downloading component 'rust-src'
info: downloading component 'miri'
info: downloading component 'cargo'
8.7 MiB / 8.7 MiB (100 %) 4.8 MiB/s in 2s
info: downloading component 'clippy'
3.6 MiB / 3.6 MiB (100 %) 513.6 KiB/s in 7s
info: downloading component 'rust-docs'
20.5 MiB / 20.5 MiB (100 %) 10.1 MiB/s in 2s
info: downloading component 'rust-std'
20.7 MiB / 20.7 MiB (100 %) 11.9 MiB/s in 2s
info: downloading component 'rustc'
76.0 MiB / 76.0 MiB (100 %) 11.2 MiB/s in 8s
info: downloading component 'rustfmt'
info: removing previous version of component 'rust-src'
info: removing previous version of component 'miri'
info: removing previous version of component 'cargo'
info: removing previous version of component 'clippy'
info: removing previous version of component 'rust-docs'
info: removing previous version of component 'rust-std'
info: removing previous version of component 'rustc'
info: removing previous version of component 'rustfmt'
info: installing component 'rust-src'
info: installing component 'miri'
info: installing component 'cargo'
info: installing component 'clippy'
info: installing component 'rust-docs'
20.5 MiB / 20.5 MiB (100 %) 2.0 MiB/s in 8s
info: installing component 'rust-std'
20.7 MiB / 20.7 MiB (100 %) 14.2 MiB/s in 1s
info: installing component 'rustc'
76.0 MiB / 76.0 MiB (100 %) 15.7 MiB/s in 5s
info: installing component 'rustfmt'
info: checking for self-update
stable-x86_64-pc-windows-msvc updated - rustc 1.88.0 (6b00bc388 2025-06-23) (from rustc 1.87.0 (17067e9ac 2025-05-09))
nightly-x86_64-pc-windows-msvc updated - rustc 1.90.0-nightly (f26e58023 2025-06-30) (from rustc 1.89.0-nightly (45acf54ee 2025-06-16))
info: cleaning up downloads & tmp directories
下载速度还是很快的。
踩坑点 1:Could not connect to server (Failed to connect to 127.0.0.1 port 4781 after
一个可能的原因是使用了代理 proxy。
查询是否使用代理:
git config --global http.proxy
取消代理:
git config --global --unset http.proxy

后面就可以正常下载 crate 了。
1865

被折叠的 条评论
为什么被折叠?



