Mac installed MongoDB Generally there are two ways, one is through the source of installation, one is the direct use of homebrew, personal recommendations using homebrew, simple rough.
1. Install Homebrew:
" $ (curl-fssl https://raw.githubusercontent.com/Homebrew/install/master/install) "
2. Install MongoDB using homebrew:
Install MongoDB
A cup of tea will be installed.
At this point MongoDB will be installed in/usr/local/cellar/mongodb/3.4.6 (my MongoDB version is 3.4.6).
3. Configure MongoDB:
After you install MongoDB, you need to configure MongoDB, or you cannot start the server.
(1) Create the root directory under the data/db folder:
mkdir -p/data/db
If permission denied appears, add the sudo command:
sudo mkdir-p/data/db
(2) Give permissions to the/data/db folder:
sudo Chown ID -u/data/db
If the "Illegal user name" error message appears, we can view the current username and give permission:
$ WhoAmI sudochown username/data/db
(3) Add environment variables:
Open a. zshrc file;
Vim ~/.ZSHRC
Add the MongoDB installation directory to the environment variable:
Export path=/usr/local/cellar/mongodb/3.4. 6/bin:${path}
Execute the command to make the environment variable effective:
SOURCE ~/.ZSHRC
(4) Modify the MongoDB configuration file, the configuration file by default under/usr/local/etc mongod.conf:
in/usr/local/var/mongodb instead of the default/data/=/data//usr/local/var/log/mongodb/ =/usr/local/var/log/mongodb/true127.0. 0.1
(5) Let's try to start the server:
$ mongod
When the words waiting for connections on port 27017 appear, our server has started successfully, it is running and listening on the port 27017
. This allows you to start interacting with the server, such as simply opening a new Terminal tab and running mongo
, which opens the interactive console for MONGO and connects to the default server ( localhost:27017
):
Until now, our server has been started successfully, then we can operate, enter show DBS and other commands to try ~
Install MongoDB under Mac