如何在MacOS上删除所有旧的和过时的brew软件包

时间:2020-01-09 10:39:35  来源:igfitidea点击:

我正在使用Homebrew在MacOS Sierra或Mac OS X上安装软件包。
我注意到在/usr/local/Cellar/bash /中安装了多个版本的bash或curl。
如何删除Brew包装包的过时版本,仅在系统上保留最新版本?
首先,打开终端应用程序。
要查看是否安装了多个版本的curl软件包,请执行:

$ ls /usr/local/Cellar/curl/

或者

$ brew info curl

输出示例:

curl: stable 7.51.0 (bottled) [keg-only]
Get a file from an HTTP, HTTPS or FTP server
https://curl.haxx.se/
/usr/local/Cellar/curl/7.50.3 (367 files, 2.6M)
  Built from source on 2015-11-02 at 03:13:19 with: --with-nghttp2
/usr/local/Cellar/curl/7.51.0 (368 files, 2.7M)
  Built from source on 2015-11-08 at 01:10:09 with: --with-nghttp2
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/curl.rb
==> Dependencies
Build: pkg-config ?
Optional: openssl ?, libidn ?, rtmpdump ?, libssh2 ?, c-ares ?, libmetalink ?, libressl ?, nghttp2 ?
==> Options
--with-c-ares
	Build with C-Ares async DNS support
--with-gssapi
	Build with GSSAPI/Kerberos authentication support.
--with-libidn
	Build with support for Internationalized Domain Names
--with-libmetalink
	Build with libmetalink support.
--with-libressl
	Build with LibreSSL instead of Secure Transport or OpenSSL
--with-libssh2
	Build with scp and sftp support
--with-nghttp2
	Build with HTTP/2 support (requires OpenSSL or LibreSSL)
--with-openssl
	Build with OpenSSL instead of Secure Transport
--with-rtmpdump
	Build with RTMP support
==> Caveats
This formula is keg-only, which means it was not symlinked into /usr/local.
 
macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
 
Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:
 
    LDFLAGS:  -L/usr/local/opt/curl/lib
    CPPFLAGS: -I/usr/local/opt/curl/include
    PKG_CONFIG_PATH: /usr/local/opt/curl/lib/pkgconfig

清理选项

cleanup选项可以删除所有已安装的或特定的公式,也可以从Homebrew下载缓存中删除所有较旧的版本。
同样,从Homebrew下载缓存中下载的旧文件也会被删除。
只需执行以下命令即可释放磁盘空间并删除过时的旧版本:

$ brew cleanup

建议您在更新后运行清理以解决旧软件包:

$ brew update && brew upgrade && brew cleanup

最后,您将在屏幕上看到以下消息:

Removing: /usr/local/Cellar/android-sdk/24.2... (1,460 files, 105.3M)
Removing: /usr/local/Cellar/android-sdk/24.4... (1,471 files, 136.4M)
Removing: /usr/local/Cellar/atk/2.20.0... (205 files, 3.1M)
Removing: /usr/local/Cellar/babl/0.1.16... (37 files, 819.1K)
Removing: /usr/local/Cellar/bash/4.3.42... (59 files, 7.3M)
Removing: /usr/local/Cellar/bash/4.3.46... (59 files, 7.3M)
Removing: /usr/local/Cellar/bash/4.4... (145 files, 8.8M)
...
..
...
Removing: /Users/veryv/Library/Logs/Homebrew/libtorrent... (1.9K)
Removing: /Users/veryv/Library/Logs/Homebrew/most... (5 files, 124.5K)
Removing: /Users/veryv/Library/Logs/Homebrew/mtr... (68B)
Removing: /Users/veryv/Library/Logs/Homebrew/nmap... (6 files, 1.6M)
Removing: /Users/veryv/Library/Logs/Homebrew/openssl... (68B)
Removing: /Users/veryv/Library/Logs/Homebrew/rsnapshot... (3 files, 10.2K)
Removing: /Users/veryv/Library/Logs/Homebrew/ssh-copy-id... (68B)
Removing: /Users/veryv/Library/Logs/Homebrew/wakeonlan... (2 files, 470B)
==> This operation has freed approximately 3.9G of disk space.

关于cask的注意事项

执行以下内容也可以清理cask:

$ brew cask cleanup

输出示例:

==> Removing cached downloads
/Users/veryv/Library/Caches/Homebrew/Cask/gimp--2.8.18-x86_64.dmg
/Users/veryv/Library/Caches/Homebrew/Cask/lisanet-gimp--2.8.14p2.dmg
/Users/veryv/Library/Caches/Homebrew/Cask/wireshark--2.2.3.dmg
/Users/veryv/Library/Caches/Homebrew/Cask/wkhtmltopdf--0.12.4.pkg
==> This operation has freed approximately 199.8M of disk space.