Skip to content

网络与代理

命令行代理

如果 npm、git、curl 访问国外资源失败,可以临时设置代理。

先测试:

bash
curl https://www.google.com

macOS / Linux:

bash
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890

Windows PowerShell:

powershell
$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"

端口以本机代理软件为准

示例使用 7890,如果你的代理软件使用 789710809 或其他端口,需要替换成实际端口。

Git 代理

设置:

bash
git config --global http.proxy http://127.0.0.1:7890
git config --global https.proxy http://127.0.0.1:7890

查看:

bash
git config --global --list

取消:

bash
git config --global --unset http.proxy
git config --global --unset https.proxy

npm 镜像

如果 npm 下载慢,可临时使用镜像源:

bash
npm config set registry https://registry.npmmirror.com

恢复官方源:

bash
npm config set registry https://registry.npmjs.org

安装国外包失败的排查顺序

  1. 浏览器能否访问目标站。
  2. 命令行 curl 是否能访问目标站。
  3. npm / git 是否单独配置了错误代理。
  4. 公司网络或系统代理是否覆盖了终端代理。
  5. 换网络后是否恢复。

SuperAPI 文档仅用于帮助用户正确配置客户端。