Browsed by
标签: macOS

macOS / OS X 如何清除 homebrew 缓存

macOS / OS X 如何清除 homebrew 缓存

MacBook Pro (13-inch, Mid 2012)

最近将老旧的 MacBook Pro (13-inch, Mid 2012) 升级到 SSD 固态硬盘,磁盘空间告急,想着 homebrew 一直使用从没有来没有清理过缓存,查询 man brew 看到 cleanup 命令如下。

cleanup [--prune=days] [--dry-run] [-s] [formulae]  
              For  all installed or specific formulae, remove any older versions from the cellar. In addition, old downloads from the Homebrew
              download-cache are deleted.

              If --prune=days is specified, remove all cache files older than days.

              If --dry-run or -n is passed, show what would be removed, but do not actually remove anything.

              If -s is passed, scrubs the cache, removing downloads for even the latest versions of formulae. Note downloads for any installed
              formulae will still not be deleted. If you want to delete those too: rm -rf $(brew --cache)

cleanup 命令会删除旧版 cellar,以及所有 brew 缓存。好吧,正是想要的。

~ brew cleanup
Removing: /usr/local/Cellar/aria2/1.20.0... (21 files, 4MB)
Removing: /usr/local/Cellar/aria2/1.30.0... (22 files, 3.9MB)
Removing: /usr/local/Cellar/aria2/1.31.0... (22 files, 3.9MB)
Removing: /usr/local/Cellar/autojump/21.6.9... (11 files, 73.9KB)
Removing: /usr/local/Cellar/autojump/22.3.0... (21 files, 246.2KB)
Removing: /usr/local/Cellar/autojump/22.5.0... (24 files, 254.0KB)
Removing: /usr/local/Cellar/cairo/1.14.2... (122 files, 6.4MB)
Removing: /usr/local/Cellar/cairo/1.14.4... (118 files, 5.9MB)
Removing: /usr/local/Cellar/cairo/1.14.6_1... (118 files, 5.9MB)
Warning: Skipping cmake: most recent version 3.8.2 not installed
Warning: Skipping homebrew/php/composer: most recent version 1.4.2 not installed
Warning: Skipping dnscrypt-proxy: most recent version 1.9.5 not installed
Warning: Skipping elasticsearch: most recent version 5.4.1 not installed
Removing: /usr/local/Cellar/ffmpeg/2.4.3... (217 files, 39.9MB)
Removing: /usr/local/Cellar/ffmpeg/2.8.1_1... (228 files, 45.4MB)
Removing: /usr/local/Cellar/ffmpeg/3.0... (230 files, 48MB)
Removing: /usr/local/Cellar/ffmpeg/3.0.1... (230 files, 47.7MB)
Removing: /usr/local/Cellar/ffmpeg/3.2.2... (239 files, 51.3MB)
Removing: /usr/local/Cellar/flow/0.22.0... (7 files, 5.7MB)
Removing: /usr/local/Cellar/flow/0.22.1... (7 files, 5.7MB)
Removing: /usr/local/Cellar/flow/0.37.4... (8 files, 5.5MB)
Removing: /usr/local/Cellar/flow/0.43.1... (8 files, 5.9MB)
Removing: /usr/local/Cellar/fontconfig/2.11.1... (449 files, 2.6MB)
Removing: /usr/local/Cellar/fontconfig/2.11.1_2... (450 files, 2.9MB)
Removing: /usr/local/Cellar/freetype/2.6.3... (61 files, 2.5MB)
Removing: /usr/local/Cellar/freetype/2.6_1... (61 files, 2.5MB)
Removing: /usr/local/Cellar/freetype/2.7... (61 files, 2.4MB)
Removing: /usr/local/Cellar/freetype/2.7.1... (62 files, 2.5MB)
Removing: /usr/local/Cellar/fribidi/0.19.7... (61 files, 373.2KB)
Removing: /usr/local/Cellar/gdbm/1.11... (17 files, 370.7KB)
Removing: /usr/local/Cellar/gdbm/1.12... (18 files, 486.9KB)
Removing: /usr/local/Cellar/gettext/0.19.3... (1,925 files, 12.7MB)
Removing: /usr/local/Cellar/gettext/0.19.4... (1,925 files, 15.7MB)
Removing: /usr/local/Cellar/gettext/0.19.6... (1,926 files, 16.4MB)
Removing: /usr/local/Cellar/gettext/0.19.7... (1,934 files, 16.7MB)
Removing: /usr/local/Cellar/ghostscript/9.16... (720 files, 57.9MB)
Removing: /usr/local/Cellar/ghostscript/9.18... (719 files, 61MB)
Removing: /usr/local/Cellar/ghostscript/9.19... (717 files, 61.4MB)
Removing: /usr/local/Cellar/ghostscript/9.21... (717 files, 64.2MB)
Removing: /usr/local/Cellar/giflib/4.2.3... (39 files, 603.4KB)
Removing: /usr/local/Cellar/git/2.12.2... (1,454 files, 33.0MB)
Removing: /usr/local/Cellar/glib/2.44.1... (421 files, 16.8MB)
Removing: /usr/local/Cellar/glib/2.46.1_1... (426 files, 22.4MB)
Removing: /usr/local/Cellar/glib/2.46.2... (426 files, 22.4MB)
Removing: /usr/local/Cellar/glib/2.50.2... (427 files, 22.4MB)
Removing: /usr/local/Cellar/glib/2.52.0... (430 files, 22.5MB)
Removing: /usr/local/Cellar/go/1.6... (5,624 files, 276.3MB)
Removing: /usr/local/Cellar/go/1.7.4_1... (6,438 files, 250.7MB)
Removing: /usr/local/Cellar/go/1.8.1... (7,030 files, 281.8MB)
Removing: /usr/local/Cellar/gobject-introspection/1.44.0... (197 files, 9.7MB)
Removing: /usr/local/Cellar/gobject-introspection/1.46.0... (199 files, 9.7MB)
Removing: /usr/local/Cellar/gobject-introspection/1.46.0_1... (221 files, 10MB)
Removing: /usr/local/Cellar/gobject-introspection/1.50.0... (172 files, 9.6MB)
Removing: /usr/local/Cellar/harfbuzz/0.9.40... (82 files, 3.2MB)
Removing: /usr/local/Cellar/harfbuzz/1.0.4... (97 files, 3.4MB)
Removing: /usr/local/Cellar/harfbuzz/1.2.1... (123 files, 4.4MB)
Removing: /usr/local/Cellar/harfbuzz/1.2.6... (123 files, 4.5MB)
Removing: /usr/local/Cellar/harfbuzz/1.3.4... (132 files, 4.5MB)
Removing: /usr/local/Cellar/icu4c/56.1... (262 files, 63.7MB)
Removing: /usr/local/Cellar/icu4c/57.1... (265 files, 65.0MB)
Removing: /usr/local/Cellar/icu4c/58.1... (242 files, 65MB)
Removing: /usr/local/Cellar/imagemagick/6.8.7-7... (1,434 files, 15.9MB)
Removing: /usr/local/Cellar/imagemagick/6.9.3-6... (1,459 files, 17.9MB)
Removing: /usr/local/Cellar/imagemagick/6.9.7-0... (1,465 files, 22.2MB)
Removing: /usr/local/Cellar/imagemagick/7.0.5-4... (1,522 files, 22.6MB)
Removing: /usr/local/Cellar/imagemagick/7.0.5-5... (1,522 files, 22.4MB)
Removing: /usr/local/Cellar/jbig2dec/0.12... (11 files, 278.9KB)
Removing: /usr/local/Cellar/ldns/1.6.17_2... (544 files, 5.5MB)
Removing: /usr/local/Cellar/libass/0.13.0... (9 files, 497.9KB)
Removing: /usr/local/Cellar/libass/0.13.2... (9 files, 502.0KB)
Removing: /usr/local/Cellar/libass/0.13.4... (10 files, 511.2KB)
Removing: /usr/local/Cellar/libevent/2.0.21... (53 files, 1.7MB)
Removing: /usr/local/Cellar/libevent/2.0.22... (53 files, 1.6MB)
Removing: /usr/local/Cellar/libffi/3.0.13... (15 files, 377KB)
Removing: /usr/local/Cellar/libgpg-error/1.17... (18 files, 291.5KB)
Removing: /usr/local/Cellar/libgpg-error/1.19... (18 files, 310.4KB)
Removing: /usr/local/Cellar/libgpg-error/1.21... (19 files, 419.4KB)
Removing: /usr/local/Cellar/libgpg-error/1.25... (20 files, 441.4KB)
Removing: /usr/local/Cellar/libksba/1.3.3... (13 files, 343.1KB)
Removing: /usr/local/Cellar/libpng/1.5.18... (23 files, 977.7KB)
Removing: /usr/local/Cellar/libpng/1.6.13... (25 files, 1.2MB)
Removing: /usr/local/Cellar/libpng/1.6.15... (25 files, 1.2MB)
Removing: /usr/local/Cellar/libpng/1.6.17... (25 files, 1.2MB)
Removing: /usr/local/Cellar/libpng/1.6.18... (25 files, 1.2MB)
Removing: /usr/local/Cellar/libpng/1.6.19... (25 files, 1.2MB)
Removing: /usr/local/Cellar/libpng/1.6.21... (25 files, 1.2MB)
Removing: /usr/local/Cellar/libpng/1.6.26... (26 files, 1.2MB)
Removing: /usr/local/Cellar/libsodium/0.5.0... (61 files, 1007.0KB)
Removing: /usr/local/Cellar/libsodium/1.0.11... (66 files, 1.1MB)
Removing: /usr/local/Cellar/libsodium/1.0.8... (64 files, 1MB)
Removing: /usr/local/Cellar/libtiff/4.0.3... (256 files, 3.4MB)
Removing: /usr/local/Cellar/libtiff/4.0.4... (259 files, 3.4MB)
Removing: /usr/local/Cellar/libtiff/4.0.6... (261 files, 3.4MB)
Removing: /usr/local/Cellar/libtiff/4.0.7... (248 files, 3.3MB)
Removing: /usr/local/Cellar/libtiff/4.0.7_2... (248 files, 3.4MB)
Removing: /usr/local/Cellar/libtiff/4.0.7_3... (248 files, 3.4MB)
Removing: /usr/local/Cellar/libtool/2.4.6... (70 files, 3.7MB)
Removing: /usr/local/Cellar/libvorbis/1.3.5... (158 files, 2.3MB)
Removing: /usr/local/Cellar/libvpx/1.4.0... (16 files, 1.4MB)
Removing: /usr/local/Cellar/libvpx/1.5.0... (16 files, 1.4MB)
Removing: /usr/local/Cellar/libvpx/1.6.0... (16 files, 1.4MB)
Removing: /usr/local/Cellar/libxml2/2.9.3... (276 files, 9.8MB)
Removing: /usr/local/Cellar/libxml2/2.9.4... (276 files, 9.8MB)
Removing: /usr/local/Cellar/libxml2/2.9.4_2... (277 files, 9.8MB)
Removing: /usr/local/Cellar/libxslt/1.1.28_1... (147 files, 3.0MB)
Removing: /usr/local/Cellar/libyaml/0.1.6_1... (8 files, 330.9KB)
Removing: /usr/local/Cellar/little-cms2/2.7... (17 files, 1MB)
Removing: /usr/local/Cellar/maven/3.2.2... (79 files, 7.8MB)
Removing: /usr/local/Cellar/maven/3.3.9... (94 files, 9.6MB)
Removing: /usr/local/Cellar/minisign/0.6_1... (4 files, 26.2KB)
Removing: /usr/local/Cellar/mongodb/3.4.0... (17 files, 261.4MB)
Removing: /usr/local/Cellar/mongodb/3.4.3... (17 files, 266.4MB)
Removing: /usr/local/Cellar/mysql/5.6.25... (9,841 files, 314.1MB)
Removing: /usr/local/Cellar/mysql/5.7.11... (12,818 files, 435MB)
Removing: /usr/local/Cellar/mysql/5.7.16... (13,511 files, 439MB)
Removing: /usr/local/Cellar/mysql/5.7.17... (321 files, 234.4MB)
Warning: Skipping nginx: most recent version 1.12.0_1 not installed
Warning: Skipping node: most recent version 8.0.0_1 not installed
Warning: Skipping openjpeg: most recent version 2.1.2_1 not installed
Removing: /usr/local/Cellar/openssl/1.0.1g... (1,229 files, 10.6MB)
Removing: /usr/local/Cellar/openssl/1.0.1h... (1,229 files, 10.4MB)
Removing: /usr/local/Cellar/openssl/1.0.1j... (1,236 files, 10.6MB)
Removing: /usr/local/Cellar/openssl/1.0.2c... (1,634 files, 12MB)
Removing: /usr/local/Cellar/openssl/1.0.2d... (1,638 files, 11.7MB)
Removing: /usr/local/Cellar/openssl/1.0.2d_1... (1,638 files, 11.7MB)
Removing: /usr/local/Cellar/openssl/1.0.2g... (1,678 files, 12.0MB)
Removing: /usr/local/Cellar/openssl/1.0.2j... (1,695 files, 12MB)
Removing: /usr/local/Cellar/openssl/1.0.2k... (1,696 files, 12MB)
Removing: /usr/local/Cellar/[email protected]/1.1.0e... (6,303 files, 15.4MB)
Warning: Skipping pango: most recent version 1.40.6 not installed
Warning: Skipping passenger: most recent version 5.1.4 not installed
Removing: /usr/local/Cellar/pcre/8.37... (203 files, 5.3MB)
Removing: /usr/local/Cellar/pcre/8.38... (203 files, 5.4MB)
Removing: /usr/local/Cellar/pcre/8.39... (203 files, 5.4MB)
Warning: Skipping pdf2htmlex: most recent version 0.14.6_14 not installed
Warning: Skipping homebrew/php/php-cs-fixer: most recent version 2.3.2 not installed
Removing: /usr/local/Cellar/php55/5.5.30... (328 files, 48.0MB)
Removing: /usr/local/Cellar/php55/5.5.32... (328 files, 48.0MB)
Warning: Skipping homebrew/php/php55-mcrypt: most recent version 5.5.38 not installed
Warning: Skipping homebrew/php/php70: most recent version 7.0.19_11 not installed
Warning: Skipping homebrew/php/php71: most recent version 7.1.5_17 not installed
Removing: /usr/local/Cellar/pixman/0.32.6... (12 files, 1.4MB)
Removing: /usr/local/Cellar/pixman/0.32.8... (12 files, 1.2MB)
Removing: /usr/local/Cellar/pkg-config/0.29... (10 files, 625.4KB)
Removing: /usr/local/Cellar/pkg-config/0.29.1... (10 files, 627.2KB)
Removing: /usr/local/Cellar/pkg-config/0.29.1_2... (10 files, 627.5KB)
Warning: Skipping poppler: most recent version 0.55.0 not installed
Warning: Skipping postgresql: most recent version 9.6.3 not installed
Removing: /usr/local/Cellar/python3/3.5.1... (3,543 files, 52.7MB)
Removing: /usr/local/Cellar/python3/3.5.2_3... (7,720 files, 109.4MB)
Removing: /usr/local/Cellar/rbenv/0.4.0... (32 files, 49.8KB)
Removing: /usr/local/Cellar/rbenv/1.0.0... (36 files, 61.9KB)
Removing: /usr/local/Cellar/readline/6.3.8... (46 files, 2MB)
Removing: /usr/local/Cellar/readline/7.0.1... (46 files, 2MB)
Warning: Skipping ruby-build: most recent version 20170523 not installed
Removing: /usr/local/Cellar/scons/2.4.1... (408 files, 3.7MB)
Removing: /usr/local/Cellar/sqlite/3.11.0... (10 files, 2.8MB)
Removing: /usr/local/Cellar/sqlite/3.11.0_1... (10 files, 2.8MB)
Removing: /usr/local/Cellar/sqlite/3.12.0... (10 files, 2.8MB)
Removing: /usr/local/Cellar/sqlite/3.15.2... (11 files, 2.9MB)
Removing: /usr/local/Cellar/sqlite/3.18.0... (11 files, 3.0MB)
Removing: /usr/local/Cellar/sqlite/3.7.15.2... (11 files, 1.9MB)
Removing: /usr/local/Cellar/sqlite/3.8.2... (10 files, 2.0MB)
Removing: /usr/local/Cellar/ssh-copy-id/6.6p1... (7 files, 164.2KB)
Removing: /usr/local/Cellar/ssh-copy-id/7.1p1... (7 files, 335KB)
Removing: /usr/local/Cellar/ssh-copy-id/7.2p2... (7 files, 310.4KB)
Removing: /usr/local/Cellar/ssh-copy-id/7.3p1... (8 files, 309.2KB)
Removing: /usr/local/Cellar/tag/0.7.5... (4 files, 46.2KB)
Removing: /usr/local/Cellar/tag/0.8.1... (4 files, 49.6KB)
Removing: /usr/local/Cellar/texi2html/1.82... (108 files, 2MB)
Warning: Skipping tomcat: most recent version 8.5.15 not installed
Removing: /usr/local/Cellar/tree/1.6.0... (7 files, 96.7KB)
Removing: /usr/local/Cellar/ttfautohint/1.3... (8 files, 250.7KB)
Removing: /usr/local/Cellar/ttfautohint/1.5... (8 files, 266KB)
Removing: /usr/local/Cellar/unison/2.48.3... (6 files, 3.6MB)
Removing: /usr/local/Cellar/unixodbc/2.3.2_1... (34 files, 954.8KB)
Warning: Skipping unrar: most recent version 5.5.3 not installed
Removing: /usr/local/Cellar/watchman/3.9.0... (17 files, 254.0KB)
Removing: /usr/local/Cellar/watchman/4.4.0... (22 files, 386.2KB)
Warning: Skipping wget: most recent version 1.19.1_1 not installed
Removing: /usr/local/Cellar/wxmac/3.0.2... (812 files, 39.5MB)
Removing: /usr/local/Cellar/wxmac/3.0.2_2... (809 files, 23.7MB)
Removing: /usr/local/Cellar/x264/r2601... (10 files, 3.3MB)
Removing: /usr/local/Cellar/x264/r2728... (11 files, 3.3MB)
Removing: /usr/local/Cellar/xz/5.2.1... (91 files, 1.4MB)
Removing: /usr/local/Cellar/xz/5.2.2... (91 files, 1.4MB)
Warning: Skipping yarn: most recent version 0.24.6 not installed
Removing: /usr/local/Cellar/yasm/1.3.0... (44 files, 3.1MB)
Warning: Skipping youtube-dl: most recent version 2017.05.29 not installed
Removing: /usr/local/Cellar/zlib/1.2.8... (11 files, 361.6KB)
==> This operation has freed approximately 4.4GB of disk space.

