Install MongoDB under Mac

Source: Internet
Author: User
Tags install homebrew install mongodb mongodb version

  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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.