安装mongodb
首先执行命令
brew tap mongodb/brew
在M1芯片使用brew安装mongodb需要添加arch -arm64
arch -arm64 brew install mongodb-community
安装过程中遇到报错
==> Installing mongodb/brew/mongodb-community dependency: libnghttp2
==> Pouring libnghttp2-1.46.0.arm64_monterey.bottle.tar.gz
Error: No such file or directory @ rb_sysopen - /Users/AhaoPlus/Library/Caches/Homebrew/downloads/4a6689684e10547da67f4c788694e5e98811a4a3a114f36ca8506a2b263f63ca--libnghttp2-1.46.0.arm64_monterey.bottle.tar.gz
这是在安装mongodb过程中安装的依赖libnghttp2没有安装成功
此时执行命令
arch -arm64 brew install libnghttp2
安装libnghttp2成功之后再重新安装mongodb,后面又遇到了一些依赖库没有成功,重复上面的操作即可。
验证
最后安装mongodb成功后使用mongod --version
命令验证版本信息,正常输出如下:
启动mongodb
使用brew命令启动
brew services start mongodb-community
终止mongodb命令
brew services stop mongodb-community
使用mongod命令启动
x86_64芯片版本命令
mongod --config /usr/local/etc/mongod.conf --fork
复制代码
M1芯片版本命令:
mongod --config /opt/homebrew/etc/mongod.conf --fork
停止服务
mongod --shutdown --dbpath /database/mongodb/data/
killing process with pid: 17747
pid后跟的事pid
验证服务是否已启动
在终端中输入
ps aux | grep -v grep | grep mongod
输出如下所示
AhaoMac 7645 0.7 0.5 411592752 76800 ?? S 5:19下午 0:01.03 /opt/homebrew/opt/mongodb-community/bin/mongod --config /opt/homebrew/etc/mongod.conf
在浏览器中输入http://localhost:27017/ 验证是否启动成功,成功如下图所示