配置背景

基础信息:Macbook pro (m1 pro)

配置方式:采用 Homebrew 进行配置

解决流程

具体流程:

1-打开终端

2-查看 mongodb formulae

brew list

我的是 mongodb-community@5.0

3-查看并复制mongodb安装目录

nathanchen@NathansMacBook-Pro ~ % brew list mongodb-community@5.0/opt/homebrew/Cellar/mongodb-community@5.0/5.0.21/bin/install_compass/opt/homebrew/Cellar/mongodb-community@5.0/5.0.21/bin/mongo/opt/homebrew/Cellar/mongodb-community@5.0/5.0.21/bin/mongod/opt/homebrew/Cellar/mongodb-community@5.0/5.0.21/bin/mongos...

复制以下内容:

/opt/homebrew/Cellar/mongodb-community@5.0/5.0.21/bin

5-更新 .zshrc 文件

vi ~/.zshrc

加入以下内容

export PATH="/opt/homebrew/Cellar/mongodb-community@5.0/5.0.21/bin:${PATH}"

然后让文件生效

 source ~/.zshrc

6-查看mongo版本

nathanchen@NathansMacBook-Pro ~ % mongo -versionMongoDB shell version v5.0.21Build Info: {"version": "5.0.21","gitVersion": "4fad44a858d8ee2d642566fc8872ef410f6534e4","modules": [],"allocator": "system","environment": {"distarch": "x86_64","target_arch": "x86_64"}}

ok,至此解决问题 : )

参考:https://stackoverflow.com/questions/68695241/zsh-command-not-found-mongo