brew 是 Mac 下的一個包管理工具,類似於 centos 下的 yum,可以很方便地進行安裝/卸載/更新各種軟件包,例如:nodejs, elasticsearch, kibana, mysql, mongodb 等等,可以用來快速搭建各種本地環境,程序員必備工具
安裝 brew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
安裝/卸載/更新
以 nodejs 為例,執行下面命令即可,安裝目錄在 /usr/local/Cellar
brew install nodejs
如果需要更新或卸載
brew upgrade nodejs
brew remove nodejs
brew list # 列出當前安裝的軟件 brew search nodejs # 查詢與 nodejs 相關的可用軟件 brew info nodejs # 查詢 nodejs 的安裝信息
如果需要指定版本,可以在 brew search
查看有沒有需要的版本,在 @
后面指定版本號,例如 brew install thrift@0.9
brew services
brew services
是一個非常強大的工具,可以用來管理各種服務的啟停,有點像 linux 里面的 services,非常方便,以 elasticsearch 為例
brew install elasticsearch # 安裝 elasticsearch brew services start elasticsearch # 啟動 elasticsearch brew services stop elasticsearch # 停止 elasticsearch brew services restart elasticsearch # 重啟 elasticsearch brew services list # 列出當前的狀態
brew services 服務相關配置以及日志路徑
- 配置路徑:
/usr/local/etc/
- 日志路徑:
/usr/local/var/log
安裝mysql:
brew install mysql
We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation MySQL is configured to only allow connections from localhost by default To connect run: mysql -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start ==> Summary 🍺 /usr/local/Cellar/mysql/8.0.18_1: 287 files, 278.6MB ==> 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 openssl/libressl is provided by macOS so don't link an incompatible version. 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" ==> protobuf@3.7 protobuf@3.7 is keg-only, which means it was not symlinked into /usr/local, because this is an alternate version of another formula. If you need to have protobuf@3.7 first in your PATH run: echo 'export PATH="/usr/local/opt/protobuf@3.7/bin:$PATH"' >> ~/.zshrc For compilers to find protobuf@3.7 you may need to set: export LDFLAGS="-L/usr/local/opt/protobuf@3.7/lib" export CPPFLAGS="-I/usr/local/opt/protobuf@3.7/include" ==> mysql We've installed your MySQL database without a root password. To secure it run: mysql_secure_installation MySQL is configured to only allow connections from localhost by default To connect run: mysql -uroot To have launchd start mysql now and restart at login: brew services start mysql Or, if you don't want/need a background service you can just run: mysql.server start
mysql.server stop
參考鏈接
- brew 官網:https://brew.sh/