This is the 14th day of my participation in Gwen Challenge

Mac OS installation

There are two ways to install Mac OS, manually or using Homebrew.

Homebrew is installed

Run the following command on the terminal:

$ brew install mongodb
Copy the code

Manual installation

  • Download the latest stable MongoDB community edition from the MongoDB official website. Care needs to be taken to download the appropriate version, especially to check whether the operating system is 32-bit or 64-bit. The downloaded file is in TGZ format.
  • Decompress the file in the downloaded folder as follows:
$ tar xvf mongodb-osx-xyz.tgz
Copy the code

The file name is determined based on the downloaded file. After the decompression is complete, there is a bin subdirectory under the folder, which contains the executable files mongod and mongo required to run MongoDB.

  • The default server saves data to a directory/data/db. Therefore, you need to create this folder. Running if you do not want to save to the default directorymongod“Needs to be specifieddbpathParameters, i.e.,Mongod --dbpath {data hold path}.
$ sudo bash
# mkdir -p /data/db
# chmod 777 /data
# chmod 777 /data/db
# exit
Copy the code
  • When running the server, you can run the MongoDBbinRun under directory./mongodThe default port is 27017. You can also edit the source path for convenience. Take ZSH as an example:
$ vim ~/.zshrc

#Export the Mongod environment variableExport PATH="{mongo decompress directory}/bin"
$ source ~/.zshrc
Copy the code
  • When you run the client, you can run it in the same directory./mongoCan. The default is to connect totestThe database. You can rundb.test.find()Find data (null by default).

Windows installation

  • Download the latest stable MongoDB community edition from the MongoDB official website. Care needs to be taken to download the appropriate version, especially to check whether the operating system is 32-bit or 64-bit. The downloaded file is in EXE format.
  • Run the exe file to start the installation guide, accept the license agreement, and click “Next” along the way until the installation is complete. If you have permission to ask the administrator, click Agree.
  • The default installation path isC:/Program FIles/MongoDB/Server/{version}/bin.
  • binThe directory contains multiple executables, includingmongodandmongo. To run in another directory, we need to add the environment variable:
    • Right click on “My Computer” and select Properties.
    • Click “Advanced System Settings” in the left panel.
    • In the Advanced column, click Environment Variables.
    • Select the “Path” parameter in the system variable and click Edit.
    • In Win10 before, directly in the original parameters to increase the semicolon (English) after the addition of mongo installation path can be. Win10 after the system, click the new button can add a path.
    • Click ok to save the environment variables.
  • Create a directory named data and subdirectory db under the folder where you want to run the server. Run from the command line in this directorymongodCommand.
  • Allow in another command line windowmongoCan run the client, and connect to the server, the default database istest. The installation verification is complete.

Linux installation

The Linux installation is basically the same as the Mac OS.

Debian class system (using apt-get)

  • Import MongoDB repository key:
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
gpg: Total number processed: 1\
gpg:							imported 1 (RSA: 1)
Copy the code
  • Add Ubuntu Repositories to the package list:
#Ubuntu 16.04 later
$ echo "Deb xenial/mongo - http://repo.mongodb.org/apt/ubuntu org / {version} multiverse"| sudo tee/etc/apt/sources list. D/mongo - org - {version}. The list
#Ubuntu earlier than 16.04
$ echo "Deb trusty/mongo - http://repo.mongodb.org/apt/ubuntu org / {version} multiverse"| sudo tee/etc/apt/sources list. D/mongo - org - {version}. The listCopy the code
  • Update the installation package list
$ sudo apt-get update
Copy the code
  • Install the mongo:
$ sudo apt-get install mongodb-org
Copy the code

Red Hat (yum install)

  • Edit yum install repository information
D /mongodb-org-{version number}.repoCopy the code

Paste the following content:

[mongodb-org-{version}] name= mongodb Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/ {version} / x86_64 / gpgcheck = 1 enabled = 1 gpgkey=https://www.mongodb.org/static/pgp/server- {version}. AscCopy the code
  • Update the installation package list
$ sudo yum update
Copy the code
  • Install the mongo
$ sudo yum install mongodb-org
Copy the code

Minor adjustments may be required depending on the version. For details, see the MongoDB installation guide.