原文轉載自:https://www.cnblogs.com/richard-youth/p/9718349.html
使用 React Native,必須安裝的依賴有:Node、Watchman 和 React Native 命令行工具以及 Xcode。
推薦使用 Homebrew 來安裝 Node 和 Watchman。
1、Homebrew是什么?
Homebrew是以最簡單,最靈活的方式來安裝蘋果公司在MacOS中不包含的UNIX工具。 換句話說就是 macOS 缺失的軟件包的管理器。
官方網站:點擊查看
Git倉庫地址:點擊查看
2、Homebrew 安裝:
打開mac終端,復制粘貼下面命令,根據要求,一步一步即可。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
3、Homebrew卸載:
打開mac終端,復制粘貼下面命令(其實只用把上面安裝的install換成uninstall就行了)。
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
4、Homebrew 怎么使用?常用命令有哪些?
安裝軟件,如:brew install node
卸載軟件,如:brew uninstall node
搜索軟件,如:brew search node
更新軟件,如:brew upgrade node
查看安裝列表,如:brew list
更新Homebrew,如:brew update
5、安裝中遇到的問題
(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這個工具。
6、詳細的流程:
$ 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等工具了。