清理出 4.4G 空间,大功告成。

(完)

使用 Homebrew 完成 macOS 10.12 Sierra 下 PHP 多版本切换

使用 Homebrew 完成 macOS 10.12 Sierra 下 PHP 多版本切换

之前的文章我们已经通过 brew 成功安装 Apache 2.4 接下来,我们继续安装 PHP。通过以下命令分别安装多个版本。

$ brew install php55 --with-httpd24 
$ brew unlink php55 
$ brew install php56 --with-httpd24 
$ brew unlink php56 
$ brew install php70 --with-httpd24 
$ brew unlink php70 
$ brew install php71 --with-httpd24

执行完成后四个版本的 PHP 位于下列位置:

/usr/local/Cellar/php55/
/usr/local/Cellar/php56/
/usr/local/Cellar/php70/
/usr/local/Cellar/php71/

接下来我们安装 sphpsphp 可以方便切换 PHP 版本,官方网址 https://github.com/sgotre/sphp-osx

# 下载到本地目录
curl -L https://raw.githubusercontent.com/sgotre/sphp-osx/master/sphp > /usr/local/bin/sphp

# 添加可执行权限
chmod +x /usr/local/bin/sphp

在运行 sphp 之前确保 /usr/local/bin 添加到 $PATH,通过以下命令进行检查:

