Homebrew -- 安裝與使用

使用 React Native,必須安裝的依賴有:Node、Watchman 和 React Native 命令行工具以及 Xcode。php

推薦使用Homebrew來安裝 Node 和 Watchman。html

一、Homebrew是什麼? git

Homebrew是以最簡單,最靈活的方式來安裝蘋果公司在MacOS中不包含的UNIX工具。 換句話說就是macOS 缺失的軟件包的管理器。github

官方網站:點擊查看xcode

Git倉庫地址:點擊查看ruby

二、Homebrew 安裝:bash

打開mac終端,複製粘貼下面命令,根據要求,一步一步便可。app

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

三、Homebrew卸載:ide

打開mac終端,複製粘貼下面命令(其實只用把上面安裝的install換成uninstall就好了)。

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

四、Homebrew 怎麼使用?經常使用命令有哪些?

安裝軟件,如:brew install oclint

卸載軟件,如:brew uninstall oclint

搜索軟件,如:brew search oclint

更新軟件,如:brew upgrade oclint

查看安裝列表, 如:brew list

更新Homebrew,如:brew update

五、安裝中遇到的問題

(1)錯誤描述以下:

xcode-select: error: invalid developer directory '/Library/Developer/CommandLineTools'

Failed during: /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools

緣由:xcode的命令行工具再也不安裝在/Library/Developer/CommandLineTools 這個位置了,而是以下圖所示的位置:

/Applications/Xcode.app 

這個時候只須要使用下面這個命令設置一下就能夠了:

sudo xcode-select --switch /Applications/Xcode.app

最後再輸入下面命令驗證一下:

xcode-select -p

打印輸出

/Applications/Xcode.app/Contents/Developer

而後再嘗試安裝命令,就沒有出現上面的那個問題了。

想法:我的以爲上面的那個問題能夠不用管,由於xcode 已經自動安裝了CommandLineTools這個工具。

六、詳細的流程:

$ sudo xcode-select --switch /Applications/Xcode.app

Password:

$ xcode-select -p

/Applications/Xcode.app/Contents/Developer

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

==> This script will install:

/usr/local/bin/brew

/usr/local/share/doc/homebrew

/usr/local/share/man/man1/brew.1

/usr/local/share/zsh/site-functions/_brew

/usr/local/etc/bash_completion.d/brew

/usr/local/Homebrew

==> The Xcode Command Line Tools will be installed.

Press RETURN to continue or any other key to abort

==> Searching online for the Command Line Tools

==> /usr/bin/sudo /usr/bin/touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

==> Installing Command Line Tools (macOS High Sierra version 10.13) for Xcode-9.4

==> /usr/bin/sudo /usr/sbin/softwareupdate -i Command\ Line\ Tools\ (macOS\ High\ Sierra\ version\ 10.13)\ for\ Xcode-9.4

Software Update Tool

Downloading Command Line Tools (macOS High Sierra version 10.13) for Xcode

Downloaded Command Line Tools (macOS High Sierra version 10.13) for Xcode

Installing Command Line Tools (macOS High Sierra version 10.13) for Xcode

Done with Command Line Tools (macOS High Sierra version 10.13) for Xcode

Done.

==> /usr/bin/sudo /bin/rm -f /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress

Password:

==> /usr/bin/sudo /usr/bin/xcode-select --switch /Library/Developer/CommandLineTools

==> Downloading and installing Homebrew...

HEAD is now at dae47914 Merge pull request #4992 from MikeMcQuaid/keg-remove-top-level-directories

==> Migrating /Library/Caches/Homebrew to /Users/galahad/Library/Caches/Homebrew

==> Deleting /Library/Caches/Homebrew...

Already up-to-date.

==> Installation successful!

==> Homebrew has enabled anonymous aggregate formulae and cask analytics.

Read the analytics documentation (and how to opt-out) here:

  https://docs.brew.sh/Analytics.html

==> Homebrew is run entirely by unpaid volunteers. Please consider donating:

  https://github.com/Homebrew/brew#donations

==> Next steps:

- Run `brew help` to get started

- Further documentation: 

  https://docs.brew.sh

接下來可使用Homebrew來安裝 Node 和 Watchman等工具了。

相關文章
相關標籤/搜索