无法通过brew services启动mongodb-community服务求助
解决
brew services start mongodb-community 报错 undefined method plist_startup 的问题 问题描述
执行brew services start mongodb-community时触发以下错误:
Error: undefined method `plist_startup' for #<Formula mongodb-community (stable) /opt/homebrew/Library/Taps/mongodb/homebrew-brew/Formula/mongodb-community.rb> Did you mean? plist_name /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/formula_wrapper.rb:71:in `service_startup?' /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:280:in `service_load' /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:122:in `block in start' /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:97:in `each' /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/services_cli.rb:97:in `start' /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/commands/start.rb:12:in `run' /opt/homebrew/Library/Taps/homebrew/homebrew-services/cmd/services.rb:130:in `services' /opt/homebrew/Library/Homebrew/brew.rb:86:in `<main>'
重新安装Homebrew和MongoDB后,仅重启电脑后能正常运行一次,再次启动仍出现相同错误。
解决方案
方案1:修改homebrew-services的代码文件(快速修复)
错误源于homebrew-services调用了MongoDB formula未实现的plist_startup方法,将其替换为存在的plist_name即可:
- 打开报错的文件:
open /opt/homebrew/Library/Taps/homebrew/homebrew-services/lib/service/formula_wrapper.rb - 找到第71行附近的
service_startup?方法,原代码类似:def service_startup? @formula.plist_startup.present? end - 将
@formula.plist_startup替换为@formula.plist_name,修改后:def service_startup? @formula.plist_name.present? end - 保存文件后,重新启动MongoDB服务:
brew services start mongodb-community
方案2:绕过brew services,手动启动MongoDB
如果不想修改工具代码,可直接使用mongod命令启动:
- 停止残留服务:
brew services stop mongodb-community - 通过配置文件启动MongoDB(后台运行):
mongod --config /opt/homebrew/etc/mongod.conf --fork - 设置开机自启:将上述启动命令添加到你的shell配置文件(如
~/.zshrc或~/.bashrc),或通过系统偏好设置→用户与群组→登录项添加该命令的执行脚本。
方案3:重置brew服务关联并重装MongoDB
- 清理无效的服务关联:
brew services cleanup - 卸载MongoDB:
brew uninstall mongodb-community - 修复并更新MongoDB的tap仓库:
brew tap --repair mongodb/homebrew-brew brew update - 重新安装MongoDB:
brew install mongodb-community - 启动服务:
brew services start mongodb-community
内容的提问来源于stack exchange,提问作者Deewas Tamang
相关产品推荐
相关产品推荐

