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

相关推荐
bubiyoushang8881 小时前
解决 Git 访问 GitHub 时的 SSL 错误
git·github·ssl
海码0075 小时前
【版本控制】Git 和 GitHub 入门教程
git·github
网硕互联的小客服8 小时前
503 Service Unavailable:服务器暂时无法处理请求,可能是超载或维护中如何处理?
服务器·git·github
abcnull10 小时前
github开源协议选择
git·github·开源协议
安庆平.Я12 小时前
git互联GitHub 使用教程
git·github
自来也_19 小时前
Git配置代理
git
Jooolin1 天前
【编程史】Git是如何诞生的?这可并非计划之中...
linux·git·ai编程
Lw老王要学习2 天前
VScode 使用 git 提交数据到指定库的完整指南
windows·git·vscode
去旅行、在路上2 天前
Git & Svn
git·svn
abcnull2 天前
github中main与master,master无法合并到main
git·github