MongoDB download, installation and configuration in Linux/Mac/Windows environment

Used for mongodb notes

1.Linux

mongodb version 5.0.9

1. Official website download

MongoDB Community Edition download official website
Insert image description here
You can click download directly or click the Copy Link at the back to get the download link.

2. Download and install

wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-5.0.9.tgz

3. Unzip

tar -zxvf mongodb-linux-x86_64-rhel70-5.0.9.tgz

4. Rename for easier reading

mv mongodb-linux-x86_64-rhel70-5.0.9 mongodb

5. Create data and log files

cd mongodb
mkdir data log

6. Configure environment variables

# vim编辑profile
vim /etc/profile
# 添加代码(路径为自己的mongodb路径,每个人每次每台机器是不一样的):
export MONGODB_HOME=/usr/local/mongodb
export PATH=$PATH:$MONGODB_HOME/bin

保存退出(按Esc-->输入  :wq)

vim ~/.bash_profile
添加代码
   	PATH=$PATH:/usr/local/mongodb/bin
保存退出

# 重载使其生效
 source /etc/profile
 source ~/.bash_profile
# 测试是否配置环境变量成功
 mongo --version

2. Mac

mongodb version 6.0.6

1. Official website

MongoDB community edition download official website
Insert image description here

2. Click to download

3. Unzip

tar -zxvf mongodb-macos-x86_64-6.0.6.tgz

4. Move to the specified directory and rename

mv mongodb-macos-x86_64-6.0.6 /usr/local/mongodb

5. Create data and log files

cd mongodb
mkdir data log

6. Configure environment variables

# vim编辑profile
vim /etc/profile
# 添加代码(路径为自己的mongodb路径,每个人每次每台机器是不一样的):
export MONGODB_HOME=/usr/local/mongodb
export PATH=$PATH:$MONGODB_HOME/bin

保存退出(按Esc-->输入  :wq)

vim ~/.bash_profile
添加代码
   	PATH=$PATH:/usr/local/mongodb/bin
保存退出

# 重载使其生效
 source /etc/profile
 source ~/.bash_profile
# 测试是否配置环境变量成功
 mongod --version

At this time, if you execute mongothe command as before, you will find that there is no such command.
The mongo6.x version needs to download and configure mongosh.

7. Download and configure mongosh

Mongolian
Insert image description here

1. 解压缩 mongosh
可以直接双击
2. 移动到和mongodb同级的目录下并重命名
mv mongosh-1.9.1-darwin-x64 /usr/local/mongosh
3. 配置环境变量
和上面mongodb一样。
4. 创建配置文件
cd /usr/local/mongodb
vim mongo.conf
5. 追加以下代码
# 数据库存放路径
dbpath=/usr/local/mongodb/data
# 日志文件
logpath=/usr/local/mongodb/log/mongo.log
# 端口
port=27017
6. 退出保存
7. 启动mongo服务
mongod -f /usr/local/mongodb/mongo.conf

8. Process precautions

8.1 No permission

usesudo

8.2 No write permission

chmod a+w 文件名

To be continued…

Guess you like

Origin blog.csdn.net/s18438610353/article/details/125652907