NoSQL: Environment Setup and Installation on OSX

Udemy.com Home page wide-banner

In this part of this article’s series, we are going to install and set up all the necessary programs to make things work with MongoDB in an OSX environment. I will directly provide you with the links to download everything in order to make the process easier.

Installing Brew

Brew is a package manager that we will make use of in order to install pieces of software onto our machine. Later, after its installation, we will start to use it by downloading important tools for our environment such as NodeJS, MongoDB( of course! ) and RoboMongo.

Start by going to the installation link, you will find yourself on the brew package manager main page. Here, you will be able to notice a little script under the: Install HomeBrew section:

 

homebrew homepage screenshot

That script over there is an installation script! Copy it and paste it onto your terminal like so:

homebrew installation script

Press Enter and wait for the installation. The process should take about a minute or so. Once you’re done, we can move on to the next step:

Installing NodeJS

If you don’t know what NodeJS is, well basically we can consider it as Javascript on the server. Since it’s very unlikely that you already have it installed on your machine, we will use brew package manager to perform this specific task:

Type in your terminal the following command to start the installation:

brew install node script

A note of recommendation

In case you already have NodeJS installed, you can check your current version by typing in:

node version check code

In that case, try to be updated with a version older than number 4. If you have a version previous than that, run the following command to upgrade node:

homebrew update node

Installing MongoDB

And now the harder part: the installation and set up of our database. To perform this task, type in your terminal:

homebrew install mongo db code

Now, once you have finished the installation process, you will be able to use a new command from the command line called: mongod. This command, when used, is going to start up a local server for us. Let’s type this inside our terminal and proceed with the steps:

But First…

Unluckily, since we are on an OSX environment, the process to install MongoDB is a little bit harder. In fact, we can’t just use the mongod command. First, we have to go through other little steps of configuration that include:

  • Creating the \data\db folder for storing our data
  • taking ownership of the newly created folder

Creating the data folder

MongoDB, as a database, requires us to provide an actual location on our local machine to store the data that we will memorize inside of it. These data will be put in a folder called \data\db. And by chances, you don’t already have that folder on your local operating system. So:

  • Start the command prompt
  • Create the folder by typing in the command :

create folder example code osx

Taking ownership of our data folder

Now we need to take ownership of our newly created folder to perform operations on it by following these steps:

Type in:

whoami code example

This command will tell you the name of the currently logged in user, so this is gonna be dependent on you. We will use this name to take ownership of the data folder using this command:

ownership code example

And finally

Type in this command to start the server:

osx start mongo command

You should, if everything was performed correctly, a message that says something like:

Waiting for connections on port 27017

One last thing

To avoid having to start MongoDB over and over during time, we will make use of a special part of the Mongod that will allow us to only startup Mongo once manually, and from that moment on we will always have it available, whether we closed our terminal or even turned off our machine. Brew will take care of starting Mongo for us leaving less work to do. To do this, type in:

brew start service mongodb

You should, if everything was performed correctly, a message that says something like:

Successfully started ‘MongoDB’

A companion tool : RoboMongo:

Now that we have everything set up for MongoDB, we will install another little tool called RoboMongo. This tool will help us to visualize the data that are sitting inside our database.

To do this, follow along with these steps:

  • Go to the download section of this:  website
  • Click on the: download Robo3t button and download the mac executable
  • Drag RoboMongo inside the installation folder
  • Startup RoboMongo

At the end of this process, you should have a window open that looks like this:

robo3t screenshot

To establish a new connection to the local database that we just setup follow these steps:

  • Go to the file menu on the top left of the RoboMongo window
  • Select connect
  • Click on the create link button on top of the new window that appears.

connections screenshot

A database connection creation form will open, follow the steps:

  • Leave the Address as it is and change the name if you want
  • Click on the save button
  • Now select this new connection and click on the connect button

MongoDB Connection Settings local

We are done!

And we are done also for this step! Now you will have all of your configurations properly set up and you are finally ready to start using MongoDB. In the next sections, we are going to start writing in some code to learn using this amazing technology.

The next part of the series is Building our First Application & Connecting To MongoDB, check it out.

Interesting Links

Follow me on twitter @BorrelliDev or check out my blog thecoderswag.com. Stay tuned!

NoSQL: Environment Setup and Installation on OSX

You May Also Like

Leave a Reply

Your email address will not be published.