2. MongoDB Installation

Página 2

2. Installing MongoDB

Before you start working with MongoDB, it is crucial to install it on your system. This e-book chapter will guide you through the process of installing MongoDB on different operating systems, including Windows, MacOS, and Linux. Let's start with Windows.

2.1 Installation on Windows

To install MongoDB on Windows, follow the steps below:

  1. Visit the official MongoDB website at https://www.mongodb.com/try/download/community.
  2. Choose the version of MongoDB you want to download. For beginners, it is recommended to choose the latest stable version.
  3. Select your operating system, which in this case is Windows.
  4. Click the "Download" button. The MongoDB installation file download should begin immediately.
  5. After downloading the file, double-click it to begin the installation process.
  6. Follow the installation wizard instructions. During installation, you can choose the location where you want to install MongoDB. You can also leave the default option.
  7. Once the installation is complete, you can verify that MongoDB was installed correctly by opening the command prompt and typing "mongod". If the installation was successful, you will see a message indicating that the MongoDB server is running.

2.2 Installation on MacOS

To install MongoDB on MacOS, you can use the Homebrew package manager. Here are the steps:

  1. Open the terminal.
  2. If you don't have Homebrew installed, you can install it by typing the following command in the terminal: /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/ install/master/install.sh)"
  3. After installing Homebrew, you can install MongoDB by typing the following command: brew tap mongodb/brew and then brew install mongodb-community
  4. To start MongoDB, type the following command: brew services start mongodb-community
  5. To check if MongoDB is working correctly, you can type "mongo" in the terminal. If MongoDB was installed correctly, you will see a message indicating that the MongoDB server is running.

2.3 Installation on Linux

Installing MongoDB on Linux varies depending on the distribution you are using. For this tutorial, we will focus on installing MongoDB on Ubuntu.

  1. Open the terminal.
  2. First, you need to import the public key used by the package management system. Enter the following command: wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
  3. Create a list of files for MongoDB. Enter the following command: echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
  4. Update the local database of available packages. Type the following command: sudo apt-get update
  5. Install MongoDB. Type the following command: sudo apt-get install -y mongodb-org
  6. To start MongoDB, type the following command: sudo systemctl start mongod
  7. To check if MongoDB is working correctly, you can type "mongo" in the terminal. If MongoDB was installed correctly, you will see a message indicating that the MongoDB server is running.

With this, we have completed the MongoDB installation section. In the next chapter, we will learn how to configure MongoDB and start working with it.

Now answer the exercise about the content:

What is the process to install MongoDB on MacOS?

You are right! Congratulations, now go to the next page

You missed! Try again.

Next page of the Free Ebook:

33. Basic concepts of MongoDB

Earn your Certificate for this Course for Free! by downloading the Cursa app and reading the ebook there. Available on Google Play or App Store!

Get it on Google Play Get it on App Store

+ 6.5 million
students

Free and Valid
Certificate with QR Code

48 thousand free
exercises

4.8/5 rating in
app stores

Free courses in
video, audio and text