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

相关推荐
摇滚侠4 小时前
GIT版本管理工具轻松入门 | TortoiseGit,解决冲突,笔记07
笔记·git
一点事9 小时前
windows:git下载安装
git
不说别的就是很菜10 小时前
【前端面试】Git篇
前端·git
~~李木子~~18 小时前
通过git上传项目到码云和GitHub操作手册
git·gitee·github
songyuc20 小时前
【Git】请帮忙解释一下“git reset”
git·elasticsearch
Komorebi_99991 天前
使用Git创建自己的分支的操作指南
git
~~李木子~~1 天前
git仓库管理
git
秦jh_1 天前
【git】远程操作
git
tianming20191 天前
Gogs迁移到Gitea不完全指南
git·后端
QT 小鲜肉1 天前
【Git、GitHub、Gitee】GitLab的概念、注册流程、远程仓库操作以及高级功能详解(超详细)
git·qt·gitee·gitlab·github