0

Install MongoDB Community Edition on Ubuntu

Install MongoDB

Import the public key menggunakan package management system

Buka terminal, kemudian ketikkan perintah berikut

wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

Jika mendapati error karena gnupg tidak terinstall, lakukan langkah berikut ini

  • Install gnupg package
    sudo apt-get install gnupg
  • Mencoba ulang import key
    wget -qO - https://www.mongodb.org/static/pgp/server-6.0.asc | sudo apt-key add -

Buat list file untuk MongoDB

echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-6.0.list

Reload database package manager

sudo apt-get update

Install MongoDB package

sudo apt-get install -y mongodb-org

Jika mendapati error seperti berikut

The following packages have unmet dependencies:
mongodb-org-mongos : Depends: libssl1.1 (>= 1.1.1) but it is not installable
mongodb-org-server : Depends: libssl1.1 (>= 1.1.1) but it is not installable

Lakukan langkah berikut ini

wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb

Kemudian install ulang MongoDB package

sudo apt-get install -y mongodb-org

Konfigurasi

Directory

Jika instalasi melalui package manager, lokasi default untuk data ada di folder /var/lib/mongodb dan lokasi log ada di folder /var/log/mongodb.

Configuration File

Secara default, konfigurasi file ada di folder /etc/mongod.conf.

Init System

Start MongoDB

sudo systemctl start mongod

Untuk melihat status service

sudo systemctl status mongod

Untuk start otomatis ketika boot

sudo systemctl enable mongod

Stop MongoDB

sudo systemctl stop mongod

Restart mongoDB

sudo systemctl restart mongod

Remove MongoDB

Sebelum menghapus MongoDB, matikan service MongoDB

sudo service mongod stop

Hapus package

sudo apt-get purge mongodb-org*

Hapus database dan log

sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb