【Rust】cargo update或者cargo build国内被墙失败解决办法

Cargo build失败解决办法

现象

cargo build 时下载失败(Mac 10.13.4),提示:

error: failed to download from https://crates-io.proxy.ustclug.org/api/v1/crates/actix-codec/0.3.0/download

Caused by:
[56] Failure when receiving data from the peer (Received HTTP code 500 from proxy after CONNECT)

或者提示:
error: failed to download from https://crates-io.proxy.ustclug.org/api/v1/crates/actix-codec/0.3.0/download

Caused by:
[60] Peer certificate cannot be authenticated with given CA certificates (SSL certificate problem: certificate has expired)

或者
Caused by:
failed to load source for dependency actix-cors

Caused by:
Unable to update registry crates-io

Caused by:
failed to update replaced source registry crates-io

Caused by:
failed to fetch https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index

Caused by:
network failure seems to have happened
if a proxy or similar is necessary net.git-fetch-with-cli may help here
https://doc.rust-lang.org/cargo/reference/config.html#netgit-fetch-with-cli

Caused by:
[56] Failure when receiving data from the peer (Received HTTP code 500 from proxy after CONNECT); class=Net (12)

解决办法

vi ~/.cargo/config

# 放到 `$HOME/.cargo/config` 文件中
[source.crates-io]
registry = "https://github.com/rust-lang/crates.io-index"

# 替换成你偏好的镜像源
replace-with = 'sjtu'
#replace-with = 'ustc'

# 清华大学
[source.tuna]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"

# 中国科学技术大学
[source.ustc]
registry = "git://mirrors.ustc.edu.cn/crates.io-index"

# 上海交通大学
[source.sjtu]
registry = "https://mirrors.sjtug.sjtu.edu.cn/git/crates.io-index"

# rustcc社区
[source.rustcc]
registry = "git://crates.rustcc.cn/crates.io-index"

[net]
git-fetch-with-cli=true

变为上海交通大学的源,最重要的是 最后net的参数,设置为从git拉取。git不会被墙。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值