macos brew


原文链接: macos brew

配置清华镜像

git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git

brew update

复原

(感谢Snowonion Lee提供说明)

git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update

常用命令:
brew update  #更新brew可安装包,建议每次执行一下
brew search php55 #搜索php5.5
brew tap josegonzalez/php #安装扩展 ,可以获得更多的资源
brew tap #查看安装的扩展列表
brew install php55 #安装php5.5
brew remove php55 #卸载php5.5
brew upgrade php55 #升级php5.5
brew options php55 #查看php5.5安装选项
brew info php55 #查看php5.5相关信息
brew home php55 #访问php5.5官方网站

brew services list #查看系统通过 brew 安装的服务
brew services cleanup #清除已卸载无用的启动配置文件
brew services restart php55 #重启php-fpm

github tap

brew tap mongodb/brew # mongodb

Run mongod as a service
To have launchd start mongod immediately and also restart at login, use:

brew services start mongodb-community
brew services stop mongodb-community

使用brew services管理服务

官网:
https://github.com/Homebrew/homebrew-services

macOS使用launchctl命令加载开机自动运行的服务,brew service可以简化lauchctl的操作。

以MySQL为例,使用launchctl启动:

ln -sfv /usr/local/opt/mysql/*.plist ~/Library/LaunchAgents
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mysql.plist

如使用brew service可以简化为:

brew services start mysql

常用命令

brew services list  # 查看使用brew安装的服务列表
brew services run formula|--all  # 启动服务(仅启动不注册)
brew services start formula|--all  # 启动服务,并注册
brew services stop formula|--all   # 停止服务,并取消注册
brew services restart formula|--all  # 重启服务,并注册
brew services cleanup  # 清除已卸载应用的无用的配置

配置文件目录

/Library/LaunchDaemons # 开机自启,需要sudo
~/Library/LaunchAgents # 用户登录后自启

以homebrew.mxcl.kafka.plist为例:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>homebrew.mxcl.kafka</string>
    <key>WorkingDirectory</key>
    <string>/usr/local</string>
    <key>ProgramArguments</key>
    <array>
        <string>/usr/local/opt/kafka/bin/kafka-server-start</string>
        <string>/usr/local/etc/kafka/server.properties</string>
    </array>
    <key>RunAtLoad</key>
    <true/>
    <key>KeepAlive</key>
    <true/>
    <key>StandardErrorPath</key>
    <string>/usr/local/var/log/kafka/kafka_output.log</string>
    <key>StandardOutPath</key>
    <string>/usr/local/var/log/kafka/kafka_output.log</string>
</dict>
</plist>

在这里可以找到服务路径、启动参数、日志路径等

`