Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Mongo Basics Getting Started With MongoDB Setting Up MongoDB

If you're running Linux, here's a MongoDB install guide...

If you're on an Ubuntu variant for development, here's a great guide to get it installed:

https://docs.mongodb.com/v3.0/tutorial/install-mongodb-on-ubuntu/

There are instructions there for other distributions and package managers, as well. Simply cut and paste the commands to add the repo to your package manager and the proceed to the next steps.

Steps in CLI

sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10

echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list

sudo apt-get update

sudo apt-get install -y mongodb-org

Don't worry about the documented run/start of Mongo, as another way is made available below.

Alternate Run/Start Method

For an Ubuntu variant using the CLI to install, create the default directory for MongoDB in root system directory:

sudo mkdir -p /data/db

This creates the needed directory for Mong and adds it as a path to issue the mongod command soon. And then issue the following command from the CLI and substitute username with your own system username that you're using on Linux:

sudo chown -R username /data/db

This will give you (the user) permission to use that folder so that Mongo doesn't throw an error, stating that it either can't find it, write to it, or access it. Once that's done, then issue the final command:

mongod

You should see a multiple line confirmation that the Mongo service has started and the CLI window should just remain open for it to continue to listen for connections. If you're using a JetBrains product, you can also start this from the CLI within the development environment and simply leave that CLI instance open and add another if needed for routine tasks.

2 Answers

I'm running Linux Mint. The command "mongod" doesn't work for me, I tried "sudo mongod" that worked for me!

Just had the same with Ubuntu. Thanks for the tip David.

Yes, it's just going to depend on how you have your system setup, and if you're a "super user" or not in the CLI when it all starts. If not, then "sudo" will elevate your status.

Tom Geraghty
Tom Geraghty
24,174 Points

That's what I did and it worked. I did have some warnings (sudo mongod in terminal 1, and mongo in terminal 2):

WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
We suggest setting it to 'never'

I googled around, and mongo's documentation has instructions on how to turn them off but I wasn't able to find any good explanation of how this might affect my system otherwise.

Did you get this warning on linux? Did you change the huge page setting?

I did a bit of searching around on this, and may have found an answer for you to reference on Stack Overflow, actually. It seems with some configs, you're contending with a restart needed of the actual daemon at the right time, but not the default behavior. Try this solution, which has the highest amount of votes, as it was crafted using the Mongo documentation.

(https://stackoverflow.com/questions/28911634/how-to-avoid-transparent-hugepage-defrag-warning-from-mongodb)

I never encountered this error on my system, and at the time, I was running LInux Mint that had a full install of PHPStorm, for reference. Let me know if this worked for you by modifying the mongod file.