Troubleshooting
Errors when retrieving the public key
During Import the public key used by the package management systemstep of the Install MongoDB Community Edition using .deb Packages procedure, you mayencounter a "gpg: no valid OpenPGP data found."
error.
Ensure you are copying the command exactly as documented. The operationshould respond with OK
.
To check that the MongoDB public GPG key exists on your system,run the following command in the terminal:
- sudo apt-key list
The output should include an entry that resembles the following:
- /etc/apt/trusted.gpg
- /etc/apt/trusted.gpg
pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17] E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6Buid [ unknown] MongoDB 4.2 Release Signing Key <packaging@mongodb.com>
Errors when running sudo apt update
You may encounter one or more errors that resemble the followingwhen running sudo apt-get update
as part of theInstall MongoDB Community Edition using .deb Packages procedure:
- W: GPG error: https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/4.2 Release: \
- The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4B7C549A058F8B6B
- E: The repository 'https://repo.mongodb.org/apt/ubuntu <release>/mongodb-org/4.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.
These errors indicate that the MongoDB Public GPG key was notadded in stepImport the public key used by the package management systemof the Install MongoDB Community Edition using .deb Packages procedure.
Repeating theImport the public key used by the package management systemstep of theInstall MongoDB Community Edition using .deb Packages procedure typically resolves thisissue. Ensure you are copying the command and key exactly as documented.
You can validate that the MongoDB public GPG key exists on your systemby running the following command in the terminal:
- sudo apt-key list
The output should include an entry that resembles the following:
- --------------------
- pub rsa4096 2018-04-18 [SC] [expires: 2023-04-17]
- E162 F504 A20C DF15 827F 718D 4B7C 549A 058F 8B6B
- uid [ unknown] MongoDB 4.2 Release Signing Key <packaging@mongodb.com>
Errors when running sudo apt install -y mongodb-org
You may encounter an error that resembles the following when runningsudo apt install -y mongodb-org
in step Create a list file for MongoDB of theInstall MongoDB Community Edition using .deb Packages procedure:
- Reading package lists... Done
- Building dependency tree
- Reading state information... Done
- E: Unable to locate package mongodb-org
This error indicates that the/etc/apt/sources.list.d/mongodb-org-4.2.list
may be configured incorrectly or is missing.
To review the contents of the mongodb-org-4.2.list
file,run the following command in the terminal or shell:
- cat /etc/apt/sources.list.d/mongodb-org-4.2.list
If the file contents do not exactly match the documentation foryour Ubuntu version in the step linked above, remove the file andrepeat the Create a list file for MongoDB step.If the file does not exist, create it as part of that step.
Once you have validated that the mongodb-org-4.2.list
file exists and has the correct contents, runsudo apt update
to update the apt
repositories andretry sudo apt install -y mongodb-org
.
Unable to install package due to dpkg-deb: error
You may encounter an error that resembles the following wheninstalling the mongodb-org
package:
- dpkg: error processing archive /var/cache/apt/archives/mongodb-org-server_4.2.0_amd64.deb (--unpack):
- trying to overwrite '/usr/bin/mongod', which is also in package mongodb-server-core 1:3.6.3-0ubuntu1
This error indicates that the system already had the Ubuntumongodb
package installed prior to installing the officialMongoDB Inc. mongodb-org
packages. To confirm wheter thehost has the Ubuntu mongodb
package installed, run thefollowing command in a terminal or shell:
- sudo apt list --installed | grep mongo
If your output resembles the following, you must uninstallthe Ubuntu mongodb
package before retrying theInstall MongoDB Community Edition using .deb Packages procedure:
- mongodb/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed]
- mongodb-clients/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,automatic]
- mongodb-server/bionic,bionic,now 1:3.6.3-0ubuntu1 all [installed,automatic]
- mongodb-server-core/bionic,now 1:3.6.3-0ubuntu1 amd64 [installed,automatic]
Run the following commands in a terminal or shell to fully remove theUbuntu mongodb
package before retrying the installationprocedure:
- sudo apt remove mongodb
- sudo apt purge mongodb
- sudo apt autoremove
Note
sudo apt purge mongodb
removes any default configuration filesinstalled by the Ubuntu mongodb
package. If you havemodified these configuration files and want to keep thosemodifications, copy the files to another directory such as/home/your-user-name
.
If your output includes a mix of mongodb-org
andmongodb
binaries, you may need to first apt remove
, aptpurge
, and apt autoremove
the mongodb-org
packagebefore attempting to remove and purge the Ubuntu mongodb
package. After clearing all MongoDB-related packages, retry theinstallation procedure.
mongod reports errors related to opening a socket
You may encounter the Socket is already in use
orFailed to unlink socket file
errors when starting amongod
. These errors generally indicateanother process using the configured port for themongod
process, typically anothermongod
running on the system.
The following example uses the ss
utility to list all openTCP (-t
) or UDP (-u
) sockets in the LISTEN
(-l
) stateand the process using each socket (-p
)without resolving any service names or hostnames (-n
).
- sudo ss --tulpn
The following partial output shows a mongod
processlistening on the 27017
port. Attempting to run another mongod
process on that same port will result in socket errors.
- Netid State Local Address:Port
- udp UNCONN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=663,fd=12))
- udp UNCONN 10.1.16.87%enp0s3:68 users:(("systemd-network",pid=652,fd=15))
- tcp LISTEN 127.0.0.53%lo:53 users:(("systemd-resolve",pid=663,fd=13))
- tcp LISTEN 0.0.0.0:22 users:(("sshd",pid=819,fd=3))
- tcp LISTEN 192.168.1.15:27017 users:(("mongod",pid=10027,fd=12))
- tcp LISTEN 127.0.0.1:27017 users:(("mongod",pid=10027,fd=11))
- tcp LISTEN ::]:22 users:(("sshd",pid=819,fd=4))
If the system has a mongod
or other systemprocess running on your desired port, you must either shut theexisting process down or select a new port for the newmongod
process. You can specify thenet.port
configuration fileoption to change the port that the mongod
listens on.
mongod reports errors related to the data directory
Users may encounter errors that resemble the following in themongod
process log:
- Data directory ... not found
- Attempted to create lock file on a read-only directory: ...
The mongod
uses the directory specified to thestorage.dbPath
configuration file setting or the—dbpath
command line option for storing itsdata files. The directory permission and ownership settings must allowthe mongod
to read, write, and navigate thedirectory contents (rwx
user or group permissions).
The mongod
process does not automatically createits data directory nor can it modify permissions or ownership to gainaccess to the directory. Use utilities like mkdir
, chown
, andchmod
to create directories, modify permissions, and setuser:group
ownership as appropriate prior to starting themongod
.
Users starting the mongod
as a service(e.g. sudo service mongod start
) typically only see these errorsif they modified the default dbPath
value inthe /etc/mongod.conf
to:
- A directory that does not allow the
mongodb
user ormongodb
group to read, write, or execute (rwx
) the directory and itscontents, or - A directory that does not exist.
Users starting the mongod
without using theservice definition (e.g. using the terminal to launch mongod
)typically see these errors if: