44

When I attempt to install mongodb using the instructions on https://docs.mongodb.com/getting-started/shell/tutorial/install-mongodb-on-ubuntu/ on 16.04 I get the following result on the install step:

jonathan@poseidon:~$ sudo apt-get install mongodb-org
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Package mongodb-org is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

E: Package 'mongodb-org' has no installation candidate

I checked the HTTP traffic with Wireshark and found that the only traffic was a HTTP GET for the list and a HTTP 304 response which suggests that the problem lies in my local configuration files. My sources.list.d file contains the following entry:

mongodb-org-3.4.list

What do I need to do to continue to troubleshoot this problem?

EDIT: I tried to do this again on a new install of 16.04 under VirtualBox. I retrieved the key, created the list file, and did sudo apt update with the following results:

jonathan@Ubuntu-16:~$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
[sudo] password for jonathan: 
Executing: /tmp/tmp.uWYpRUWfjK/gpg.1.sh --keyserver
hkp://keyserver.ubuntu.com:80
--recv
0C49F3730359A14518585931BC711F9BA15703C6
gpg: requesting key A15703C6 from hkp server keyserver.ubuntu.com
gpg: key A15703C6: public key "MongoDB 3.4 Release Signing Key <[email protected]>" imported
gpg: Total number processed: 1
gpg:               imported: 1  (RSA: 1)
jonathan@Ubuntu-16:~$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse
jonathan@Ubuntu-16:~$ sudo apt update
Ign:1 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 InRelease
Get:2 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release [3 462 B]
Hit:3 http://mx.archive.ubuntu.com/ubuntu xenial InRelease               
Get:4 http://security.ubuntu.com/ubuntu xenial-security InRelease [94.5 kB]                   
Get:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release.gpg [801 B]                      
Get:6 http://mx.archive.ubuntu.com/ubuntu xenial-updates InRelease [95.7 kB]           
Ign:5 http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release.gpg                       
Get:7 http://mx.archive.ubuntu.com/ubuntu xenial-backports InRelease [92.2 kB]                    
Reading package lists... Done      
W: GPG error: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY D68FA50FEA312927
E: The repository 'http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.
jonathan@Ubuntu-16:~$ 

As you can see, the key retrieved was for Mongodb 3.4, not Mongodb 3.2 and this explains the GPG failure in apt update. Any one know where to get the correct key?

0

10 Answers 10

120

Ubuntu 18.04 and MongoDB 4.2

First, remove MongoDB from previous if installed:

sudo apt remove --autoremove mongodb-org

Remove any mongodb repo list files:

sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update

Now, add the new key:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B

Add the new repository:

echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list

Install MongoDB

sudo apt update
sudo apt install mongodb-org

Enable and start the mongod server service:

systemctl enable mongod.service
systemctl start mongod.service

Check your installation:

~$ mongo --version
MongoDB shell version v4.2.2
git version: a0bbbff6ada159e19298d37946ac8dc4b497eadf
OpenSSL version: OpenSSL 1.1.1  11 Sep 2018
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1804
    distarch: x86_64
    target_arch: x86_64

You can also check your service has started:

~$ systemctl status mongod.service 
● mongod.service - MongoDB Database Server
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: e
   Active: active (running) since Mon 2019-12-30 08:05:48 MST; 1min 7s ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 7941 (mongod)
   CGroup: /system.slice/mongod.service
           └─7941 /usr/bin/mongod --config /etc/mongod.conf

Ubuntu 20.04 and MongoDB 4.4 or MongoDB 5.0

First, remove MongoDB from previous if installed:

systemctl stop mongod.service
systemctl disable mongod.service
sudo apt remove --autoremove mongodb-org

Remove any mongodb repo list files:

sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update

Now, add the new key for MongoDB 4.4:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 656408E390CFB1F5

The new key for MongoDB 5.0:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv B00A0BD1E2C63C11

Add the new repository for MongoDB 4.4:

echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu $(lsb_release -sc)/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list

Or the new repository for MongoDB 5.0:

echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu $(lsb_release -sc)/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list

