ubuntu20安装mongodb
方法一:直接安装(命令是直接从mongo官网Install MongoDB Community Edition on Ubuntu — MongoDB Manual复制的)
cat /etc/lsb-release
sudo apt-get install -y gnupg curl
curl -fsSL https://www.mongodb.org/static/pgp/server-7.0.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-7.0.gpg \
--dearmor
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-7.0.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/7.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-7.0.list
sudo apt-get update -y
sudo apt-get install -y mongodb-org
竟然要几个小时,实在太慢了,于是我又改用docker的方式。
方法二:使用docker镜像(参考了这个文章MongoDB从入门到实战之Docker快速安装MongoDB - 知乎
docker pull mongo
docker images
docker run -itd --name mongo_latest -p 27017:27017 mongo
docker ps
docker exec -it mongo_latest mongosh