Tutorial

How To Install MongoDB on FreeBSD 10.1

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

Introduction

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.

Prerequisites

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:

mongod_enable="YES"

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:

/usr/local/etc/mongodb.conf
net:
    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
	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.

Conclusion

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

author


Default avatar
Tammy Fox

editor


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
2 Comments


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!

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.