• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Mac安装homebrew

武飞扬头像
UncoDong
帮助2

下载并安装homebrew的sh安装包

安装命令来自https://brew.sh/, 直接复制到命令行运行就可以

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

如果上述命令执行不了,就手动下载install.sh文件,然后在命令行之行.sh文件

遇到Permission denied问题:参考https://blog.csdn.net/weixin_41770169/article/details/86664553

执行如下命令

chmod 777 install.sh

安装完成

安装完成后可能会出现warning

Warning: /opt/homebrew/bin is not in your PATH.
  Instructions on how to configure your shell for Homebrew
  can be found in the 'Next steps' section below.

这表示brew没有被加入到环境变量中,因此需要添加环境变量

参考https://blog.csdn.net/tao_627/article/details/104856365

首先命令行执行,打开配置文件

vim ~/.bash_profile

这是用vim方式执行修改文件的命令,想要详细了解可以去搜索vim的命令用法, 我们要做的事情是

  1. 首先切换输入法到英文,点击i(表示正在insert文字)
  2. 将下述内容复制粘贴
export PATH=/opt/homebrew/bin:$PATH
  1. 首先按esc退出insert模式,然后按住shift ;输入:(表示接下来要执行命令),然后输入wq(表示执行write的命令后执行quite的命令)。这步完成后,应该退出vim模式,返回到命令行页面
  2. 执行source ~/.bash_profile使命令生效
  3. 执行brew -v查看是否有输出,有输出版本号表示安装完毕

遇到问题:mac每次打开命令行都找不到brew

因为mac命令行用的zsh,但我配置的是bash。参考https://www.jianshu.com/p/407f0f9d8203

命令行输入echo $SHELL,检查自己用的是什么,我的输出就是zsh

  • 打开vim配置文件
vim ~/.zshrc
  • 添加以下内容
if [ -f ~/.bash_profile ]; then
   source ~/.bash_profile
fi
  • 使zsh配置文件生效
source ~/.zshrc

意思就是每次调用zsh命令行的时候,都会执行一下bash_profile的配置,这样bash_profile里面的环境变量等一系列配置就都可以同步到当前命令行窗口了

修改镜像源

参考https://developer.aliyun.com/mirror/homebrew/, https://cloud.tencent.com/developer/article/1614039

查看当前源

# 查看 brew.git 当前源
# 有$打头的这一行是命令行输入
$ cd "$(brew --repo)" && git remote -v
# 下面的都表示该命令执行完成后的输出
origin    https://github.com/Homebrew/brew.git (fetch)
origin    https://github.com/Homebrew/brew.git (push)

# 查看 homebrew-core.git 当前源
$ cd "$(brew --repo homebrew/core)" && git remote -v
origin    https://github.com/Homebrew/homebrew-core.git (fetch)
origin    https://github.com/Homebrew/homebrew-core.git (push)

Bash 终端配置

    # 替换brew.git:
    cd "$(brew --repo)"
    git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
    # 替换homebrew-core.git:
    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
    # 应用生效
    brew update
    # 替换homebrew-bottles:
    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.bash_profile
    source ~/.bash_profile

Zsh 终端配置

    # 替换brew.git:
    cd "$(brew --repo)"
    git remote set-url origin https://mirrors.aliyun.com/homebrew/brew.git
    # 替换homebrew-core.git:
    cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
    git remote set-url origin https://mirrors.aliyun.com/homebrew/homebrew-core.git
    # 应用生效
    brew update
    # 替换homebrew-bottles:
    echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.aliyun.com/homebrew/homebrew-bottles' >> ~/.zshrc
    source ~/.zshrc

恢复默认配置
出于某些场景, 可能需要回退到默认配置, 你可以通过下述方式回退到默认配置。

首先执行下述命令:

# 重置brew.git:
	$ cd "$(brew --repo)"
	$ git remote set-url origin https://github.com/Homebrew/brew.git
	# 重置homebrew-core.git:
	$ cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
	$ git remote set-url origin https://github.com/Homebrew/homebrew-core.git

我是懒狗直接截图了,图源自教程https://developer.aliyun.com/mirror/homebrew/
学新通

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanhgbggce
系列文章
更多 icon
同类精品
更多 icon
继续加载