MacOS15 bash 终端怎么使用网络代理

在macOS 15版本的bash终端中配置网络代理,可以按照以下步骤进行设置:

配置步骤

1. 确定代理设置

首先,确认你的代理客户端的IP地址和端口。例如,假设你的HTTP代理为127.0.0.1:1088

2. 修改.bash_profile文件

  1. 打开终端并输入以下命令以编辑.bash_profile文件:

    bash 复制代码
    vi ~/.bash_profile
  2. 在文件末尾添加以下内容以设置代理:

    bash 复制代码
    alias proxy='export http_proxy=http://127.0.0.1:1088; export https_proxy=$http_proxy'
    alias unproxy='unset http_proxy; unset https_proxy'
  3. 保存并退出编辑器。

3. 使配置生效

在终端中运行以下命令以使更改立即生效:

bash 复制代码
source ~/.bash_profile

4. 测试代理设置

  • 使用以下命令查看当前IP地址,以确认未使用代理:

    bash 复制代码
    curl ipinfo.io
  • 启用代理:

    bash 复制代码
    proxy
  • 再次检查IP地址以确认代理是否生效:

    bash 复制代码
    curl ipinfo.io

5. 禁用代理

如果需要关闭代理,可以使用以下命令:

bash 复制代码
unproxy

附加配置(Git和NPM)

如果你还需要在Git或NPM中使用代理,请执行以下命令:

  • Git:

    bash 复制代码
    git config --global http.proxy http://127.0.0.1:1088
    git config --global https.proxy https://127.0.0.1:1088
  • NPM:

    bash 复制代码
    npm config set proxy http://127.0.0.1:1088
    npm config set https-proxy http://127.0.0.1:1088

通过这些步骤,你可以在macOS的bash终端中成功配置和使用网络代理。

Citations:

[1] https://www.hangge.com/blog/cache/detail_3138.html

[2] https://cloud.baidu.com/article/2825134

[3] https://www.cnblogs.com/oziasly/p/17100911.html

[4] https://www.cnblogs.com/ghj1976/p/macos-xia-huan-jing-bian-liang-de-pei-zhi-wen-jian.html

[5] https://blog.csdn.net/xiaxl/article/details/137552528

[6] https://blog.csdn.net/sinat_38719275/article/details/105989892

[7] https://blog.csdn.net/yang2330648064/article/details/142727271

相关推荐
2501_903238659 分钟前
Git Bash:Windows下的强大命令行工具
windows·git·bash·个人开发
神明木佑2 小时前
datalist 是什么?以及作用是什么?
git
那片海还在吗4 小时前
使用 Git、Postman、Newman、Jenkins 与邮件构建自动化接口测试及通知流程
git·jenkins·postman
heeheeai12 小时前
git 国内源
git
the_seventh_dog12 小时前
git | 团队协作开发注意事项
git
yinshuilan15 小时前
今日运维之-Mac笔记本python环境问题
运维·git·python·brew
辄也16 小时前
git拉取远程分支到本地分支
git
皮克斯的进化之路16 小时前
Git原理+使用(超详细)
git
wrjwww16 小时前
【Git学习笔记】Git常用命令
笔记·git·学习
大乔乔布斯17 小时前
WSL,Power shell 和CMD, Git bash的区别
开发语言·git·bash