Mac电脑上安装Homebrew工具


Homebrew 安装还是比较烦的,主要是要找对安装方式,如果你直接用官网上给的安装命令,那你将注定失败。

1. Homebrew 安装技巧

官网上的安装地址是不能用的,几乎是百分百报错,改为用下面的命令安装,但是安装之前需要想办法把 git 安装上,因为安装包需要通过 git 拉取,用到 git 命令。

/bin/zsh -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

从给的链接就能看的出来,这个是中国的安装源,就连仓库都是用的码云,而不是 github,杠杠的给力。按照引导步骤一步一步安装即可。

2. Homebrew 扫尾工作

上面安装完,还没到万事大吉的程度,还需要检查一下 HomeBrew 有没有安装成功。需要重启一下终端或者应用一下配置文件(安装成功后有提示),我选择重启,简单粗暴

执行命令brew -v,可能有一下的日志内容。


Homebrew 4.0.10-80-gbe7091b
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:

	git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/opt/homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:

	git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)

如果有以上的内容,就需要手动配置一下 git,如果没有可以忽略。直接执行上面给定的两条 git 配置命令即可。

git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-core

git config --global --add safe.directory /opt/homebrew/Library/Taps/homebrew/homebrew-cask

执行结束后,可以用brew -v命令再检查一下。结果如下,表示配置成功,可以正常使用喽!

Homebrew/homebrew-core (git revision ab34ea291b0; last commit 2023-03-30)
Homebrew/homebrew-cask (git revision cf23e88a8f; last commit 2023-03-30)

3. brew 安装 nginx 出现的问题和解决方案

出现的问题:

在使用brew install nginx时,执行到最后报错,报错信息如下:

fatal: not in a git directory
Error: Command failed with exit 128: git

解决方案:

其实很简单,就是上面 Homebrew 扫尾工作没有做好,按照上面的说明做好了,在重新安装即可。

安装后的目录:(仅供参考)

nginx 默认安装配置文件地址:/opt/homebrew/etc/nginx/nginx.conf
启动脚本文件:/opt/homebrew/opt/nginx/bin/nginx


文章作者: 程序猿洞晓
版权声明: 本博客所有文章除特別声明外,均采用 CC BY 4.0 许可协议。转载请注明来源 程序猿洞晓 !
评论
  目录