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

相关推荐
高调的涵涵3 天前
删了1.2GB,.git仍是1.2GB
git
程序员沉梦听雨3 天前
【Git】git-submodule子模块管理
git
全栈陈序员4 天前
Git】从入门到精通(八)—— git log:查看提交历史
大数据·git·elasticsearch
7177774 天前
Git自建用什么工具比较好:Gitea、Forgejo、GitLab CE与Gitee的选型对比
git·gitlab·gitea
lsc_blog5 天前
年底还在招的岗位,先确认缺口和到岗要求
git·缓存·ci/cd·职场和发展·github
全栈陈序员5 天前
【Git】从入门到精通(十一)—— git reset 三种模式详解
git·elasticsearch
全栈陈序员5 天前
【Git】从入门到精通(十)—— 撤销与恢复:git checkout与git restore
运维·网络·数据库·git
全栈陈序员5 天前
【Git】从入门到精通(五)—— git add:将文件加入暂存区
大数据·git·elasticsearch
全栈陈序员6 天前
【Git】从入门到精通(七)—— git status:查看仓库状态
大数据·git·elasticsearch
莫晓燚6 天前
Ansible 13 个常用模块---企业实战
git·github