Install MongoDB

sudo apt update
sudo apt install mongodb-org

Enable and start the mongod server service:

systemctl enable mongod.service
systemctl start mongod.service

Check your installation:

~$ mongo --version
MongoDB shell version v4.4.3
Build Info: {
    "version": "4.4.3",
    "gitVersion": "913d6b62acfbb344dde1b116f4161360acd8fd13",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

Or

$ mongo --version
MongoDB shell version v5.0.2
Build Info: {
    "version": "5.0.2",
    "gitVersion": "6d9ec525e78465dcecadcff99cce953d380fedc8",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

You can also check your service has started:

~$ systemctl status mongod.service 
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset>
     Active: active (running) since Sun 2021-01-24 07:52:50 MST; 27s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 2353629 (mongod)
     Memory: 59.2M
     CGroup: /system.slice/mongod.service
             └─2353629 /usr/bin/mongod --config /etc/mongod.conf

Jan 24 07:52:50 terrance-ubuntu systemd[1]: Started MongoDB Database Server.

Ubuntu 22.04 and MongoDB 6.0

The MongoDB repos are not 100% ready for 22.04 yet, so you will have to use the Focal repository from them to install it. Also, the repo doesn't have the key ready for GPG since apt-key is now deprecated, but these instructions still work for now.

First, remove MongoDB from previous if installed:

systemctl stop mongod.service
systemctl disable mongod.service
sudo apt remove --autoremove mongodb-org

Remove any mongodb repo list files:

sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt update

You might need to install gpg before doing the next step.

sudo apt install gpg

Now, add the new key for MongoDB 6.0:

curl -fsSL https://pgp.mongodb.com/server-6.0.asc | sudo gpg --dearmor -o /usr/share/keyrings/mongodb60.gpg

Add the new repository for MongoDB 6.0 (You have to use the Focal repo as the Jammy repo does not contain the mongodb-org install for the mongod server):

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/mongodb60.gpg] http://repo.mongodb.org/apt/ubuntu focal/mongodb-org/6.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org.list

Install MongoDB

sudo apt update
sudo apt install mongodb-org

Enable and start the mongod server service:

systemctl enable mongod.service
systemctl start mongod.service

Check your installation:

mongod --version
db version v6.0.2
Build Info: {
    "version": "6.0.2",
    "gitVersion": "94fb7dfc8b974f1f5343e7ea394d0d9deedba50e",
    "openSSLVersion": "OpenSSL 1.1.1f  31 Mar 2020",
    "modules": [],
    "allocator": "tcmalloc",
    "environment": {
        "distmod": "ubuntu2004",
        "distarch": "x86_64",
        "target_arch": "x86_64"
    }
}

systemctl status mongod.service 
● mongod.service - MongoDB Database Server
     Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset>
     Active: active (running) since Thu 2022-10-13 08:13:21 MDT; 39s ago
       Docs: https://docs.mongodb.org/manual
   Main PID: 44048 (mongod)
     Memory: 68.1M
        CPU: 1.169s
     CGroup: /system.slice/mongod.service
             └─44048 /usr/bin/mongod --config /etc/mongod.conf

Oct 13 08:13:21 terrance-ubuntu systemd[1]: Started MongoDB Database Server.

Hope this helps!

8
  • 6
    Thanks for this. Getting the right key was the critical part.
    – Jonathan
    Oct 29, 2016 at 0:14
  • gpg: keyserver receive failed: Server indicated a failure Oct 13, 2017 at 14:31
  • @MáximaAlekz Check my answer.
    – Tpojka
    Feb 14, 2018 at 12:52
  • Thanks a lot, @Terrance. You saved me a lot of time. Oct 7, 2018 at 13:26
  • Lots of thanks for this. it helped me a lot after trying so many other tutorials. great answer.
    – BC Smith
    Jan 30, 2021 at 21:38
16

In addition to @Terrance 's answer, here is how you can find appropriate sig key. Example is applicable to mongodb in this case but can be used for any other package similarly. Before you execute lines from @Terrance 's answer:

  1. Go to ubuntu key server to find actual key

  2. Search for string of interest (mongodb in case) and submit that first form (you don't need second form for this) - click Search! button

enter image description here

  1. On provided search list seek for your version (it was 3.4 in my case here in example)

enter image description here

  1. You can see two rows with keys there. Focus on most actual by date. First string is date created while second one is date valid due.

  2. Use sig from row mentioned in point 5 - in case from picture it would be A15703C6

  3. Continue with Terrance 's answer wether you need to install package or upgrade like myself

2
  • 2
    Thanks. This saved me a lot of time!
    – akazuko
    Mar 12, 2019 at 5:54
  • Incredible that this isn't more plainly explained in documentation. Why provide signed releases when you hide the methods to use the signatures? Feb 27, 2020 at 17:20
2

First run:

$ sudo rm /etc/apt/sources.list.d/mongodb*.list

It would be recommended to also remove any lines that are related to MongoDB from the /etc/apt/sources.list file.

Then do a fresh installation of MongoDB using the commands provided in the official MongoDB intstallation instructions for Ubuntu.

Commands in provided link are given below

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

sudo apt-get install gnupg

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


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


sudo apt-get update

sudo apt-get install -y mongodb-org

sudo service mongod start

sudo service mongod status
1
  • can you include commands from this link inside your answer?
    – damadam
    Dec 9, 2019 at 8:21
1

Nothing worked for me either, so I went to the mogodb website and followed these instructions to install from tarball:

Install dependencies:

sudo apt-get install libcurl3 openssl

Download the tarball from this page

cd to the Downloads directory or wherever the file went, and extract it:

tar -zxvf mongodb-linux-*-4.0.1.tgz

The binaries are in the bin directory of the extracted structure. You can add this directory to PATH or copy the files to /usr/local/bin or another PATH location.

1
  • You installed a different version then what was listed above at the time so the answers will not have worked for you. I have updated my answer since. For each version the key changes and the repository changes. I will try to keep my answer updated for new stable versions as they come out.
    – Terrance
    Sep 14, 2018 at 14:02
0

I was struggling today to install mongodb 4.2 in Ubuntu 20.04.1 LTS (Focal Fossa). I am a new user and its took me time to figure it out. Answer written by @Terrance helped me to solve my problem. I followed the below steps to install it in my system:

sudo rm /etc/apt/sources.list.d/mongodb*.list 
sudo apt update
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 4B7C549A058F8B6B
echo "deb [arch=amd64] http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt update
sudo apt install mongodb-org

Hope this will help others. Thank you.

0

SOLVED N.B. Check your version, in this case is 3.2

curl -sLO https://www.mongodb.org/static/pgp/server-3.2.asc && sudo /usr/bin/apt-key add server-3.2.asc
0

Hopefully, this can be helpful for installing MongoDB version 3.4.17

(this worked for me in ubuntu focal 20.04.01 LTS but hopefully it would work on other versions as well!)

Try this:

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6

echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list

sudo apt update


apt-cache policy libssl1.0-dev

sudo apt-get install libssl1.0-dev


sudo apt-get install -y mongodb-org=3.4.17 mongodb-org-server=3.4.17 mongodb-org-shell=3.4.17 mongodb-org-mongos=3.4.17 mongodb-org-tools=3.4.17
0
0

I was also facing the same problem.......

https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-ubuntu/

go to this link and follow the steps...... this worked for me

1
  • 1
    While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – David
    Mar 30, 2022 at 6:25
0

SOLVED

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

This worked on Pop OS

Since I spent some time on this, I thought it would be good to share what worked for me:

1 - remove the previous install as explained in this answer: https://askubuntu.com/a/842599/1660808

2 - follow the instructions on this link: https://askubuntu.com/a/1399874/1660808 - this answer gives you a link, there you'll find some instructions, follow them.

3 - Use the part of this answer that helps you verify the installation: https://askubuntu.com/a/842599/1660808 - notice that if you are on mongo 6.+, the shell command is mongod --version

This installed mongo v6.0.3 and it seems to be working ok

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .