uncategorized

Nginx 安裝失敗經驗&解決方法

今天照著前輩這篇安裝 nginx on Mac安裝 nginx 時,本來以為brew install nginx一鍵下去即可高枕無憂,沒想到終端機畫面顯示以下錯誤訊息

1
2
3
4
5
6
7
8
/usr/local/Homebrew/Library/Homebrew/config.rb:39:in `initialize': no implicit conversion of nil into String (TypeError)
from /usr/local/Homebrew/Library/Homebrew/config.rb:39:in `new'
from /usr/local/Homebrew/Library/Homebrew/config.rb:39:in `<top (required)>'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /usr/local/Homebrew/Library/Homebrew/global.rb:25:in `<top (required)>'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:13:in `require_relative'
from /usr/local/Homebrew/Library/Homebrew/brew.rb:13:in `<main>'

不信邪的我再跑一次brew install nginx,這次換以下錯誤訊息

1
Error: No such file or directory @ dir_chdir - /usr/local/Cellar

看來應該是少了 Cellar 資料夾。由於訊息明確,於是把以上那一行拿去 google,看到這一篇,第一則回覆寫著 You should run brew update then brew doctor before you install anything.

於是照著他的話做,先brew update更新 brew 的版本,然後brew doctor檢測,又出現了以下訊息:

1
2
3
4
5
6
7
8
9
10
11
Warning: The following directories do not exist:
/usr/local/opt
/usr/local/sbin
/usr/local/Cellar

You should create these directories and change their ownership to your account.
sudo mkdir -p /usr/local/opt /usr/local/sbin /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/opt /usr/local/sbin /usr/local/Cellar
(...中間一堆無意義資料夾名直接跳過)
Warning: Broken symlinks were found. Remove them with `brew cleanup`:
/usr/local/share/man/man3/*

我先brew cleanup清除舊版本的緩存,然後再建立 Cellar 資料夾並指定權限

1
2
sudo mkdir -p /usr/local/opt /usr/local/sbin /usr/local/Cellar
sudo chown -R $(whoami) /usr/local/opt /usr/local/sbin /usr/local/Cellar

接著終於可以安枕無憂的一鍵搞定brew install nginx了…(淚)

參考連結:
安裝 nginx on Mac
brew doctor – >> Error: No such file or directory - /usr/local/Cellar
Mac - homebrew 套件管理 常用指令
Homebrew

Share