Compiling and Installing MongoDB
This section uses MongoDB 3.6.13 as an example. You can also refer to this section for MongoDB of other versions.
In the following commands, 3.6.13 indicates the MongoDB version. When installing another version, replace 3.6.13 with the actual version.
- Download the MongoDB source package.
1 2
cd /root wget https://github.com/mongodb/mongo/archive/r3.6.13.tar.gz --no-check-certificate
If the wget command fails to be executed, replace github.com with github.com.cnpmjs.org and run the download command again.
- Decompress the MongoDB source package.
1 2
mv r3.6.13.tar.gz mongo-r3.6.13.tar.gz tar -xvf mongo-r3.6.13.tar.gz
- Go to the /root/mongo-r3.6.13 source code directory.
1cd mongo-r3.6.13
- Compile MongoDB. The compilation takes 10 to 15 minutes.
The compilation directory must be greater than 100 GB.
- If the MongoDB version is 3.6.13 or 4.0.12, run the following command:
1python2 buildscripts/scons.py MONGO_VERSION=3.6.13 all CFLAGS="-march=armv8-a+crc -mtune=generic" -j 96 --disable-warnings-as-errors
- If the MongoDB version is 6.1.0, skip this step and run the installation command in 5.
The -j 96 parameter leverages multi-core CPUs to accelerate the compilation. The number following -j indicates the number of CPU cores. You can run the cat /proc/cpuinfo | grep processor | wc -l command to query the number of CPU cores. The value specified must be equal to or less than the number of CPU cores.
Output for the start:

Output for the end:

- If the MongoDB version is 3.6.13 or 4.0.12, run the following command:
- Install MongoDB.
- If the MongoDB version is 3.6.13 or 4.0.12, run the following command to install MongoDB. Specify the installation directory using the prefix option.
1 2
mkdir /usr/local/mongo python2 buildscripts/scons.py MONGO_VERSION=3.6.13 --prefix=/usr/local/mongo --disable-warnings-as-errors CFLAGS="-march=armv8-a+crc" install -j 64
- If the MongoDB version is 6.1.0, run the following command to install MongoDB. Specify the installation directory using the DESTDIR option.
mkdir /usr/local/mongo python3 buildscripts/scons.py MONGO_VERSION=6.1.0 DESTDIR=/usr/local/mongo install-all-meta CFLAGS="-march=armv8-a+crc -mtune=generic" -j 96 --disable-warnings-as-errors
Output for the start:

Output for the end:

After the installation is complete, the bin directory is automatically generated in /usr/local/mongo. Run the following command to view the files in the bin directory:
1ll /usr/local/mongo/bin
- If the MongoDB version is 3.6.13 or 4.0.12, run the following command to install MongoDB. Specify the installation directory using the prefix option.
- Delete the debugging information.
1 2 3 4
cd /usr/local/mongo/bin strip mongos strip mongod strip mongo
