Create New Post

MongoDB - Installation

To install MongoDB, you can follow the steps outlined below. The installation process might vary slightly depending on your operating system. Here, I'll cover installations for popular operating systems: Windows, macOS, and Linux.

Windows:

  1. Download MongoDB Installer:

    • Visit the official MongoDB website: MongoDB Download Center.
    • Choose the "Community Server" tab and select the appropriate version for Windows.
    • Download the installer (MSI).
  2. Run the Installer:

    • Run the downloaded MSI installer.
    • Follow the installation wizard, accepting the default options. You can customize the installation directory if needed.
  3. Complete the Installation:

    • The installer will prompt you to install MongoDB Compass, a graphical user interface for MongoDB. You can choose to install it or skip it.
    • Complete the installation process.
  4. Verify Installation:

    • Open a Command Prompt and run the following command to start the MongoDB server:
      mongod 
    • Open another Command Prompt and run the following command to open the MongoDB shell:
      mongo 

macOS:

  1. Install Homebrew (if not installed):

    • Open Terminal.
    • Install Homebrew using the following command:
       /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
      
  2. Install MongoDB:

    • Run the following command to install MongoDB using Homebrew:
      brew tap mongodb/brew
      brew install mongodb-community
      
  3. Start MongoDB:

    • Run the following command to start MongoDB:
       brew services start mongodb-community
      
  4. Verify Installation:

    • Open a new Terminal window and run the MongoDB shell:
       mongo
      

Linux (Ubuntu/Debian):

  1. Import MongoDB GPG Key:

    • Open a terminal and import the MongoDB GPG key:
      wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
      
  2. Add MongoDB Repository:

    • Add the MongoDB repository to the sources list:
       echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
      
  3. Install MongoDB:

    • Update the package list and install MongoDB:
       sudo apt-get update
      sudo apt-get install -y mongodb-org
      
  4. Start MongoDB:

    • Start the MongoDB service:
       sudo systemctl start mongod
      
  5. Enable MongoDB to Start on Boot:

    • Enable MongoDB to start on system boot:
       sudo systemctl enable mongod
      
  6. Verify Installation:

    • Open a terminal and run the MongoDB shell:
       mongo
      

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

89422