Download Mongodb Macos

Posted on
  • Install MongoDB

Author: MongoDB Documentation Team

One of the benefits of having a MongoDB server on your macOS is that it resembles a Unix-like system. That being said, you can do a lot with a Linux distro and MongoDB’s latest version. The best news is that you can use a variety of methods to install MongoDB on the different distros of Linux. Official.NET Core downloads for Linux, macOS, and Windows.NET Core is a cross-platform version of.NET, for building apps that run on Linux, macOS, and Windows. The switch was mostly very smooth, with one main problem: setting up MongoDB. The problem is related to the latest major macOS release, Catalina, and in this article, I’ll share my solution.

This guide describes how to install MongoDB locally. If you wouldlike to use MongoDB in the Cloud using Atlas, our manageddatabase product, see Get Started with Atlas.

Time required: 10 minutes

What You’ll Need¶

MongoDB supports a variety of 64-bit platforms. Refer to theSupported Platforms table toverify that MongoDB is supported on the platform to which you wishto install it.

Download mongodb macos command

Procedure¶

Install MongoDB¶

  • Windows
  • macOS
  • Linux

Download the binaries from the MongoDB Download Center.

  1. Open Windows Explorer/File Explorer.

  2. Change the directory path to where you downloaded the MongoDB.msi file. By default, this is %HOMEPATH%Downloads.

  3. Double-click the .msi file.

  4. The Windows Installer guides you through the installation process.

    If you choose the Custom installation option, you mayspecify an installation directory.

    MongoDB does not have any other system dependencies. You can install and run MongoDB from any folder you choose.

    Note

    This tutorial assumes that you installed MongoDBin C:ProgramFilesMongoDBServer4.2.

Platform Support

MongoDB only supports macOS versions 10.11 and later on Intel x86-64.

Download the binary files for the desired release of MongoDB.¶

Download the binaries from the MongoDB Download Center.

Extract the files from the downloaded archive.¶

For example, from a system shell, you can extract through the tar command:

Copy the extracted archive to the target directory.¶

Copy the extracted folder to the location from which MongoDB will run.

Ensure the location of the binaries is in the PATH variable.¶

The MongoDB binaries are in the bin/ directory of the archive. Toensure that the binaries are in your PATH, you can modify yourPATH.

For example, you can add the following line to your shell’src file (e.g. ~/.bashrc):

Replace <mongodb-install-directory> with the path to the extractedMongoDB archive.

Note

These instructions are for installing MongoDB directly froman archive file. If you would rather use your linuxdistribution’s package manager, refer to theinstallation instructions for yourdistribution in the MongoDB Manual.

Download the binary files for the desired release of MongoDB.¶

Download the binaries from the MongoDB Download Center.

Extract the files from the downloaded archive.¶

Extract the archive by double-clicking on the tar file or usingthe tar command from the command line, as in the following:

Copy the extracted archive to the target directory.¶

Copy the extracted folder to the location from which MongoDB will run.

Ensure the location of the binaries is in the PATH variable.¶

The MongoDB binaries are in the bin/ directory of the archive. Toensure that the binaries are in your PATH, you can modify yourPATH.

For example, you can add the following line to your shell’src file (e.g. ~/.bashrc):

Replace <mongodb-install-directory> with the path to the extractedMongoDB archive.

Run MongoDB¶

  • Windows
  • macOS
  • Linux

Warning

Do not make mongod.exe visible on publicnetworks without running in “Secure Mode” with theauth setting. MongoDB is designed to be run intrusted environments, and the database does not enable“Secure Mode” by default.

Set up the MongoDB environment.¶

MongoDB requires a data directory to store alldata. MongoDB’s default data directory path is the absolute pathdatadb on the drive from which you start MongoDB. Createthis folder by running the following command in aCommand Prompt:

You can specify an alternate path for data files using the--dbpath option tomongod.exe, for example:

If your path includes spaces, enclose the entire path in doublequotes, for example:

