Install Mongodb On Mac Catalina

In this article, I will share how to install MongoDB on MacOS Catalina. First, I created a directory under the Library folder as shown below. I recently upgrade my Mac OS Sierra to Catalina and realize that the mongoDB was not usable in Catalina, somehow `brew update` and `brew upgrade` did not update the mongoDB to be able to run on Catalina. Below is a guide to fix it. The problem is related to the latest major macOS release, Catalina, and in this article, I’ll share my solution.

MongoDB is a general purpose, document-based, distributed data platform built for modern application developers and for the cloud.

MongoDB is classified as a NoSQL database. It uses JSON-like documents with optional schemas.

Install

This tutorial shows you how to install MongoDB on a Mac via Homebrew.

Installation Options

You can use MongoDB as a cloud deployment, or as an on-premise installation. In this tutorial, we install it as an on-premise installation.

When you install it on-premise, you have a choice of installing the Enterprise Server or the free Community Server. In this tutorial, we install the free Community Server.

There are a couple of ways to install MongoDB on a Mac.

  • Option 1: Install it via Homebrew (recommended).
  • Option 2: Install it manually with the installation files.

In this tutorial, we use install it using option 2 (via Homebrew).

Installing MongoDB via Homebrew is recommended, because it automatically installs all needed dependencies, provides an example mongod.conf file to get you started, and simplifies future upgrade and maintenance tasks.

Prerequisites

Because we’re installing MongoDB via Homebrew, this requires that we have Homebrew installed on our Mac.

If you’re not sure whether you have Homebrew installed, open a Terminal window and enter the following:

If you’ve got Homebrew installed, this will return a bunch of Homebrew related information. If not, you probably need to install Homebrew.

To install Homebrew, run the command listed on the Homebrew homepage.

Be sure to read the installation requirements first. In particular, you’ll need Xcode to be installed on your Mac before you install Homebrew.

Install MongoDB

OK, now that we’ve got Homebrew installed, we can go ahead and use it to install MongoDB.

Run the following command into a Terminal window:

That downloads the official Homebrew formulae for MongoDB and the Database Tools.

Run the following:

That simply checks that your system meets all the installation prerequisites. If it does, the brew tap (mongodb/brew) will be listed.

If it doesn’t make sure your system meets the requirements listed at the link given above.

Run the following:

That’s the part that actually installs MongoDB. In this case we’re installing version 4.4. Feel free to change that part to match the actual version that you’re installing.

You can check the MongoDB website for the latest releases. You can modify the above code to reflect the latest release.

You can also run multiple versions side by side if you like.

Run MongoDB

Now that MongoDB is installed, you will need to start it up.

When you run MongoDB, you run the mongod process. mongod is the primary daemon process for the MongoDB system.

There are a couple of ways to run MongoDB (i.e. the mongodb process):

  • Option 1: Run it as a MacOS service
  • Option 2: Run it manually as a background process

Option 1

To run it as a MacOS service, enter the following command:

You can stop it like this:

Option 2

To run it as manually as a background process, enter the following command:

To stop a mongod running as a background process, connect to the mongod from the mongo shell, and issue the shutdown command.

Verify that MongoDB is Running

You can check that MongoDB is running by issuing one of the following commands, depending on whether it’s running as a MacOS service or a background process.

If you started MongoDB as a MacOS service:

You should see the service mongodb-community listed as started.

If you started MongoDB as a background process:

You should see your mongod process in the output.

Connect to MongoDB

Now that MongoDB is up and running, we can connect to it and start using it.

From a new Terminal window, enter the following:

That connects a mongo shell to the running MongoDB instance.

That should display a bunch of text, and at the end, you should see the following prompt:

This means that it’s ready to accept your commands.

Enter a Command

Once connected, you can enter as many commands as you need.

Install mongodb on mac catalina

For starters, enter the following command to display a list of databases:

That should result in the following databases being displayed:

Installation

  1. Download Visual Studio Code for macOS.
  2. Open the browser's download list and locate the downloaded archive.
  3. Select the 'magnifying glass' icon to open the archive in Finder.
  4. Drag Visual Studio Code.app to the Applications folder, making it available in the macOS Launchpad.
  5. Add VS Code to your Dock by right-clicking on the icon to bring up the context menu and choosing Options, Keep in Dock.

Install Mongodb On Mac Catalina Os

Launching from the command line

You can also run VS Code from the terminal by typing 'code' after adding it to the path:

  • Launch VS Code.
  • Open the Command Palette (Cmd+Shift+P) and type 'shell command' to find the Shell Command: Install 'code' command in PATH command.
  • Restart the terminal for the new $PATH value to take effect. You'll be able to type 'code .' in any folder to start editing files in that folder.

Note: If you still have the old code alias in your .bash_profile (or equivalent) from an early VS Code version, remove it and replace it by executing the Shell Command: Install 'code' command in PATH command.

Alternative manual instructions

Instead of running the command above, you can manually add VS Code to your path, to do so run the following commands:

Start a new terminal to pick up your .bash_profile changes.

Install Mongodb On Mac Catalina Island

Note: The leading slash is required to prevent $PATH from expanding during the concatenation. Remove the leading slash if you want to run the export command directly in a terminal.

Note: Since zsh became the default shell in macOS Catalina, run the following commands to add VS Code to your path:

Touch Bar support

Out of the box VS Code adds actions to navigate in editor history as well as the full Debug tool bar to control the debugger on your Touch Bar:

Mojave privacy protections

After upgrading to macOS Mojave version, you may see dialogs saying 'Visual Studio Code would like to access your {calendar/contacts/photos}.' This is due to the new privacy protections in Mojave and is not specific to VS Code. The same dialogs may be displayed when running other applications as well. The dialog is shown once for each type of personal data and it is fine to choose Don't Allow since VS Code does not need access to those folders. You can read a more detailed explanation in this blog post.

Updates

VS Code ships monthly releases and supports auto-update when a new release is available. If you're prompted by VS Code, accept the newest update and it will get installed (you won't need to do anything else to get the latest bits).

Note: You can disable auto-update if you prefer to update VS Code on your own schedule.

Mongodb

Preferences menu

You can configure VS Code through settings, color themes, and custom keybindings available through the Code > Preferences menu group.

You may see mention of File > Preferences in documentation, which is the Preferences menu group location on Windows and Linux. On a macOS, the Preferences menu group is under Code, not File.

Next steps

Once you have installed VS Code, these topics will help you learn more about VS Code:

  • Additional Components - Learn how to install Git, Node.js, TypeScript, and tools like Yeoman.
  • User Interface - A quick orientation around VS Code.
  • User/Workspace Settings - Learn how to configure VS Code to your preferences settings.

Common questions

Why do I see 'Visual Studio Code would like access to your calendar.'

How To Install Mongodb On A Mac

If you are running macOS Mojave version, you may see dialogs saying 'Visual Studio Code would like to access your {calendar/contacts/photos}.' This is due to the new privacy protections in Mojave discussed above. It is fine to choose Don't Allow since VS Code does not need access to those folders.

VS Code fails to update

Install Mongodb On Mac Catalina Operating System

If VS Code doesn't update once it restarts, it might be set under quarantine by macOS. Follow the steps in this issue for resolution.

Does VS Code run on Mac M1 machines?

Yes, VS Code supports macOS ARM64 builds that can run on Macs with the Apple M1 chip. You can install the Universal build, which includes both Intel and Apple Silicon builds, or one of the platform specific builds.

Comments are closed.