3.6. Install MongoDB on Mac OSX platform

发布时间 :2025-10-25 12:33:00 UTC      

MongoDB provides a 64-bit installation package on the OSX platform, which you can download from the official website.

Download address: https://www.mongodb.com/download-center#community

Image0

Starting with MongoDB 3.0, only OS X 10.7 (Lion) and newer systems are supported.

Next we use the curl command to download the installation:

# 进入 /usr/local
cd /usr/local

# 下载
sudo curl -O https://fastdl.mongodb.org/osx/mongodb-osx-ssl-x86_64-4.0.9.tgz

# 解压
sudo tar -zxvf mongodb-osx-ssl-x86_64-4.0.9.tgz

# 重命名为 mongodb 目录

sudo mv mongodb-osx-x86_64-4.0.9/ mongodb

After the installation is complete, we can add the MongoDB binary command file directory (installation directory / bin) to the PATH path:

export PATH=/usr/local/mongodb/bin:$PATH

Create a directory 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, make sure that the current user has read and write permissions to the above two directories:

sudo chown runoob /usr/local/var/mongodb
sudo chown runoob /usr/local/var/log/mongodb

Above runoob It is a user on my computer. You need to modify it according to your current user name.

Next, let’s start mongodb in the background using the following command:

mongod --dbpath /usr/local/var/mongodb --logpath /usr/local/var/log/mongodb/mongo.log --fork
  • –dbpath Set up the data storage directory

  • –logpath Set the log storage directory

  • –fork Run in the background

If you do not want to run on the backend, but view the running process on the console, you can directly set up the configuration file to start:

mongod --config /usr/local/etc/mongod.conf

Check to see if the mongod service starts:

ps aux | grep -v grep | grep mongod

Using the above command, if you see a record of mongod, the operation is successful.

After startup, 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=mongodb
Implicit session: session { "id" : UUID("3c12bf4f-695c-48b2-b160-8420110ccdcf") }
MongoDB server version: 4.0.9
……
> 1 + 1
2
>

3.6.1. Install using brew

You can also use OSX’s brew to install mongodb:

brew tap mongodb/brew
brew install mongodb-community@4.4

After the @ symbol 4.4 It’s 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

Run MongoDB

We can use the brew command or the mongod command to start the service.

Brew launch:

brew services start mongodb-community@4.4

Brew stop:

brew services stop mongodb-community@4.4

Mongod command background process method:

mongod --config /usr/local/etc/mongod.conf --fork

To enable and shut down in this way, you can enter the mongo shell console to achieve:

> db.adminCommand({ "shutdown" : 1 })
Principles, Technologies, and Methods of Geographic Information Systems  102

In recent years, Geographic Information Systems (GIS) have undergone rapid development in both theoretical and practical dimensions. GIS has been widely applied for modeling and decision-making support across various fields such as urban management, regional planning, and environmental remediation, establishing geographic information as a vital component of the information era. The introduction of the “Digital Earth” concept has further accelerated the advancement of GIS, which serves as its technical foundation. Concurrently, scholars have been dedicated to theoretical research in areas like spatial cognition, spatial data uncertainty, and the formalization of spatial relationships. This reflects the dual nature of GIS as both an applied technology and an academic discipline, with the two aspects forming a mutually reinforcing cycle of progress.