You may also specify the dbpath in a configuration file.

Start MongoDB.¶

To start MongoDB, run mongod.exe. For example, from theCommand Prompt:

This starts the main MongoDB database process. The waitingforconnections message in the console output indicates that themongod.exe process is running successfully.

Depending on the security level of your system, Windows may pop up aSecurity Alert dialog box about blocking “some features” ofC:ProgramFilesMongoDBServer4.0binmongod.exe from communicatingon networks. All users should select PrivateNetworks,suchasmyhomeorworknetwork and click Allowaccess. For additional information onsecurity and MongoDB, please see the Security Documentation.

Verify that MongoDB has started successfully¶

Verify that MongoDB has started successfully bychecking the process output for the following line:

The output should be visible in the terminal or shell window.

You may see non-critical warnings in the processoutput. As long as you see the log line shown above, you can safelyignore these warnings during your initial evaluation of MongoDB.

Connect to MongoDB.¶

To connect to MongoDB through the ~bin.mongo.exe shell,open another Command Prompt.

Create the data directory¶

Before you start MongoDB for the first time, create the directory towhich the mongod process will write data. By default, themongod process uses the /data/db directory. If you createa directory other than this one, you must specify that directory in thedbpath option when starting the mongod processlater in this procedure.

The following example command creates the default /data/db directory:

Set permissions for the data directory¶

Before running mongod for the first time, ensure that theuser account running mongod has read and write permissionsfor the directory.

Run MongoDB¶

To run MongoDB, run the mongod process at the system prompt.If necessary, specify the path of the mongod or the datadirectory. See the following examples.

Run without specifying paths¶

If your system PATH variable includes the location of themongod binary and if you use the default data directory(i.e., /data/db), simply enter mongod at the system prompt:

Specify the path of the mongod

If your PATH does not include the location of themongod binary, enter the full path to the mongodbinary at the system prompt:

Specify the path of the data directory¶

If you do not use the default data directory (i.e., /data/db),specify the path to the data directory using the--dbpath option:

Verify that MongoDB has started successfully¶

Verify that MongoDB has started successfully bychecking the process output for the following line:

The output should be visible in the terminal or shell window.

You may see non-critical warnings in the processoutput. As long as you see the log line shown above, you can safelyignore these warnings during your initial evaluation of MongoDB.

Important

If you are using SELinux on a Red Hat Linux-based system,(Red Hat Enterprise Linux or CentOS Linux), you mustconfigure SELinux to allow MongoDB to start. Refer toConfigure SELinux for instructions.

Create the data directory¶

Before you start MongoDB for the first time, create the directory towhich the mongod process will write data. By default, themongod process uses the /data/db directory. If you createa directory other than this one, you must specify that directory in thedbpath option when starting the mongod processlater in this procedure.

The following example command creates the default /data/db directory:

Set permissions for the data directory¶

Before running mongod for the first time, ensure that theuser account running mongod has read and write permissionsfor the directory.

Run MongoDB¶

To run MongoDB, run the mongod process at the system prompt.If necessary, specify the path of the mongod or the datadirectory. See the following examples.

Run without specifying paths¶

If your system PATH variable includes the location of themongod binary and if you use the default data directory(i.e., /data/db), simply enter mongod at the system prompt:

Specify the path of the mongod

If your PATH does not include the location of themongod binary, enter the full path to the mongodbinary at the system prompt:

Specify the path of the data directory¶

If you do not use the default data directory (i.e., /data/db),specify the path to the data directory using the--dbpath option:

Verify that MongoDB has started successfully¶

Verify that MongoDB has started successfully bychecking the process output for the following line:

The output should be visible in the terminal or shell window.

You may see non-critical warnings in the processoutput. As long as you see the log line shown above, you can safelyignore these warnings during your initial evaluation of MongoDB.

Summary¶

If you have successfully completed this guide, you have installedMongoDB and are ready to connect to your mongodinstance and start inserting data.

What’s Next¶

