install mongodb from official source on ubuntu 18.04
You can have many ways to install mongodb on linux. But I prefer to install the release from official resource.
Here are my steps to install mongodb 4.0 on ubuntu 18.04 system.
$ curl -fsSL https://www.mongodb.org/static/pgp/server-4.0.asc | sudo apt-key add -
$ echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.0.list
$ sudo apt update
$ sudo apt install mongodb-org
Please note:
- From my test, ubuntu 18.04 doesn't support the latest mongodb 4.4 version, while 4.0 is supported.
- mongodb 4.0 doesn't have arm64 architecture, only amd64 available.
- After installation, mongodb doesn't start up by default, you need to start it by hand.
To start mongodb and enable it as a system service:
$ sudo systemctl start mongod
$ sudo systemctl enable mongod
You will see this port listening on the system:
tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 12953/mongod
Now, let's login into mongodb and issue a query command:
$ mongo
MongoDB shell version v4.0.28
...
---
> show databases
admin 0.000GB
config 0.000GB
local 0.000GB
> use admin
switched to db admin
> show tables
system.version
All done.