分类
devops

updating crates.io index 慢慢慢慢慢慢

Symptoms

docker run -it --rm rust:1.49-buster bash
root@8c6989069d3f:/# cargo install --verbose simple-http-server
    Updating crates.io index
       Fetch [                                                       ]   1.62%

于是参考一些博客尝试修改Rust Crates的mirror,在 $HOME/.cargo/config 中添加如下内容,重新cargo install simple-http-server依然不行

[source.crates-io]
replace-with = 'ustc'

[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"

Cause

潜在默认的索引地址是https://github.com/rust-lang/crates.io-index

Resolution

root@8c6989069d3f:/# echo $CARGO_HOME
/usr/local/cargo

官方的rust镜像配置了$CARGO_HOME环境变量,参看官方网站,配置文件写入$CARGO_HOME/config.toml再次调用发现mirror就生效了

root@8c6989069d3f:/# cat $CARGO_HOME/config.toml
[source.crates-io]
replace-with = "ustc"
[source.ustc]
registry = "https://mirrors.ustc.edu.cn/crates.io-index"
root@8c6989069d3f:/# cargo install --verbose simple-http-server
    Updating `https://mirrors.ustc.edu.cn/crates.io-index` index
       Fetch [==================>                                    ]  36.22%

ref

  • https://mirrors.ustc.edu.cn/help/crates.io-index.html
  • https://mirrors.tuna.tsinghua.edu.cn/help/crates.io-index.git/
  • https://doc.rust-lang.org/cargo/reference/config.html
  • https://doc.rust-lang.org/cargo/reference/source-replacement.html