如果你使用慣了linux,你會對軟件包管理、命令行不能自拔旅择。由于mac的底層是類unix系統(tǒng)宣赔,也可以配置向linux一樣好用预麸。
安裝HomeBrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
上面必須先有ruby以及其他開發(fā)環(huán)境支持,建議安裝xcode后使用以上命令安裝儒将。
HomeBrew使用
安裝成功以后吏祸,使用man brew
查看命令幫助學習使用。man brew
的內(nèi)容很多钩蚊,我下面展示brew --help
(data) youdi@liangchangyoudeMacBook-Pro ~ brew --help
Example usage:
brew search [TEXT|/REGEX/]
brew (info|home|options) [FORMULA...]
brew install FORMULA...
brew update
brew upgrade [FORMULA...]
brew uninstall FORMULA...
brew list [FORMULA...]
Troubleshooting:
brew config
brew doctor
brew install -vd FORMULA
Developers:
brew create [URL [--no-fetch]]
brew edit [FORMULA...]
https://docs.brew.sh/Formula-Cookbook.html
Further help:
man brew
brew help [COMMAND]
brew home
下面詳細介紹具體的使用
搜索軟件包
brew search [TEXT|/REGEX/]
這個是進行搜索軟件包贡翘,參數(shù)支持正則表達式,
(data) youdi@liangchangyoudeMacBook-Pro ~ brew search nginx
==> Searching local taps...
nginx ?
==> Searching taps on GitHub...
homebrew/nginx/accesskey-nginx-module homebrew/nginx/xsltproc-nginx-module homebrew/nginx/anti-ddos-nginx-module homebrew/nginx/set-misc-nginx-module
homebrew/nginx/ajp-nginx-module homebrew/nginx/geoip2-nginx-module homebrew/nginx/array-var-nginx-module homebrew/nginx/stream-lua-nginx-module
1. brew search, -S:
顯示出本地所有可用的包砰逻,不加參數(shù)鸣驱,不會去線上去查詢,使用`brew search`或`brew -S`
2. brew search [--desc] (text|/text/):
獲取一個軟件的短描述
3. brew search (--debian|--fedora|--fink|--macports|--opensuse|--ubuntu) text:
獲取不同平臺上軟件的文檔信息
獲取軟件包信息
brew (info|home|options) [FORMULA…]
1.brew info
brew info formula
顯示這個軟件的信息,后面可以接的參數(shù)有 —github, —json=version等等
2.brew home
通過瀏覽器打開軟件的主頁
3.brew options
顯示軟件包的options信息,安裝時的蝠咆,默認的安裝信息
安裝軟件包
brew install FORMULA...
安裝軟件使用的命令踊东,也是我們使用最頻繁的。看看她的詳細參數(shù):
brew install [--debug][--env=(std|super)] [--ignore-dependencies|--only-dependencies][--cc=compiler] [--build-from-source|--force-bottle][--devel|--HEAD] [--keep-tmp][--build-bottle] formula [options …]
先來介紹最簡單的使用
安裝
brew install elinks
Homebrew 會將軟件包安裝到獨立目錄递胧,并將其文件軟鏈接至 /usr/local
碑韵。
$ cd /usr/local/Cellar
$ tree -L 3 elinks
elinks
└── 0.11.7_2
├── AUTHORS
├── COPYING
├── ChangeLog
├── INSTALL_RECEIPT.json
├── NEWS
├── README
├── TODO
├── bin
└── share
3 directories, 7 files
$ cd /usr/local/bin
$ ll elinks
lrwxr-xr-x 1 youdi admin 36B 10 15 15:32 elinks -> ../Cellar/elinks/0.11.7_2/bin/elinks
Homebrew 不會將文件安裝到它本身目錄之外,所以您可將 Homebrew 安裝到任意位置缎脾。
你可以使用man brew
或brew install --help
查看具體一些參數(shù)的使用祝闻,都很簡單。
升級和清理
brew update
brew upgrade
brew updte
會自動升級軟件包和自身
brew outdate
查看過時的軟件包,會有升級的版本號
brew upgrade
升級所有可以升級的
brew upgrade <formula>
升級具體的軟件包
brew upgrade <formula>
停止一些軟件包的更新和升級
brew unpin <formula>
將停止更新的軟件包設(shè)置為允許
brew cleanup <formula>
將軟件包的舊版本記錄清理掉
brew cleanup
清理所有
brew cleanup -n
顯示清理的內(nèi)容
brew --cahce
顯示緩存位置遗菠, 一般是在
~/Library/Caches/Homebrew
查看安裝軟件包
brew list
brew list —help
brew list, ls [--full-name]:
列出所有的安裝的軟件包联喘,可以接一些參數(shù),類似ls
List all installed formulae. If --full-name is passed, print formulae
with fully-qualified names. If --full-name is not passed, any other
options (e.g. -t) are passed to ls which produces the actual output.
brew list, ls --unbrewed:
List all files in the Homebrew prefix not installed by Homebrew.
# diy方式安裝的軟件
brew list, ls [--versions [--multiple]] [--pinned] [formulae]:
List the installed files for formulae. Combined with --verbose, recursively
list the contents of all subdirectories in each formula's keg.
If --versions is passed, show the version number for installed formulae,
or only the specified formulae if formulae are given. With --multiple,
only show formulae with multiple versions installed.
If --pinned is passed, show the versions of pinned formulae, or only the
specified (pinned) formulae if formulae are given.
See also pin, unpin.
卸載軟件包
brew unisntall
這個命令也是使用比較頻繁的辙纬。
brew uninstall, rm, remove [--force][--ignore-dependencies]
rm豁遭,remove也是卸載命令
--force 強制卸載, 如果有依賴贺拣,也強制卸載
--ignore-dependencies 忽略依賴
管理服務(wù)
brew services
brew services [-v|--verbose] [list | run | start | stop | restart | cleanup] [...]
brew services [-v|--verbose] [list | run | start | stop | restart | cleanup] [...]
Easily start and stop formulae via launchctl.
With -v or --verbose, print more detail.
Integrates Homebrew formulae with macOS' launchctl manager. Services can be
added to either /Library/LaunchDaemons or ~/Library/LaunchAgents.
Basically, items in /Library/LaunchDaemons are started at boot, while those
in ~/Library/LaunchAgents are started at login.
When started with sudo, it operates on /Library/LaunchDaemons; otherwise,
it operates on ~/Library/LaunchAgents.
On start the plist file is generated and written to a Tempfile, and then
copied to the launch path (existing plists are overwritten).
[sudo] brew services list
List all running services for the current user (or root)
[sudo] brew services run formula|--all
Run the service formula without starting at login (or boot).
[sudo] brew services start formula|--all
Start the service formula immediately and register it to launch at login (or boot).
[sudo] brew services stop formula|--all
Stop the service formula immediately and unregister it from launching at login (or boot).
[sudo] brew services restart formula|--all
Stop (if necessary) and start the service immediately and register it to launch at login (or boot).
[sudo] brew services cleanup
Remove all unused services.
用法
1. brew services list
打印出安裝的所有服務(wù)
2. brew services run service_name
運行某個服務(wù)蓖谢,沒有運行,運行譬涡,運行的闪幽,重啟
3. brew services start| stop| restart formula|--all
開啟,關(guān)閉涡匀,重啟
另外盯腌,自己定義服務(wù),記住/Library/LaunchDaemons, ~/Library/LaunchAgents, /Library/LaunchDaemons,修改對應(yīng)文件陨瘩。
總結(jié)
homebrew內(nèi)容很多腕够,另外,擴展性和靈活性也很強大舌劳,如果感興趣帚湘,可以去官網(wǎng)文檔 閱讀文檔學習。