Eric's blog

随笔记录

macOS 终端、NPM、Go、Git配置代理

一、配置终端代理

zsh 是 mac Catalina 及更高版本中的默认终端

1、临时使用

终端输入:

1
export all_proxy=http://127.0.0.1:8123

测试本地IP:

1
curl ipinfo.io

2、长期使用

1
vi ~/.zshrc

最后一行写入配置

1
2
alias proxy='export all_proxy=http://127.0.0.1:8123'
alias unproxy='unset all_proxy'

执行配置文件生效命令

1
source ~/.zshrc

开启、关闭代理

1
proxy
1
unproxy

二、配置 NPM 代理

设置代理

1
2
3
npm config set proxy http://127.0.0.1:8123
npm config set https-proxy http://127.0.0.1:8123
npm config set strict-ssl false

取消代理

1
2
npm config delete proxy
npm config delete https-proxy

三、GO 代理

Go 1.13 及以上(推荐)

一次配置一直有效

1
2
go env -w GO111MODULE=on
go env -w GOPROXY=https://goproxy.cn,direct

四、其他的

Bash 终端

Bash 是 macOS Mojave 及更低版本中的默认终端

临时使用:

1
export http_proxy=http://127.0.0.1:8123;export https_proxy=$http_proxy

参考文档:

  1. macOS系统Terminal 终端配置端口/GIT/NPM代理