echo $PATH | grep '/usr/local/bin' 

出现以下结果则为正常

如果未出现,请使用以下命令:

# Terminal
echo 'export PATH="/usr/local/bin:$PATH"' >> $HOME/.bashrc
# iTerm
echo 'export PATH="/usr/local/bin:$PATH"' >> $HOME/.zshrc

现在通过以下命令完成 PHP 版本切换:

sphp 55
sphp 56
sphp 70
sphp 70
使用 Homebrew macOS 10.12 Sierra 下安装 Apache 2.4

使用 Homebrew macOS 10.12 Sierra 下安装 Apache 2.4

先确认安装 xcode 命令行工具集,执行一次如下命令

xcode-select --install

如果之前已经安装会得到错误信息如下:

xcode-select: error: command line tools are already installed, use "Software Update" to install updates

安装 Homebrew

因为接下来我们全程都需要使用 brew 来完成,通过以下命令安装:

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

如果之前安装过 brew,通过查下版本信息并更新

# 查看 brew 版本信息
brew -v
# brew 自检,确保配制正确
brew doctor
# brew 信息更新
brew update

到此,brew 已经准备就绪。

安装 Apache

macOS 10.12 Sierra 系统有预装 Apache 2.4,但有一些功能被移除会导致使用起来有这样那样的问题。我们使用 Homebrew 安装标准版 Apache 2.4 并且运行与标准的 80/443 端口。所有这些操作需要先停止运行中的 Apache,删除系统原有自启动项,系列命令如下:

sudo apachectl stop
sudo launchctl unload -w /System/Library/LaunchDaemons/org.apache.httpd.plist 2>/dev/null
brew install httpd24 --with-privileged-ports --with-http2

至此,已经将最新版本的 Apache 2.4.25 (作者写作时 Apache 的版本) 安装以下目录:

/usr/local/Cellar/httpd24/2.4.25/

接下来比较操作将新安装的 Apache 设置为随系统启动。


sudo cp -v /usr/local/Cellar/httpd24/2.4.25/homebrew.mxcl.httpd24.plist /Library/LaunchDaemons
sudo chown -v root:wheel /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
sudo chmod -v 644 /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist
sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.httpd24.plist

至此,打开浏览器会看到如下画面,Apache 已正常工作。

通过命令行得到的 Apache 版本信息。

httpd -v
Server version: Apache/2.4.25 (Unix)
Server built:   Jan 11 2017 20:47:08