We will be going through this process together in class, so this isn't strictly a "project" like you've done in the past. However, the successful installation of both MongoDB and Postgres on your machine will be used to pass off the Databases - Level 1 milestone.
Postgres is a very popular open-source relational database that is very well maintained. Fortunately, it's also possibly the easiest one to get installed on your mac, thanks to postgres.app!
Head to postgresapp.com, download the application, and move it to your
Applications folder on your mac.
Running the PostgreSQL server
Double click the application to run the Postgres server, and you're done! There should be an elephant logo in your menu bar which, when clicked, should pop up a window that says "Running on Port 5432".
MongoDB has a few more steps to it. We'll be following the method recommended by the MongoDB documentation for installing: using Homebrew.
- Check if you already have Homebrew installed:
- In a terminal window, type
brew -v. If it responds by telling you the version number installed on your machine, just do a
brew update. If instead you see
-bash: brew: command not found, proceed to the next step.
- In a terminal window, type
- Open the Homebrew home page and follow the (one) instruction for installing Homebrew: paste the code into the terminal and hit enter.
- Make sure Homebrew is up-to-date (especially if you already had it installed): Run
brew updateto update Homebrew to the newest stable version. This might take a little while to complete.
brew install mongodb
- Once brew finishes installing MongoDB, it should show a message telling you that you can start the MongoDB server running by using an upstart process (a process that runs as soon as your machine starts up) by running the command
brew services start mongodb. If running that line doesn't give you an error, you're all set to go and can skip the next section, "Running the MongoDB Server".
Running the MongoDB server
If the above command didn't work, open a terminal window and type
mongod. This window will be taken over by the MongoDB process, and you'll need to leave this running as long as you are planning on doing work with MongoDB.
When you're done using MongoDB for the time being (as in, until the next time you're developing) it's best to shut it down cleanly. Don't just close the terminal window with the mongod process running. Instead, hit Control + c to quit the process. Or you could use one of these other methods if you really want.
You've got those 2 very popular databases installed on your local machine now! One of the trickiest things for a beginner to grasp is the idea of the database running on it's own server on its own port. In the same way a web server needs to be running to accept requests and send back responses in order to work, a database needs to be running on its own server too. So your front-end web application speaks to your back-end application, which in turn speaks to the database.