How To Install MongoDB on FreeBSD 10.1

Published on May 26, 2015
How To Install MongoDB on FreeBSD 10.1


MongoDB is a free and open-source NoSQL database. It is one of the most popular databases used in web applications today because it offers high performance, scalability, and lots of flexibility in database schema design. In this tutorial, you will learn how to install and run MongoDB on FreeBSD 10.1.

Note: As of July 1, 2022, DigitalOcean no longer supports FreeBSD Droplets through the Control Panel or API. However, you can still spin up FreeBSD Droplets using a custom image. Learn how to import a custom image to DigitalOcean by following our product documentation.


To follow this tutorial, you need to have:

  • A FreeBSD 10.1 server which is accessible over SSH
  • A user with root privileges; in this tutorial, the user is freebsd
  • SSH key

A FreeBSD server requires an SSH Key for remote access. For help on setting up an SSH Key, read How To Configure SSH Key-Based Authentication on a FreeBSD Server.

Note: Check out the Getting Started with FreeBSD Tutorial Series for help on installing and using FreeBSD 10.1.

Step 1 — Installing the Package Management Tool

Log into your FreeBSD 10.1 server using the command:

  1. ssh freebsd@your_server_ip

FreeBSD uses a tool called pkg to manage binary packages. Update the repository catalogue by typing:

  1. sudo pkg update -f

Step 2 — Installing MongoDB

Now that pkg is ready to be used, install MongoDB and all its dependencies by running the following command:

  1. sudo pkg install mongodb

You might be prompted to update pkg first before installing mongodb. If prompted, press Y. The installation of MongoDB will automatically start after pkg is updated.

You will be shown a list of packages that are going to be installed and asked to confirm if you want to proceed. Press Y to begin the installation.

Step 3 — Allowing MongoDB to Start Automatically At Boot Time

To start MongoDB automatically at boot time, you need to edit the /etc/rc.conf file. You will need to use sudo because root privileges are required. If you want to use nano, you will need to install it with the following command:

  1. sudo pkg install nano

You might have to log out and log back in to get nano added to your default path.

Otherwise, you can use vi:

  1. sudo vi /etc/rc.conf

Add the following line at the end of the file to allow MongoDB’s primary daemon to start automatically when your FreeBSD server is booting up:


Step 4 — Starting MongoDB

You can now reboot your server to start MongoDB automatically. If you don’t want to do that, you can start MongoDB manually using the service command.

  1. sudo service mongod start

MongoDB is up and running.

Step 5 — Configuring MongoDB

Optionally, you can add configuration details to /usr/local/etc/mongodb.conf to customize MongoDB.

For example, to run on port 9000 instead of port 27017 (the default port), add the following to mongodb.conf:

    port: 9000

Every time you modify mongodb.conf, you must restart MongoDB to enable the changes:

  1. sudo service mongod restart

Refer to MongoDB Reference: Configuration File Options for a complete list of options.

Step 6 — Verifying the Installation

Connect to the database using the mongo shell:

  1. sudo mongo

If you changed the configuration to run MongoDB on a different port, run the following instead:

  1. sudo mongo --port <your-port-number>

If everything went well, you will see the following output:

MongoDB shell version: 2.6.7
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
Questions? Try the support group

On a 32-bit FreeBSD server, you will also see the following warnings:

Server has startup warnings: 
2015-05-13T19:01:49.548+0100 [initandlisten] 
2015-05-13T19:01:49.548+0100 [initandlisten] ** NOTE: This is a 32 bit MongoDB binary.
2015-05-13T19:01:49.548+0100 [initandlisten] **       32 bit builds are limited to less than 2GB of data (or less with --journal).
2015-05-13T19:01:49.548+0100 [initandlisten] **       Note that journaling defaults to off for 32 bit and is currently off.
2015-05-13T19:01:49.548+0100 [initandlisten] **       See http://dochub.mongodb.org/core/32bit
2015-05-13T19:01:49.548+0100 [initandlisten]

Though these warnings can be ignored in a development or test environment, it is recommended that you run production instances of MongoDB only on 64-bit servers.


In this short tutorial, you learned how to use the package management tool to install MongoDB on your FreeBSD 10.1 server. To know more about what you can do with your instance of MongoDB, refer to the MongoDB 2.6 Manual.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors
Default avatar
Hathy A


Default avatar
Tammy Fox


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

sudo pkg install mongodb should be replaced by sudo pkg install mongodb44. The first command does not work

there is no need to install nano

plus you can use ee for text editing which is built into freebsd

to add system processes easily to rc.conf for example mongodb using the sysrc command

sudo sysrc mongod_enable=YES

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more
DigitalOcean Cloud Control Panel