安装命令

brew install

操作流程

➜  ~ brew install nginx
Error: The following directories are not writable by your user:
/usr/local/include
/usr/local/lib
/usr/local/lib/pkgconfig
/usr/local/share
/usr/local/share/doc
/usr/local/share/man
/usr/local/share/man/man1

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

And make sure that your user has write permission.
chmod u+w /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1

➜ ~ sudo chmod 777 /usr/local/include /usr/local/lib /usr/local/lib/pkgconfig /usr/local/share /usr/local/share/doc /usr/local/share/man /usr/local/share/man/man1
➜ ~ brew install nginx
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/4e5357c0cfd55cfa4ef0b
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/pcre-8.44.c
######################################################################## 100.0%
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/nginx-1.19.
######################################################################## 100.0%
==> Installing dependencies for nginx: openssl@1.1 and pcre
==> Installing nginx dependency: openssl@1.1
Error: No such file or directory @ dir_chdir - /usr/local/Cellar
Warning: Bottle installation failed: building from source.
==> Downloading https://www.openssl.org/source/openssl-1.1.1h.tar.gz
######################################################################## 100.0%
Error: An exception occurred within a child process:
Errno::EPERM: Operation not permitted @ dir_s_mkdir - /usr/local/Cellar
➜ ~

➜ ~ sudo mkdir /usr/local/Cellar
➜ ~ sudo chmod 777 /usr/local/Cellar

➜ ~ brew install nginx
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/openssl%401.1-1.1.1h.catalina.bottle.tar.gz
Already downloaded: /Users/air/Library/Caches/Homebrew/downloads/1b76989744a676affdad36db1703cc7fb37539262f93f129a699eadf9a6b4053--openssl@1.1-1.1.1h.catalina.bottle.tar.gz
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/pcre-8.44.catalina.bottle.tar.gz
Already downloaded: /Users/air/Library/Caches/Homebrew/downloads/8a66be89ef090bca54158fd5c428f9ed215132e0449358859b9372a50dc3a283--pcre-8.44.catalina.bottle.tar.gz
==> Downloading https://mirrors.ustc.edu.cn/homebrew-bottles/bottles/nginx-1.19.4.catalina.bottle.tar.gz
Already downloaded: /Users/air/Library/Caches/Homebrew/downloads/207ddb529f528a40d61a08f92f9982ee5b7263e4a115e60e673f8c5ba0f314d4--nginx-1.19.4.catalina.bottle.tar.gz
==> Installing dependencies for nginx: openssl@1.1 and pcre
==> Installing nginx dependency: openssl@1.1
==> Pouring openssl@1.1-1.1.1h.catalina.bottle.tar.gz
Error: Failed to create /usr/local/opt/openssl@1.1
Things that depend on openssl@1.1 will probably not build.
Could not symlink .
/usr/local/opt is not writable.
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall openssl@1.1`
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> Summary
🍺 /usr/local/Cellar/openssl@1.1/1.1.1h: 8,067 files, 18.5MB
==> Installing nginx dependency: pcre
==> Pouring pcre-8.44.catalina.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.

You can try again using:
brew link pcre
==> Summary
🍺 /usr/local/Cellar/pcre/8.44: 204 files, 5.5MB
==> Installing nginx
==> Pouring nginx-1.19.4.catalina.bottle.tar.gz
Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
Could not symlink .
/usr/local/opt is not writable.

You can try again using:
brew link nginx
Warning: The post-install step did not complete successfully
You can try again using `brew postinstall nginx`
==> Caveats
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 have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Summary
🍺 /usr/local/Cellar/nginx/1.19.4: 27 files, 2.2MB
==> Caveats
==> openssl@1.1
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
/usr/local/etc/openssl@1.1/certs

and run
/usr/local/opt/openssl@1.1/bin/c_rehash

openssl@1.1 is keg-only, which means it was not symlinked into /usr/local,
because macOS provides LibreSSL.

If you need to have openssl@1.1 first in your PATH run:
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.zshrc

For compilers to find openssl@1.1 you may need to set:
export LDFLAGS="-L/usr/local/opt/openssl@1.1/lib"
export CPPFLAGS="-I/usr/local/opt/openssl@1.1/include"

==> nginx
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 have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service

验证是否安装完成

➜  ~ brew search nginx
==>

查看信息

➜  ~ brew info nginx
nginx: stable 1.19.4 (bottled), HEAD
HTTP(S) server and reverse proxy, and IMAP/POP3 proxy server
https://nginx.org/
/usr/local/Cellar/nginx/1.19.4 (27 files, 2.2MB)
Poured from bottle on 2020-11-23 at 17:52:41
From: git://mirrors.ustc.edu.cn/homebrew-core.git//Formula/nginx.rb
License: BSD-2-Clause
==> Dependencies
Required: openssl@1.1 ✔, pcre ✔
==> Options
--HEAD
Install HEAD version
==> Caveats
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 have launchd start nginx now and restart at login:
brew services start nginx
Or, if you don't want/need a background service you can just run:
nginx
==> Analytics
install: 45,828 (30 days), 116,951 (90 days), 439,551 (365 days)
install-on-request: 45,075 (30 days), 115,064 (90 days), 427,607 (365 days)
build-error: 0 (30 days)

开启服务

➜  ~ brew services start nginx
==> Tapping homebrew/services
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-services'...
remote: Enumerating objects: 972, done.
remote: Total 972 (delta 0), reused 0 (delta 0), pack-reused 972
Receiving objects: 100% (972/972), 276.93 KiB | 11.00 KiB/s, done.
Resolving deltas: 100% (403/403), done.
Error: Permission denied @ dir_s_mkdir - /usr/local/etc
Error: Failure while executing; `/usr/local/bin/brew tap homebrew/services` exited with 1.
➜ ~ sudo mkdir /usr/local/etc
➜ ~ sudo chmod 777 /usr/local/etc
➜ ~ brew services start nginx
==> Successfully started `nginx` (label: homebrew.mxcl.nginx)