To install MongoDB, follow the steps below:
For Mac OS:
- There are two options for Mac OS: manual install or homebrew.
- Installing with homebrew:
1. Type the following command into the terminal:
- Installing manually:
2. Download the latest release here. Make sure that you are downloading the appropriate file, specially check whether your operating system type is 32-bit or 64-bit. The downloaded file is in format tgz.
3. Go to the directory where this file is downloaded. Then type the following command:
Instead of xyz, there would be some version and system type information. The extracted folder would be same name as the tgz file. Inside the folder, their would be a subfolder named bin which would contain several binary file along with mongod and mongo.
4. By default server keeps data in folder /data/db. So, we have to create that directory and then
run the server having the following commands:
5. To start the server, the following command should be given from the current location:
It would start the server on port 27017 by default.
6. To start the client, a new terminal should be opened having the same directory as before. Then the following command would start the client and connect to the server.
By default it connects to the test database. If you see the line like connecting to: test. Then you have successfully installed MongoDB. Congrats! Now, you can test Hello World to be more confident.