网络与代理
命令行代理
如果 npm、git、curl 访问国外资源失败,可以临时设置代理。
先测试:
bash
curl https://www.google.commacOS / Linux:
bash
export http_proxy=http://127.0.0.1:7890
export https_proxy=http://127.0.0.1:7890Windows PowerShell:
powershell
$env:http_proxy="http://127.0.0.1:7890"
$env:https_proxy="http://127.0.0.1:7890"端口以本机代理软件为准
示例使用 7890,如果你的代理软件使用 7897、10809 或其他端口,需要替换成实际端口。
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.proxynpm 镜像
如果 npm 下载慢,可临时使用镜像源:
bash
npm config set registry https://registry.npmmirror.com恢复官方源:
bash
npm config set registry https://registry.npmjs.org安装国外包失败的排查顺序
- 浏览器能否访问目标站。
- 命令行
curl是否能访问目标站。 - npm / git 是否单独配置了错误代理。
- 公司网络或系统代理是否覆盖了终端代理。
- 换网络后是否恢复。