Installation

Windows Installation

  • Download the MongoDB Community Server from official website

  • Run the installer and follow the setup wizard

  • Choose "Complete" setup type

  • Check "Install MongoDB as a Service"

  • Set data directory to C:\data\db (or create manually if needed)

Method 2: Using Chocolatey (Package Manager)

choco install mongodb

Configure Path Environment Variable

Add MongoDB's bin directory to your system PATH:

# Default installation path
$env:Path += ";C:\Program Files\MongoDB\Server\{version}\bin"

Start MongoDB Service

# Start MongoDB service
net start MongoDB

# Stop MongoDB service
net stop MongoDB

Linux Installation

Ubuntu/Debian

# Import the public key
wget -qO - https://www.mongodb.org/static/pgp/server-7.0.asc | sudo apt-key add -

# Create list file
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu $(lsb_release -cs)/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list

# Update packages
sudo apt-get update

# Install MongoDB
sudo apt-get install -y mongodb-org

# Start MongoDB
sudo systemctl start mongod

# Enable auto-start on boot
sudo systemctl enable mongod

RHEL/CentOS/Fedora

# Create repo file
cat <<EOF | sudo tee /etc/yum.repos.d/mongodb.repo
[mongodb-org-7.0]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/\$releasever/mongodb-org/7.0/x86_64/
gpgcheck=1
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-7.0.asc
EOF

# Install MongoDB
sudo yum install -y mongodb-org

# Start service
sudo systemctl start mongod
sudo systemctl enable mongod

macOS Installation

# Tap MongoDB formula
brew tap mongodb/brew

# Install MongoDB
brew install mongodb-community

# Start MongoDB service
brew services start mongodb-community

# Stop MongoDB service
brew services stop mongodb-community

Method 2: Manual Installation

  1. Download MongoDB from official website

  2. Extract the archive:

tar -zxvf mongodb-macos-x86_64-7.0.2.tgz
  1. Move to appropriate location:

mkdir -p /usr/local/mongodb
mv mongodb-macos-x86_64-7.0.2/* /usr/local/mongodb
  1. Add to PATH:

echo 'export PATH="/usr/local/mongodb/bin:$PATH"' >> ~/.zshrc
source ~/.zshrc

Verifying Installation

Check MongoDB Version

mongod --version

Test MongoDB Connection

# Start MongoDB shell
mongosh

# Run test command
db.runCommand({ connectionStatus: 1 })

Log Files Location

  • Linux: /var/log/mongodb/mongod.log

  • macOS: /usr/local/var/log/mongodb/mongo.log

  • Windows: C:\Program Files\MongoDB\Server\{version}\log\mongod.log

Uninstall MongoDB

Ubuntu/Debian

sudo apt-get purge mongodb-org*

macOS (Homebrew)

brew uninstall mongodb-community
brew cleanup

Windows

  • Use Control Panel > Programs and Features

  • Or use Chocolatey: choco uninstall mongodb

Last updated