Skip to content

Instantly share code, notes, and snippets.

@cguldogan
Created April 19, 2025 18:59
Show Gist options
  • Save cguldogan/57943142edf89a65d546c8d2933000bd to your computer and use it in GitHub Desktop.
Save cguldogan/57943142edf89a65d546c8d2933000bd to your computer and use it in GitHub Desktop.
Mongo-Ubuntu22.04-Install-Bash
#!/bin/bash
set -e
echo "Installing prerequisites..."
sudo apt-get update
sudo apt-get install -y gnupg curl wget
echo "Importing MongoDB public GPG key..."
curl -fsSL https://www.mongodb.org/static/pgp/server-8.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-8.0.gpg --dearmor
echo "Creating MongoDB source list file..."
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-8.0.gpg ] https://repo.mongodb.org/apt/ubuntu jammy/mongodb-org/8.0 multiverse" | \
sudo tee /etc/apt/sources.list.d/mongodb-org-8.0.list
echo "Updating package index..."
sudo apt-get update
echo "Installing MongoDB..."
sudo apt-get install -y mongodb-org
echo "Enabling and starting MongoDB service..."
sudo systemctl enable mongod
sudo systemctl start mongod
echo "Checking MongoDB service status..."
sudo systemctl status mongod --no-pager
echo "Downloading MongoDB Compass..."
wget https://downloads.mongodb.com/compass/mongodb-compass_1.45.4_amd64.deb
echo "Installing MongoDB Compass..."
sudo apt install -y ./mongodb-compass_1.45.4_amd64.deb
echo "Cleaning up..."
rm mongodb-compass_1.45.4_amd64.deb
echo "MongoDB and MongoDB Compass installation complete!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment