Mac開(kāi)發(fā)環(huán)境配置之HomeBrew

如果你使用慣了linux,你會(huì)對(duì)軟件包管理、命令行不能自拔。由于mac的底層是類unix系統(tǒng),也可以配置向linux一樣好用。

安裝HomeBrew

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

上面必須先有ruby以及其他開(kāi)發(fā)環(huán)境支持,建議安裝xcode后使用以上命令安裝。

HomeBrew使用

安裝成功以后,使用man brew查看命令幫助學(xué)習(xí)使用。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

下面詳細(xì)介紹具體的使用

搜索軟件包

brew search [TEXT|/REGEX/]這個(gè)是進(jìn)行搜索軟件包,參數(shù)支持正則表達(dá)式,

(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ù),不會(huì)去線上去查詢,使用`brew search`或`brew -S`
2. brew search [--desc] (text|/text/):
   獲取一個(gè)軟件的短描述

3. brew search (--debian|--fedora|--fink|--macports|--opensuse|--ubuntu) text:
    獲取不同平臺(tái)上軟件的文檔信息
獲取軟件包信息

brew (info|home|options) [FORMULA…]

1.brew info

brew info formula

顯示這個(gè)軟件的信息,后面可以接的參數(shù)有 —github, —json=version等等

2.brew home

通過(guò)瀏覽器打開(kāi)軟件的主頁(yè)

3.brew options

顯示軟件包的options信息,安裝時(shí)的,默認(rèn)的安裝信息

安裝軟件包

brew install FORMULA...

安裝軟件使用的命令,也是我們使用最頻繁的。看看她的詳細(xì)參數(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 …]

先來(lái)介紹最簡(jiǎn)單的使用

安裝

brew install elinks

Homebrew 會(huì)將軟件包安裝到獨(dú)立目錄,并將其文件軟鏈接至 /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 不會(huì)將文件安裝到它本身目錄之外,所以您可將 Homebrew 安裝到任意位置。

你可以使用man brewbrew install --help查看具體一些參數(shù)的使用,都很簡(jiǎn)單。

升級(jí)和清理

brew update
brew upgrade
brew updte

會(huì)自動(dòng)升級(jí)軟件包和自身

brew outdate

查看過(guò)時(shí)的軟件包,會(huì)有升級(jí)的版本號(hào)

brew upgrade

升級(jí)所有可以升級(jí)的

brew upgrade <formula>

升級(jí)具體的軟件包

brew upgrade <formula>

停止一些軟件包的更新和升級(jí)

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

這個(gè)命令也是使用比較頻繁的。
brew uninstall, rm, remove [--force][--ignore-dependencies]
rm,remove也是卸載命令
--force 強(qiáng)制卸載, 如果有依賴,也強(qiáng)制卸載
--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
運(yùn)行某個(gè)服務(wù),沒(méi)有運(yùn)行,運(yùn)行,運(yùn)行的,重啟
3. brew services start| stop| restart  formula|--all
開(kāi)啟,關(guān)閉,重啟

另外,自己定義服務(wù),記住/Library/LaunchDaemons, ~/Library/LaunchAgents, /Library/LaunchDaemons,修改對(duì)應(yīng)文件。

總結(jié)

homebrew內(nèi)容很多,另外,擴(kuò)展性和靈活性也很強(qiáng)大,如果感興趣,可以去官網(wǎng)文檔 閱讀文檔學(xué)習(xí)。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

推薦閱讀更多精彩內(nèi)容