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 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.
Log into your FreeBSD 10.1 server using the command:
- ssh freebsd@your_server_ip
FreeBSD uses a tool called
pkg to manage binary packages. Update the repository catalogue by typing:
- sudo pkg update -f
pkg is ready to be used, install MongoDB and all its dependencies by running the following command:
- 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.
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:
- 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
- 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:
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
- sudo service mongod start
MongoDB is up and running.
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
net: port: 9000
Every time you modify
mongodb.conf, you must restart MongoDB to enable the changes:
- sudo service mongod restart
Refer to MongoDB Reference: Configuration File Options for a complete list of options.
Connect to the database using the
- sudo mongo
If you changed the configuration to run MongoDB on a different port, run the following instead:
- 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 http://docs.mongodb.org/ Questions? Try the support group http://groups.google.com/group/mongodb-user >
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.