mac下安装nginx
安装命令:$ brew install nginx
安装时报如下错误:
Updating Homebrew...
error: Not a valid ref: refs/remotes/origin/master
Error: No available formula with the name "nginx"
==> Searching for a previously deleted formula (in the last month)...
Error: No previously deleted formula found.
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
==> Searching taps...
==> Searching taps on GitHub...
Error: No formulae found in taps.
修复Homebrew
修改清华源命令:
cd "$(brew --repo)"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
执行以上命令,继续报错:
$ git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun at: /Library/Developer/CommandLineTools/usr/bin/xcrun
据查以上报错是git运行需要一个xcode插件,执行以下命令:
xcode-select --install
等待1~2min后,插件安装完成,重新执行修改源为清华源的命令,无报错。
执行brew update
执行brew update命令,报错:
$ brew update
error: Not a valid ref: refs/remotes/origin/master
fatal: Could not resolve HEAD to a revision
Already up-to-date.
查找以上error解决方法,执行brew update --verbose,结果如下:
$ brew update --verbose
Checking if we need to fetch /usr/local/Homebrew...
Checking if we need to fetch /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Fetching /usr/local/Homebrew...
Fetching /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
Updating /usr/local/Homebrew...
Branch 'master' set up to track remote branch 'master' from 'origin'.
Switched to and reset branch 'master'
Your branch is up to date with 'origin/master'.
Switched to and reset branch 'stable'
Current branch stable is up to date.
Updating /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core...
fatal: Could not resolve HEAD to a revision
Already up-to-date.
更加以上报错,可知报错路径为: /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
打开该路径:
cd /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core
$ ls -al
total 0
drwxr-xr-x 3 zuige admin 96 7 11 00:21 .
drwxr-xr-x 3 zuige admin 96 7 11 02:15 ..
drwxr-xr-x 12 zuige admin 384 7 18 01:03 .git
发现只有一个.git文件
在该路径下执行:
$ git fetch --prune origin
$ git pull --rebase origin master
From https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core
* branch master -> FETCH_HEAD
Updating files: 100% (5370/5370), done.
再次执行brew update,更新成功。
$ brew update
Already up-to-date.
安装nginx
再次执行安装nginx命令,安装成功。
$ brew install nginx