Sunday, September 24, 2023
 Popular · Latest · Hot · Upcoming
rated 0 times [  14] [ 0]  / answers: 1 / hits: 20148  / 1 Year ago, sun, october 23, 2022, 9:26:42

Unfortunately the official Ubuntu package for MongoDB is still stuck on 2.6, which is ancient at this point (this bug didn't get picked up for vivid, wily or xenial).

MongoDB has not yet released a package for 16.04 (Xenial), so how can I use the 14.04 (Trusty) packages to install MongoDB 3.2+ on 16.04?

More From » 16.04


It's a bit of a hack but yes, this can be done. There is an undocumented step needed to actually start the service and (weirdly enough) unless you want to futz around with upstart job conversion manually, you need to install the Ubuntu mongodb package first, then remove it so that you have a usable service. A straight install of the MongoDB packages will not give you a working service on a fresh 16.04.

Update - July 2016: The official fix for this (adding support for 16.04 to the packages) has been completed in the 3.3 dev branch as part of SERVER-23043 - and has been released as a backport in the 3.2 series as part of 3.2.7. Hence, if you are using 3.2.7+ you do not need to do this and the official MongoDB package install should just work.

In any case, after doing the add/remove, follow the usual instructions for 14.04, summarized here:

# install the Ubuntu package (to get the service set up correctly)
sudo apt-get install mongodb
# Now remove it and continue with the MongoDB instructions
sudo apt-get remove mongodb
sudo apt-get autoremove
# import key
sudo apt-key adv --keyserver hkp:// --recv EA312927
# add trusty repos
echo "deb trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
# update apt
sudo apt-get update
# install the MongoDB package
sudo apt-get install -y mongodb-org

The install succeeds, and thanks to the Ubuntu package we have all the pieces needed for a service, but attempting to start the service will initially fail:

$ sudo service mongodb start
Failed to start mongodb.service: Unit mongodb.service is masked.

Fixing this is not too hard:

$ sudo systemctl unmask mongodb
Removed symlink /etc/systemd/system/mongodb.service.

Now we can enable/start the service, get its status etc.

$ sudo service mongodb enable
$ sudo service mongodb start
$ sudo service mongodb status
● mongodb.service - LSB: An object/document-oriented database
Loaded: loaded (/etc/init.d/mongodb; bad; vendor preset: enabled)
Active: active (running) since Thu 2016-04-14 16:40:35 IST; 7s ago
Docs: man:systemd-sysv-generator(8)
Process: 2849 ExecStart=/etc/init.d/mongodb start (code=exited, status=0/SUCCESS)
Main PID: 1593 (code=exited, status=0/SUCCESS)
Tasks: 13 (limit: 512)
Memory: 51.9M
CPU: 100ms
CGroup: /system.slice/mongodb.service
└─2861 /usr/bin/mongod --config /etc/mongodb.conf

Success - and we get a nice pointer to the active config file (which is in the old key=value format, see here for examples in the newer recommended YAML format).

Note: There will actually be two config files /etc/mongod.conf and /etc/mongodb.conf thanks to slight differences between the two packages we have installed. The now-active service points to the old-format one by default /etc/mongodb.conf - you can switch by moving/copying the mongod.conf to mongodb.conf if you so wish, or simply edit the file directly.

Once started, to test, connect to the database with the mongo shell:

$ mongo
MongoDB shell version: 3.2.5
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group
Server has startup warnings:
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten]
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten] ** WARNING: Access control is not enabled for the database.
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten] ** Read and write access to data and configuration is unrestricted.
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten]
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten]
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten]
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-04-14T16:40:34.962+0100 I CONTROL [initandlisten]

If you wish to get rid of the THP warnings, check out this answer.

[#15886] Monday, October 24, 2022, 12 Months  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.

Total Points: 66
Total Questions: 120
Total Answers: 115

Location: Norway
Member since Sat, Mar 4, 2023
7 Months ago
anxietunnel questions