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

相关推荐
_codemonster16 分钟前
.git文件夹里所有文件详解
git
01杭呐1 小时前
一次错误分支合并导致 `master` 变脏的排查与修复
git
_codemonster1 小时前
git本地以及github查看历史版本、版本回退
git·github
周小码12 小时前
10分钟搭建私有Git服务器:Soft Serve实战
运维·服务器·git
梅塔文·欧帕西安卡琼21 小时前
git的底层原理详解
git
待什么青丝21 小时前
【git的摸鱼技巧】之工欲善其事
git·elasticsearch·搜索引擎
2601_961194021 天前
高中英语教资资料推荐|科三大题背诵和教学设计模板
git·开源·github·开源软件·开源协议·ossinsight
ting94520001 天前
InsForge Backend Branching 后端全链路 Git 式分支技术原理、架构实现与底层源码剖析
人工智能·git·elasticsearch·架构
程序猿阿伟1 天前
《扣子如何让OpenClaw技能开发提速》
人工智能·git·github
摇滚侠1 天前
IDEA 创建 Java 项目 推送到远程 Git 仓库
java·git·intellij-idea