如何为 Git, npm,Yarn 设置代理
2020/5/17 8:26:19
本文主要是介绍如何为 Git, npm,Yarn 设置代理,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
如何为 Git, npm,Yarn 设置代理
1. 前言
我有时候会对一些科学的设置进行改动,然后会发现自家的 Git, npm,Yarn 运行会报类似如下这些错误:
- unable to access ‘…’
- Couldn’t resolve host ‘…’
- FetchError ‘…’
- connect ECONNREFUSED ‘…’
有时候确实是网络差,但大部分时候都是因为我们使用的代理设置修改了,而这些应用却没改。
下面我们来看看如何对 Git, npm,Yarn 进行代理设置。
注意哦,下面的的端口只是举例,大家需要改为自家的端口。
2. Git
2.1 设置命令
git config --global https.proxy http://127.0.0.1:1087 git config --global http.proxy http://127.0.0.1:1087
上述命令是走 HTTP 代理。
如果你用Shadowsocks,那么还可以试一下走 socks5 代理,命令如下:
git config --global http.proxy 'socks5://127.0.0.1:1087' git config --global https.proxy 'socks5://127.0.0.1:1087'
使用 socks5 的话,速度也会有所提升。
2.2 查看命令
git config --global --get http.proxy git config --global --get https.proxy
如果没有设置代理,上述命令将什么也不会打印。
2.3 取消命令
git config --global --unset http.proxy git config --global --unset https.proxy
3. Yarn
3.1 设置命令
yarn config set https-proxy http://127.0.0.1:1087 yarn config set proxy http://127.0.0.1:1087
3.2 查看命令
yarn config list
3.3 取消命令
yarn config delete proxy yarn config delete https-proxy
4. npm
4.1 设置命令:
npm config set proxy http://127.0.0.1:1087 npm config set https-proxy http://127.0.0.1:1087
4.2 查看命令
npm config list
4.2 取消命令:
npm config delete proxy npm config delete https-proxy
总结
ok,其实还是蛮简单的,它们各自的文档也有对应说明,这里只是做个汇总,有任何问题欢迎在评论中提出。
这篇关于如何为 Git, npm,Yarn 设置代理的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-09-19环境变量处理课程:新手入门教程
- 2024-09-19接口模块封装课程:新手入门指南
- 2024-09-19请求动作封装课程:新手入门教程
- 2024-09-19拖拽表格课程:新手入门指南
- 2024-09-19页面权限课程:新手必学的权限管理入门教程
- 2024-09-19如何正确主动登出课程:新手必读教程
- 2024-09-19Element-Plus课程:新手入门与初级教程
- 2024-09-19Token处理入门教程:新手必看指南
- 2024-09-19如何应对被动登出课程的情况:新手必读指南
- 2024-09-19打包优化课程:初学者的必备指南