【原创】MacOS 安装 homebrew-cask

安装准备

1、简介

早期的 Homebrew 只能管理命令行工具,而 GUI 的界面软件不支持,不过早期有专门针对 GUI 管理的 brew 扩展,叫做 caskroom。

原先 caskroom 是 github 上一个独立的库,是对 homebrew 功能的扩展。不过现在已经合并到 homebrew 中了。也就是说安装了 homebrew 最新版本,你就具备了 brew 与 brew cask 的功能。

2、安装环境

MacOS 10.15.6
brew 0.9.5 +

3、注意事项

homebrew cask 是 homebrew 0.9.5 版本以后从 caskroom cask 合并到 homebrew 中的

homebrew-cask 的 github 页面写的是要使用 Homebrew Cask,你只需要安装了 Homebrew 即可。

确实,brew cask 命令已经被集成在 brew.sh,但 brew –help 命令中还没有 cask 命令,使用 man brew 可以查看到。而且,第一次使用 brew cask 时会自动从 github tap homebrew/cask 到本地。

安装步骤

1、安装

brew tap homebrew/cask

示例:

jiangzhuolin@bogon homebrew % brew tap homebrew/cask
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
jiangzhuolin@bogon homebrew % brew cask 
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 124, done.
remote: Counting objects: 100% (124/124), done.
remote: Compressing objects: 100% (75/75), done.
remote: Total 479896 (delta 66), reused 74 (delta 49), pack-reused 479772
Receiving objects: 100% (479896/479896), 216.41 MiB | 2.80 MiB/s, done.
Resolving deltas: 100% (340477/340477), done.
Tapped 1 command and 3657 casks (3,777 files, 232MB).
Usage: brew cask command [options] [cask]
Homebrew Cask provides a friendly CLI workflow for the administration of macOS
applications distributed as binaries.

上面的命令将会从 github 的 homebrew-cask 仓库克隆代码,并在本地创建一个 repo,repo 位置位于

jiangzhuolin@bogon homebrew-cask % pwd
/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask

注:也可以不使用上面的命令进行安装,我们可以直接使用 brew cask –help 或者 brew cask install atom 这样的命令,brew 会自动执行上面的 brew tap homebrew/cask 这个过程。

2、配置 homebrew-cask 清华镜像源

在命令行执行如下命令即可

jiangzhuolin@bogon homebrew-cask % git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

验证是否设置成功:

jiangzhuolin@bogon homebrew-cask % git -C "$(brew --repo homebrew/cask)" remote get-url origin
https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

3、更新 brew

brew update

运行验证

1、查看 brew cask

jiangzhuolin@bogon ~ % brew --version
Homebrew 2.5.1
Homebrew/homebrew-core (git revision 096ba; last commit 2020-09-16)
Homebrew/homebrew-cask (git revision bc22ba; last commit 2020-09-16)

安装 homebrew-cask 后,通过  brew –version 命令能够查看到 homebrew-cask 相关的信息

2、常用命令

(1) 查看指定应用信息

brew cask info

示例

jiangzhuolin@bogon ~ % brew cask info atom
atom: 1.51.0 (auto_updates)
https://atom.io/
Not installed
From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
==> Name
Github Atom
==> Description
Cross-platform text editor
==> Artifacts
Atom.app (App)
/Applications/Atom.app/Contents/Resources/app/apm/bin/apm (Binary)
/Applications/Atom.app/Contents/Resources/app/atom.sh -> atom (Binary)
==> Analytics
install: 3,830 (30 days), 11,179 (90 days), 56,492 (365 days)

(2) brew cask 安装 atom

brew cask install atom

示例:

jiangzhuolin@bogon homebrew-cask % brew cask install atom
==> Downloading https://github.com/atom/atom/releases/download/v1.51.0/atom-mac.zip
==> Downloading from https://github-production-release-asset-2e65be.s3.amazonaws.com/3228505/2b732e00-f22
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'atom'.
==> Installing Cask atom
==> Moving App 'Atom.app' to '/Applications/Atom.app'.
==> Linking Binary 'apm' to '/usr/local/bin/apm'.
==> Linking Binary 'atom.sh' to '/usr/local/bin/atom'.
🍺  atom was successfully installed!

(3) 卸载

brew cask uninstall

示例:

jiangzhuolin@bogon homebrew-cask % brew cask uninstall atom
==> Uninstalling Cask atom
==> Backing App 'Atom.app' up to '/usr/local/Caskroom/atom/1.51.0/Atom.app'.
==> Removing App '/Applications/Atom.app'.
==> Unlinking Binary '/usr/local/bin/apm'.
==> Unlinking Binary '/usr/local/bin/atom'.
==> Purging files for version 1.51.0 of Cask atom

(4) 更新

brew cask upgrade atom    # 已过时
brew upgrade --cask atom    # 推荐用法

示例:

jiangzhuolin@bogon homebrew-cask % brew upgrade --cask atom
Updating Homebrew...

(5) 查看安装的应用

brew cask list    # 已过时
brew list --cask    # 推荐用法

示例:

jiangzhuolin@bogon homebrew-cask % brew list --cask
atom                                                           maccy                                                          xquartz

附录

1、caskroom 安装的 cask 过时的解决方法

如果你以前通过 brew tap caskroom/cask 的方式安装过

你本地会有这个目录 

/usr/local/Homebrew/Library/Taps/caskroom/homebrew-cask

brew –version 的结果可能会是这样

➜  homebrew-cask git:(master) brew --version
Homebrew 2.5.1
Homebrew/homebrew-core (git revision a4241; last commit 2020-09-16)
Homebrew/homebrew-cask (no git repository)

运行 brew doctor 会得到如下信息:

➜  homebrew-cask git:(master) brew doctor
Warning: You have the following deprecated, cask taps tapped:
  caskroom/cask
Untap them with `brew untap`.

使用 untap 删除它

➜  homebrew-cask git:(master) brew untap caskroom/cask
Untapping caskroom/cask...
Untapped 1 command and 3657 casks (3,790 files, 235.9MB).

然后就发现 /usr/local/Homebrew/Library/Taps/ 目录下的 caskroom 目录已经没了。

如果你发现你的 /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask 目录是空目录,请执行如下命令:

➜  homebrew-cask git:(master) brew untap homebrew/cask

再执行

➜  homebrew git:(stable) brew tap homebrew/cask  
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 13, done.
remote: Counting objects: 100% (13/13), done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 479921 (delta 5), reused 0 (delta 0), pack-reused 479908
Receiving objects: 100% (479921/479921), 216.56 MiB | 4.74 MiB/s, done.
Resolving deltas: 100% (340504/340504), done.
Tapped 1 command and 3657 casks (3,777 files, 232.2MB).

一切正常

➜  homebrew-cask git:(master) brew --version        
Homebrew 2.5.1
Homebrew/homebrew-core (git revision a4241; last commit 2020-09-16)
Homebrew/homebrew-cask (git revision d7d7d; last commit 2020-09-16)

2、参考

homecask github 地址:

https://github.com/Homebrew/homebrew-cask

caskroom github repo 地址:

https://github.com/Caskroom/caskroom.github.io

清华大学镜像站:

https://mirrors.tuna.tsinghua.edu.cn/help/homebrew/

You may also like...

发表评论

电子邮件地址不会被公开。 必填项已用*标注

%d 博主赞过: