Introducing MEVN Chapter 1
Installing MongoDB via Homebrew
To install MongoDB in macOS from Homebrew, follow these steps:
- With Homebrew, we just need a single command to install MongoDB:
$ brew install mongodb
- Create a directory that will be used by Mongo to save data:
$ sudo mkdir -p /data/db
- Start the Mongo server:
$ ~/mongodb/bin/mongod
Hence, MongoDB is finally installed.
Installing MongoDB on Linux
There are two ways to install MongoDB on Linux as well: we can either use the apt-get
command or we can download the tarball and extract it.
Installing MongoDB using apt-get
To install MongoDB using apt-get, perform the following steps:
- Run the following command to install the latest version of MongoDB:
$ sudo apt-get install -y mongodb-org
- Verify if mongod has been successfully installed by running the command:
$ cd /var/log/mongodb/mongod.log
- To start the mongod process, execute the following command in the Terminal:
$ sudo service mongod start
- See if the log file has a line that denotes that the MongoDB connection was made
successfully:
$ [initandlisten] waiting for connections on port
<port>