抱歉,您的浏览器无法访问本站
本页面需要浏览器支持(启用)JavaScript
了解详情 >

最近在使用 brew 安装一些软件时发现速度太慢,而且不少因为超时问题而无法安装。然后查了很多网友提供的方法,发现大多都已经用不了或者是有些细微处有所错误,故此重新写一篇 macOS 终端实现🪜

配置🪜

过程省略
假设最终获得端口 HTTP 127.0.0.1:1087

终端配置🪜

在命令行输入执行以下两条指令

1
2
export http_proxy=http://127.0.0.1:1087
export https_proxy=http://127.0.0.1:1087

macOS 版的默认监控本地的HTTP端口是 1087,而 Windows 版本的则是 1080,如果改过默认端口,就使用你指定的端口
这样就完成终端翻墙了,当然我们每次翻墙都执行一次指令会比较麻烦,把指令写进 .bash_profile 方便以后操作。

终端🪜写进 .bash_profile

1
vim ~/.bash_profile

如果之前没有配置过会出现新建
进入 .bash_profile,在最后加上以下代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
function proxy_on(){
export http_proxy=http://127.0.0.1:1087
export https_proxy=http://127.0.0.1:1087
echo -e "已开启🪜"
}
function proxy_off(){
unset http_proxy
unset https_proxy
echo -e "已关闭🪜"
}


#全局🪜Chrome
function proxy_chrome(){
open -a /Applications/Google\ Chrome.app/ --args --proxy-server=socks5://127.0.0.1:1080
echo -e "已🪜Google Chrome"
}

#直查IP
function myip(){
curl -L tool.lu/ip
}

输入以下命令使该配置文件生效

1
source ~/.bash_profile

使用 proxy 前先查看下当前的 ip 地址

1
2
3
curl -L tool.lu/ip
当前 IP:103.202.xxx.xx
来自:北京市

之后开启 proxy,再查看

1
2
proxy_on
已开启🪜

1
2
3
curl ip.cn
当前 IP:103.88.xxx.xx
来自:XX

不需要🪜的时候再执行 proxy_off 关闭🪜

1
2
proxy_off
已关闭🪜

自己在 ~/.bash_profile 中配置环境变量, 可是每次重启终端后配置的不生效.需要重新执行 : $source ~/.bash_profile

发现zsh加载的是~/.zshrc文件,而 .zshrc 文件中并没有定义任务环境变量。

解决办法

~/.zshrc文件最后,增加一行:
source ~/.bash_profile
如果没有则新建 在~ home文件夹 显示.开头的文件command + shift + .

评论