欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

Homebrew及Homebrew cask安装与使用

程序员文章站 2024-03-24 17:49:40
...

安装Homebrew

安装命令:

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

如果不是第一次安装,可能会遇到如下错误:

It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"

解决方式:

sudo rm -fr /usr/local/.git

参考链接:http://*.com/questions/18555378/brew-installation-error-appears-homebrew-is-already-installed

再次安装:

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

遇到错误:

==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 3769, done.
remote: Compressing objects: 100% (3608/3608), done.
remote: Total 3769 (delta 43), reused 527 (delta 26), pack-reused 0
Receiving objects: 100% (3769/3769), 3.21 MiB | 269.00 KiB/s, done.
Resolving deltas: 100% (43/43), done.
From https://github.com/Homebrew/homebrew
 * [new branch]      master     -> origin/master
error: unable to unlink old 'Library/Homebrew/dev-cmd/aspell-dictionaries.rb' (Permission denied)
error: unable to unlink old 'Library/Homebrew/dev-cmd/update-test.rb' (Permission denied)
error: unable to unlink old 'Library/Homebrew/test/bottles/testball_bottle-0.1.el_capitan.bottle.tar.gz' (Permission denied)
error: unable to unlink old 'Library/Homebrew/test/bottles/testball_bottle-0.1.mavericks.bottle.tar.gz' (Permission denied)
error: unable to unlink old 'Library/Homebrew/test/bottles/testball_bottle-0.1.mountain_lion.bottle.tar.gz' (Permission denied)
error: unable to unlink old 'Library/Homebrew/test/bottles/testball_bottle-0.1.yosemite.bottle.tar.gz' (Permission denied)
fatal: Could not reset index file to revision 'origin/master'.
Failed during: git reset --hard origin/master

参考链接:https://github.com/Homebrew/homebrew/issues/15138

解决方式:

sudo mv /usr/local/Library /usr/local/Library.bk

再次安装即可。

安装Homebrew cask

Homebrew cask可用于mac应用程序或套件,比如mactex,xtrafinder等。

brew install caskroom/cask/brew-cask

使用Homebrew管理软件

安装软件

比如安装emacs和vim的命令分别如下。

  • 安装emacs
brew install emacs --with-cocoa --with-gnutls
  • 安装macvim
brew install macvim --with-override-system-vim
  • 安装ack和ag,比grep好用
brew install ack ag
  • 安装autojump,非常高效的目录跳转工具
brew install autojump

升级软件

  • 查看可以升级的软件
brew outdated
  • 比如升级macvim
brew upgrade macvim
  • 升级所有软件
brew upgrade

查找软件包

比如查找和pdf相关的软件包。

  • 查找和pdf相关的软件包
brew search pdf

删除软件包

  • 移除macvim
brew uninstall macvim

清除老版本的安装包

Homebrew 会缓存下载的安装包,长时间不清理会占用大量的磁盘空间,因此需要定期清理,清理命令如下:

brew cleanup