The next guide walks you through setting up authentication on your new MongoDB instance.

See Also¶

  • Structure your Data for MongoDB for an introduction to MongoDB.
  • Installation for installation instructionsfor MongoDB Enterprise Edition, details on installing olderversions of MongoDB.

© MongoDB, Inc 2008-present. MongoDB, Mongo, and the leaf logo are registered trademarks of MongoDB, Inc.

Introduction

One of the benefits of having a MongoDB server on your macOS is that it resembles a Unix-like system. That being said, you can do a lot with a Linux distro and MongoDB’s latest version. The best news is that you can use a variety of methods to install MongoDB on the different distros of Linux. So let’s proceed with this tutorial on how to install and setup a MongoDB server on macOS.

Prerequisites:

  • Localhost web server – It must be running.

OR

  • Linux server remote SSH access – You must have sudo privileges and a private key to gain access.

Debian-based distros: Install and Run MongoDB

  • Use the APT (Advanced Packaging Tool) repository manager to install and run the MongoDB server.

  • The sources.list.d file must have the MongoDB repository added to it.

echo'deb [arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse'sudotee/etc/apt/sources.list.d/mongodb-org-4.0.list
  • Access a terminal in Linux before you add MongoDB or anything else that is new. Prepare your OS by updating all repositories.
  • Next, go ahead and install MongoDB. Include dependencies that go with it.
sudoapt-get install-y mongodb-org

or specify a particular version

sudoapt-get install-y mongodb-org=4.0.9 mongodb-org-server=4.0.9 mongodb-org-shell=4.0.9 mongodb-org-mongos=4.0.9 mongodb-org-tools=4.0.9
  • If you experience problems locating mongodb-org, try the sudo apt-get install method below:

>NOTE: The repository file sources.list.d has to be complete and all packages have to be intact, nothing broken. If you come across an incomplete repository or some other error occurs, don’t stress. Just remove MongoDB entirely. Yes, it’s best to purge instead of trying to figure out the error because it could be anywhere and you don’t want to waste time. The sudo apt-get purge mongodb-org* command will get you to a place where you can start the installation process again.

Red Hat distros: Install and Run MongoDB

  • The YUM (Yellowdog Updater Modified) package manager works well with Red Hat Linux distros. Fedora and CentOS use YUM for installations. The good news is that within the directory of the YUM repository, a .repo file for MongoDB is created.

  • Use cd to create the MongoDB repository .repo file.

Mongodb Client Mac

cd/etc/yum.repos.d/
  • The sudo command touch creates the .repo file. You’ll do this when you’re in the yum.repos.d folder. Check that you downloaded MongoDB’s current installation because you want to base the .repo file on that.

  • Next, the nano command line editor allows you to do some file editing.

sudotouch mongodb-org-4.0.repo
sudonano mongodb-org-4.0.repo
  • Edit the file by pasting the repository installation’s configuration settings information.
