Mongodb Osx Install
# Mac OSX Platform Installation of MongoDB
MongoDB provides 64-bit installation packages for the OSX platform. You can download the installation package from the official website.
Download URL: [https://www.mongodb.com/try/download/community](https://www.mongodb.com/try/download/community)
!(#)
> Starting from MongoDB version 3.0, only OS X 10.7 (Lion) and newer versions are supported.
Next, we use the curl command to download and install:
# Go to /usr/local cd /usr/local# Download sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.9.tgz# Extract sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.9.tgz# Rename to mongodb directory sudo mv mongodb-osx-x86_64-4.0.9/ mongodb
After installation, we can add the MongoDB binary command file directory (installation directory/bin) to the PATH:
export PATH=/usr/local/mongodb/bin:$PATH
Create directories for logs and data storage:
* Data storage path:
sudo mkdir -p /usr/local/var/mongodb
* Log file path:
sudo mkdir -p /usr/local/var/log/mongodb
Next, ensure the current user has read and write permissions for the above two directories:
sudo chown /usr/local/var/mongodb sudo chown /usr/local/var/log/mongodb
Create the log file:
sudo touch /usr/local/var/log/mongodb/mongo.log sudo chown /usr/local/var/log/mongodb/mongo.log
The above **** is the username on my computer. You need to modify it according to your current username.
Next, we use the following command to start mongodb in the background:
mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
* **--dbpath** sets the data storage directory
* **--logpath** sets the log storage directory
* **--fork** runs in the background
If you don't want to run in the background and want to view the process on the console, you can start it directly by setting the configuration file:
mongod --config /usr/local/etc/mongod.conf
Check if the mongod service has started:
ps aux | grep -v grep | grep mongod
Using the above command, if you see a record for mongod, it indicates successful startup.
After starting, we can use the mongo command to open a terminal:
$ cd /usr/local/mongodb/bin $ ./mongo MongoDB shell version v4.0.9 connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodbImplicit session: session { "id" : UUID("3c12bf4f-695c-48b2-b160-8420110ccdcf") }MongoDB server version: 4.0.9β¦β¦> 1 + 12>
> Starting from MongoDB 6.0, significant changes have been made. MongoDB no longer installs the shell tool by default. You need to install an additional shell tool: (#)
* * *
## Installation Using brew
Additionally, you can use OSX's brew to install mongodb:
brew tap mongodb/brew brew install mongodb-community@4.4
The **4.4** after the @ symbol is the latest version number.
Installation information:
* Configuration file: **/usr/local/etc/mongod.conf**
* Log file path: **/usr/local/var/log/mongodb**
* Data storage path: **/usr/local/var/mongodb**
### Running MongoDB
We can use the brew command or mongod command to start the service.
Start with brew:
brew services start mongodb-community@4.4
Stop with brew:
brew services stop mongodb-community@4.4
Start mongod command as a background process:
mongod --config /usr/local/etc/mongod.conf --fork To stop this method, you can enter the mongo shell console to achieve it: > db.adminCommand({ "shutdown" : 1 })
YouTip