title | date | categories | tags | |||||
---|---|---|---|---|---|---|---|---|
Homebrew--MAC下包管理工具和软件安装工具 |
2015-08-11 11:27 |
|
|
Homebrew 是MAC下的包管理工具,可以当做debian
下的apt-get
,但要强大得多。它尽可能的利用系统自带库,大大缩短编译时间;冗余库极少,软件包的管理清晰灵活;安装脚本完全用ruby
编写,极易自由定制1。
一键安装(一键脚本请参照官网,可能略有不同):
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安装完毕后执行brew
,输出如下,列出了 brew 的一些用法。
> brew
Example usage:
brew [info | home | options ] [FORMULA...]
brew install FORMULA...
brew uninstall FORMULA...
brew search [foo]
brew list [FORMULA...]
brew update
brew upgrade [FORMULA...]
brew pin/unpin [FORMULA...]
Troubleshooting:
brew doctor
brew install -vd FORMULA
brew [--env | config]
Brewing:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/Formula-Cookbook.md
Further help:
man brew
brew home
可以方便的搜索、查看和安装和卸载软件,如下图所示:
按照官方的介绍:
- Homebrew installs the stuff you need that Apple didn’t. 是MAC OS生态的重要补充,提供了大量在Linux下喜闻乐见的工具,比如
curl
,rename
,wget
等等; - Homebrew installs packages to their own directory and then symlinks their files into
/usr/local
. 通过 brew 安装的软件可以和系统原软件完美兼容,互不影响; - Homebrew won’t install files outside its prefix, and you can place a Homebrew installation wherever you like. homebrew 安装的文件默认全部在其指定的目录下,不会安装在其他位置。方便删除,可以自定义 homebrew 的安装位置;
- Trivially create your own Homebrew packages. 方便的创建个人包;
- It's all git and ruby underneath, so hack away with the knowledge that you can easily revert your modifications and merge upstream updates. 通过git管理所有安装配置,极易创建「私服」,把官方repo作为上游分支,可以自由定制。
# brew edit wget 可以直接编辑wget的安装配置
class Wget < Formula
homepage "https://www.gnu.org/software/wget/"
url "https://ftp.gnu.org/gnu/wget/wget-1.15.tar.gz"
sha256 "52126be8cf1bddd7536886e74c053ad7d0ed2aa89b4b630f76785bac21695fcd"
def install
system "./configure", "--prefix=#{prefix}"
system "make", "install"
end
end
我安装的软件有:
> brew list | paste -sd ',' -
aspell,autoconf,autojump,automake,bash,boris,brew-cask,ccat,cloog,cmake,composer,coreutils,cscope,ctags,editorconfig,emacs-clang-complete-async,emacs-mac,fontconfig,freetype,gcc,gdbm,gettext,git,gmp,gnu-sed,gnutls,go,htop-osx,icu4c,imagemagick,isl,jpeg,leptonica,libevent,libmpc,libpng,libtasn1,libtiff,libtool,llvm,mercurial,mobile-shell,mpfr,nettle,newt,nvm,openssl,pcre,php56,pkg-config,popt,protobuf,proxychains-ng,pyenv,pyqt,python,qt,rbenv,rbenv-gem-rehash,readline,rename,ruby-build,s-lang,sip,sqlite,tesseract,the_silver_searcher,tig,tree,unixodbc,vim,wget,xz,zeromq,zlib,zsh
PS: 当希望用 brew 安装的软件替代系统自带的软件(比如 git)时,确保$PATH
中 brew 安装的位置在系统位置/usr/bin
之前,可以运行brew doctor
查看。安装软件完成之后请查看安装成功的一些后续指导。
PS: 执行brew cleanup
清除安装产生的缓存文件。
PS: 使用 LaunchRocket 管理 brew 安装的 service。
caskroom(brew cask) 构建于 Homebrew,继承了其优雅和便捷性,提供安装 OS X 应用和二进制软件的新方法。可以这么简单理解,brew安装的是命令行工具,比如curl
, rename
, wget
;brew cask安装的是应用软件,比如google chrome
, dropbox
等。通过brew cask 安装软件,只需要简单的一条命令brew cask install google-chrome
即可,再也不需要以前的打开网页、找到链接、下载软件、解压包、放到程序目录,删除安装文件,再来启动它这么复杂的步骤了。一键完成!2
虽然通过 Mac App Store 安装软件一样很简单,�但是 Mac App Store 生态圈远不完善,审核流程过长,限制太多,维护成本过高让很多应用开发者被迫离开。大量软件缺失。3
安装brew install caskroom/cask/brew-cask
,安装完毕后执行brew cask
,可以看到 cask 提供的命令基本上继承自 brew:
> brew cask
brew-cask provides a friendly homebrew-style CLI workflow for the
administration of Mac applications distributed as binaries.
!!
!! no command verb:
!!
Commands:
alfred displays note about new built-in alfred support
audit verifies installability of Casks
cat dump raw source of the given Cask to the standard output
cleanup cleans up cached downloads and tracker symlinks
create creates the given Cask and opens it in an editor
doctor checks for configuration issues
edit edits the given Cask
fetch downloads Cask resources to local cache
home opens the homepage of the given Cask
info displays information about the given Cask
install installs the given Cask
list with no args, lists installed Casks; given installed Casks, lists staged files
search searches all known Casks
uninstall uninstalls the given Cask
update a synonym for 'brew update'
zap zaps all files associated with the given Cask
See also "man brew-cask"
通过 brew 安装的软件都在/opt/homebrew-cask/Caskroom
下:
> cd /opt/homebrew-cask/Caskroom
/opt/homebrew-cask/Caskroom
> ls
aliwangwang goagentx macdown sourcetree virtualbox
anki google-chrome mplayerx thunder xiami
bettertouchtool haskell-platform p4merge tunnelblick xtrafinder
dropbox iterm2 qqinput typora zotero
evernote jumpcut rdm utopia
firefox lilypond skitch vagrant
同时在~/Applications
下创建了链接文件:
> ll ~/Applications
lrwxr-xr-x 1 haidao staff 62B Jun 13 2014 AliWangwang.app -> /opt/homebrew-cask/Caskroom/aliwangwang/latest/AliWangwang.app
...
你也可以像 brew 那样自由定制,假如你觉得某个软件全球的用户都需要,就可以向官方 repo 发起 pull request。
cask :v1 => 'dropbox' do
version :latest
sha256 :no_check
url 'https://www.dropbox.com/download?plat=mac&full=1'
name 'Dropbox'
homepage 'https://www.dropbox.com/'
license :gratis
app 'Dropbox.app'
zap :delete => '~/.dropbox'
end
更有趣的是,你的重装系统将变得极为简单!把你的常用软件列表记下来,然后执行brew cask install software-1 software-2 ... software-n
,然后睡一觉就一切搞定了~ 个人文档数据通过dropbox
直接恢复你的代码肯定都在 github
PS: cask 重装软件,brew cask uninstall xxx && brew cask install xxx
或brew cask install xxx --force
。
PS: alfred 支持,brew cask alfred link
。
PS: brew 和 brew cask 的下载都是断点续传的。