安裝工具:
homebrew(還沒(méi)用過(guò)的小伙伴可以點(diǎn)鏈接進(jìn)行了解)
1、打開(kāi)終端, 查看是否已經(jīng)安裝了Homebrew, 直接終端輸入命令
localhost:~ xxx$ man brew
如果Mac已經(jīng)安裝了, 會(huì)顯示一些命令的幫助信息. 此時(shí)輸入Q退出即可
BREW(1)
NAME
brew - The missing package manager for macOS
SYNOPSIS
brew --version
brew command [--verbose|-v] [options] [formula] ...
DESCRIPTION
Homebrew is the easiest and most flexible way to install the UNIX tools
Apple didn't include with macOS.
ESSENTIAL COMMANDS
For the full command list, see the COMMANDS section.
With --verbose or -v, many commands print extra debugging information.
Note that these flags should only appear after a command.
install formula
Install formula.
uninstall formula
:
2抓歼、查看當(dāng)前電腦所安裝的brew版本
localhost:~ xxx$ brew --version
3鼻疮、更新brew版本*
localhost:~ xxx$ brew --update
Error: The following directories are not writable by your user:
/usr/local/share/man/man8
You should change the ownership of these directories to your user.
sudo chown -R $(whoami) /usr/local/share/man/man8
And make sure that your user has write permission.
chmod u+w /usr/local/share/man/man8
輸入
sudo chown -R whoami
:admin /usr/local/bin
接著系統(tǒng)會(huì)提醒你輸入密碼,輸入密碼回車之后接著輸入:
sudo chown -R whoami
:admin /usr/local/share
之后就能在終端繼續(xù)下一步
localhost:~ xxx$ sudo chown -R `whoami`:admin /usr/local/bin
Password:
localhost:~ xxx$ sudo chown -R `whoami`:admin /usr/local/share
5、查詢要安裝的軟件nginx是否存在
localhost:~ xxx$ brew search nginx
6减俏、安裝nginx*
localhost:~ xxx$ brew install nginx
==> 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 you can just run:
nginx
查看nginx配置文件目錄
open /usr/local/etc/nginx/
查看ginx被安裝到的目錄
open /usr/local/Cellar/nginx
7、啟動(dòng)nginx*
localhost:~ xxx$ nginx
測(cè)試是否成功
打開(kāi)瀏覽器訪問(wèn):localhost:8080
出現(xiàn)下圖 表示成功
8 關(guān)閉nginx*
localhost:~ xxx$ nginx -s stop