[mongodb-org-4.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-4.0.asc
  • Now that the YUM directory contains the .repo file, you’re ready to install MongoDB.
  • Update repositories with the YUM command This is the simplest way for those that use the RPM (Red Hat Package Manager):

  • CentOS distros

  • Fedora distros

  • Red Hat distros

sudoyum update
# use 'upgrade' to install the updated packages:
sudoyum upgrade

Use PHP and PEAR: Install and Run MongoDB

The PHP Extension and Application Repository is another way to install MongoDB. Before you begin though, use php --version to verify your current version of PHP on your OS.

  • Check that your PHP 7 version is complete. Verify that you have the necessary development libraries for it.
# replace `7.x` with your version of PHP 7
sudoapt-get install php7.x-dev
  • PEAR has a pecl library. Install MongoDB with it.

The version is identified on a macOS terminal by using the pear version command.

Be sure to verify your installation of PEAR .

Use a Tarball archive: Install and Run MongoDB

  • You can install and run MongoDB using a tarball archive. After you download, you can unarchive it.

Use cURL to download Tarball file

sudo curl -O https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.9.tgz

Use tar to unpack the Tarbarll file

Download Mongodb Macos
  • A new directory will contain the unpacked installation files for MongoDB.

  • Move it to the $PATH environment variable

OR

  • Link it symbolically to point to the directory folder

Option 1: MongoDB Directory – Use MV for Path Exporting

  • The mv command will move the MongoDB archive (unzipped) to a new location where it can stay for good.

  • If you do that, the next thing you’ll want to do is use cd to gain access into the directory.

  • The pwd command will show you the directory’s path.

  • For the ability to gain access to the folder wherever, export the directory’s name and its path to $PATH in Linux.

Run Mongodb Mac

exportPATH=/some/path/mongodb-linux-x86_64-4.0.9/bin:$PATH
  • Another way to export the path is to copy and paste the following code below in the ~/.bashrc file:
exportPATH=$PATH:/some/path/mongodb-linux-x86_64-4.0.9
  • To look at every environmental path, use the echo $PATH command.

  • To view every environmental variable, use the echo $VARIABLE command.

Option 2: MongoDB Directory – Move it to Linux

For this option, there are two ways to move the MongoDB directory:

  • Put it in a system directory of Linux

OR

  • Put it in an established environment in Linux such as:

  • /usr/bin

  • /usr/local/bin
  • another similar path based on your OS and Linux system
  • View the environment path directory listing by inputting the terminal command: echo $PATH

Optional Validation Task: Use a Public Key

  • If you want to validate the installer’s character, you can download a GPG public key and the TAR archive at the same time. Start with this script:
sudo curl -LO https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-4.0.9.tgz.sig
  • To get the public signature file, use cURL.
sudo curl -LO https://www.mongodb.org/static/pgp/server-4.0.asc
  • The last step in this process is to use cURL again to import the server.
curl -LO https://www.mongodb.org/static/pgp/server-3.4.asc
gpg --import server-3.4.asc

Use Composer: Install and Run MongoDB

  • You can use composer to install MongoDB as well through composer require mongodb/mongodb.

MongoDB: Setup and Configure the Server

  • If you don’t see the file mongodb.service in the cd /etc/systemd/system/ system directory, then in the terminal, paste the following code:
  • It’s likely that you won’t find MongoDB files in the system folder, but you can try ls -A to find out after you accessed the system folder.

  • Go to the directory /etc/systemd/system/ and use the command touch to create the mongodb.servicefile.

sudotouch mongodb.service
  • Edit the mongodb.service file you just created with the command line terminal editor nano or another one.
  • Export the file’s changes you just made by pressing Ctrl+O

  • Next, close the command line terminal editor nano or whichever one you used to edit by pressing Ctrl+X.

  • Press CTRL+O to output the changes to the file, and then press CTRL+X to close the nano editor running in terminal.

  • Try these sudo commands:

  • sudo systemctl start mongodb

  • sudo systemctl status mongodb

NOTE: To stop MongoDB service in Linux while in the terminal, press Ctrl+Z.

MongoDB: Test it. Start it up

mongod --port42424

Time to Create a MongoDB Database Directory

  • You might already have a directory for MongoDB. Find out by going into a terminal and pasting the data directory path /data/db/. Press Return when finished.

  • If you receive a “error: dbpath (/data/db) does not exist” or similar error message, create the `/data/db/ by entering the following code:

  • Start up the MongoDB service
sudo service mongod start

*Restart the MongoDB service

*Stop MongoDB service

stop: sudo service mongod stop
  • Type Ctrl+Z to stop running the MongoDB service in the terminal.

Mac Mongodb Restart

Conclusion

Mongodb Download Mac

This tutorial explained the various Linux distros and how you can setup MongoDB server on a macOS with them. Among the ways discussed, we talked about Debian-based, Red Hat, PHP and PEAR, Tarball archive, Composer, plus some more tips and tricks. With so many choices, you can select the method that suits you best.