caogo换国内镜像源的步骤
caogo换国内镜像源的步骤
ytkz使用方法
[source.crates-io]
replace-with = 'mirror'
[source.mirror]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
注:$CARGO_HOME
:在 Windows 系统默认为:%USERPROFILE%\.cargo
,在类 Unix 系统默认为:$HOME/.cargo
。
注:cargo 仍会尝试读取不带 .toml
扩展名的配置文件(即 $CARGO_HOME/config
),但从 1.39 版本起,cargo 引入了对 .toml
扩展名的支持,并将其设为首选格式。请根据使用的 cargo 版本选择适当的配置文件名。
在 Linux 环境可以使用下面的命令完成:
mkdir -vp ${CARGO_HOME:-$HOME/.cargo}
cat << EOF | tee -a ${CARGO_HOME:-$HOME/.cargo}/config.toml
[source.crates-io]
replace-with = 'mirror'
[source.mirror]
registry = "https://mirrors.tuna.tsinghua.edu.cn/git/crates.io-index.git"
EOF
如果使用了vpn,配置 Git 代理(若网络需要代理)
若你的网络需要通过代理访问互联网(如公司/校园网),Git 必须配置代理才能连接外部仓库。
步骤 1:确认系统代理设置
- Windows 设置 → 网络和 Internet → 代理 → 手动设置代理(若有)。
- 记录代理地址(如
http://proxy.example.com:8080
)和端口(若代理需要认证,记录用户名和密码)。
步骤 2:配置 Git 全局代理
在 PowerShell 中执行以下命令(替换为你的代理信息):
git config --global http.proxy http://127.0.0.1:[PORT]
git config --global https.proxy http://127.0.0.1:[PORT]
3. 启用 net.git-fetch-with-cli
(关键)
Cargo 默认使用内置的 Git 实现,可能无法正确读取系统代理或证书。启用 git-fetch-with-cli
后,Cargo 会调用系统安装的 Git 命令行工具(使用系统的代理和证书配置)。
操作步骤:
打开 Cargo 全局配置文件(路径:
C:\Users\你的用户名\.cargo\config.toml
)。添加以下内容(若文件不存在则新建):
[net] git-fetch-with-cli = true # 强制使用系统 Git 命令行工具