0%

homebrew介绍

homebrew简介

homebrew类似于QQ软件管家,方便我们安装卸载第三方软件。当然这里的软件指的是命令行软件,而不是我们通常使用的应用软件。

安装homebrew

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

通过homebrew安装的软件目录位置

1
/usr/local/Cellar

/usr/local/bin目录下的文件则是Cellar下对应软件的一个快捷访问。

homebrew使用

1.安装软件

1
brew install xxx

eg:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
➜  ~ brew install wget
==> Downloading https://formulae.brew.sh/api/formula.jws.json
######################################################################### 100.0%
==> Downloading https://formulae.brew.sh/api/cask.jws.json
######################################################################### 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/wget/manifests/1.21.4
######################################################################### 100.0%
==> Fetching wget
==> Downloading https://ghcr.io/v2/homebrew/core/wget/blobs/sha256:3def758612b33
######################################################################### 100.0%
==> Pouring wget--1.21.4.sonoma.bottle.tar.gz
🍺 /usr/local/Cellar/wget/1.21.4: 91 files, 4.4MB
==> Running `brew cleanup wget`...
Disable this behaviour by setting HOMEBREW_NO_INSTALL_CLEANUP.
Hide these hints with HOMEBREW_NO_ENV_HINTS (see `man brew`).

...
➜ ~ wget -V
GNU Wget 1.21.4 在 darwin23.0.0 上编译。

2.卸载软件

1
brew uninstall xxx

3.查看使用homebrew安装的二进制软件

1
brew list

例如:

1
2
3
4
5
6
7
brew list
==> Formulae
abseil gettext libunistring openssl@3 sqlite
brotli icu4c libuv protobuf swift-protobuf
c-ares inetutils libyaml python@3.11 telnet
ca-certificates libidn2 mpdecimal readline wget
cocoapods libnghttp2 nvm ruby xz

4.升级homebrew自身

1
brew update --verbose

5.升级安装的二进制软件

1
brew upgrade xxx

eg:

1
brew upgrade cocoapods

1.安装了两个homebrew

不知道什么原因电脑里安装了两个homebrew,然后每个homebrew下又都安装了一些软件。

1
2
/usr/local/Homebrew
/opt/homebrew

然后zsh里面,优先使用的是/opt/homebrew的homebrew。

1
2
3
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/opt/homebrew/bin/brew shellenv)"
eval "$(/usr/local/bin/brew shellenv)"

导致在升级一些软件时提示已经升级了,但查看版本时还是旧的,原因就是升级的是另一个homebrew下的,而/opt/homebrew下的还是旧版本的。所以打算删除掉/opt目录下的。

卸载/opt/homebrew下的homebrew

1.先备份要删除的/opt/homebrew。后续确定没问题了再彻底删除。

2.修改.zprofile 的内容为:

1
2
# Set PATH, MANPATH, etc., for Homebrew.
eval "$(/usr/local/bin/brew shellenv)"

即删除掉之前/opt/homebrew的。

3.查看where brew,应该只剩下一个了。

1
2
3
  ~ where brew
/usr/local/bin/brew
/usr/local/bin/brew

删除后有一些软件可能得重新安装了,比如之前安装的hexo命令提示没了。

重新安装hexo:

1
npm install -g hexo-cli

参考

homebrew官网

一些使用homebrew的经验

觉得文章有帮助可以打赏一下哦!