
博主目前都用 mac 电脑练习,所以这里重点讲 MacOS 安装方式
MongoDB 4.4 社区版支持 macOS 10.13 或更高版本
Homebrew 是一个软件包管理器。它的作用就是将软件包安装到自己的目录中,然后将其文件符号链接到 /usr/local。更多信息,请自行进入官网查看
https://brew.sh/在将下面代码复制进终端
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"brew tap mongodb/brew
brew install [email protected] ==> Installing [email protected] from mongodb/brew
==> Downloading https://fastdl.mongodb.org/osx/mongodb-macos-x86_64-4.4.5.tgz
Already downloaded: /Users/polo/Library/Caches/Homebrew/downloads/f86017008241ff604c5586f09b0ac27416ca9006d72f3c7087a9c8d02d26df8e--mongodb-macos-x86_64-4.4.5.tgz
==> Caveats
[email protected] 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 [email protected] first in your PATH, run:
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
To have launchd start mongodb/brew/[email protected] now and restart at login:
brew services start mongodb/brew/[email protected]
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
? /usr/local/Cellar/[email protected]/4.4.5: 11 files, 157.3MB, built in 4 seconds最新5.0,先不做小白鼠
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.zshrc
source ~/.zshrcmongo --version
mongod --version
# 均显示
db version v4.4.5
Build Info: {
"version": "4.4.5",
"gitVersion": "ff5cb77101b052fa02da43b8538093486cf9b3f7",
"modules": [],
"allocator": "system",
"environment": {
"distarch": "x86_64",
"target_arch": "x86_64"
}
} | Intel 处理器 | Apple M1 处理器 |
|---|---|---|
configuration file | /usr/local/etc/mongod.conf | /opt/homebrew/etc/mongod.conf |
log directory | /usr/local/var/log/mongodb | /opt/homebrew/var/log/mongodb |
data directory | /usr/local/var/mongodb | /opt/homebrew/var/mongodb |
brew services start [email protected]
brew services stop [email protected]intel 处理器
mongod --config /usr/local/etc/mongod.conf --forkM1 处理器
mongod --config /opt/homebrew/etc/mongod.conf --fork从 mongo shell 连接到 mongod,并发出关闭命令
brew services list 
ps aux | grep mongdb
ps aux | grep -v grep | grep mongod
mongo
brew services list 查看 MongoDB 服务 status 显示 error 的问题
执行 mongo、mongod 显示无命令