Homebrew 是最简单和灵活的方式,用来在 Mac OS X 安装 Linux 工具包。
Homebrew 国内高速安装脚本:HomebrewCN: Homebrew 国内安装脚本
安装过程很简单:
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
HomeBrew是ruby脚本,但是mac下不需要安装ruby解释环境,系统自带了。
安装好后,可以:
brew –v
通过检查homebrew版本确认是否安装成功。
使用homebrew安装wget:
brew install wget
可能遇到‘fatal: not in a git directory=’的问题:
==> Fetching dependencies for wget: libunistring, gettext, libidn2, ca-certificates and openssl@3
==> Fetching libunistring
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/libunistring-1.1.ve
######################################################################## 100.0%
==> Fetching gettext
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/gettext-0.21.1.vent
######################################################################## 100.0%
==> Fetching libidn2
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/libidn2-2.3.4_1.ven
######################################################################## 100.0%
==> Fetching ca-certificates
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/ca-certificates-202
######################################################################## 100.0%
==> Fetching openssl@3
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/openssl%403-3.0.8.v
######################################################################## 100.0%
==> Fetching wget
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/wget-1.21.3_1.ventu
######################################################################## 100.0%
==> Installing dependencies for wget: libunistring, gettext, libidn2, ca-certificates and openssl@3
==> Installing wget dependency: libunistring
fatal: not in a git directory
Error: Command failed with exit 128: git
运行brew -v命令,看到提示:
Homebrew 4.0.1-60-g6ad9294
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core'
To add an exception for this directory, call:
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
Homebrew/homebrew-core (no Git repository)
fatal: detected dubious ownership in repository at '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'
To add an exception for this directory, call:
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
Homebrew/homebrew-cask (no Git repository)
按照提示分别执行:
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
git config --global --add safe.directory /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask
再次运行brew -v命令,看到提示:
Homebrew 4.0.1-60-g6ad9294
Homebrew/homebrew-core (git revision d65938832c3; last commit 2023-02-19)
Homebrew/homebrew-cask (git revision 8a41398bb1; last commit 2023-02-19)
brew可以正常安装了。
使用国内的源时可能遇到的问题
详见:Homebrew国内如何自动安装(国内地址)(Mac & Linux) - 知乎
1.error: could not lock config file .git/config: Permission denied
Error: Command failed with exit 255: git
error: could not lock config file .git/config: Permission denied
Error: Command failed with exit 255: git
解决办法:
sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local
执行时会报目录没权限,不必理会!!!