2021-12-13 mac 安裝 nginx 踩坑(M1 芯片、ARM 架構芯片)

問題一 沒有 brew

安裝 brew

$ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

# version
$ brew -v

問題二 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.
$ 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
Already up-to-date.

問題三 不支持安裝 ARM 架構的 nginx

# 報錯內容

Cannot install in Homebrew on ARM processor in Intel default prefix (/usr/local)!
  1. 關閉所有的終端
  2. 訪達 => 應用程序 => 實用工具
  3. 右鍵終端.app,顯示簡介
  4. 將 【使用 Rosetta】勾選
  5. 重新打開終端,執行brew install

p.s. 安裝完成後,記得將勾選去掉

問題四 權限不足

報錯內容

Error: The following directories are not writable by your user:
/usr/local/lib/pkgconfig

You should change the ownership of these directories to your user.
  sudo chown -R $(whoami) /usr/local/lib/pkgconfig

And make sure that your user has write permission.
  chmod u+w /usr/local/lib/pkgconfig

直接用

$ sudo brew install nginx

# 報錯

Error: Running Homebrew as root is extremely dangerous and no longer supported.
As Homebrew does not drop privileges on installation you would be giving all
build scripts full access to your system.

按照提示解決

$ sudo chown -R $(whoami) /usr/local/lib/pkgconfig
$ chmod u+w /usr/local/lib/pkgconfig

安裝 nginx

$ brew install nginx

# success log
...

Docroot is: /usr/local/var/www

The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
nginx can run without sudo.

nginx will load all files in /usr/local/etc/nginx/servers/.

To restart nginx after an upgrade:
  brew services restart nginx
Or, if you don't want/need a background service you can just run:
  /usr/local/opt/nginx/bin/nginx -g daemon off;

問題五 如何啓動/停止/重啓 nginx

# 啓動
$ brew services start nginx

# 關閉
$ brew services stop nginx

# 重啓
$ brew services restart nginx

但是這種啓動方式會存在修改的配置文件不生效

# 啓動
$ nginx

# 重新加載配置文件
$ nginx -s reload

# 停止
$ nginx -s stop
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章