如何使用自制软件安装 mongodb 的早期版本?

How to install earlier version of mongodb with homebrew?

我在 osx6.8 上,需要安装 Mongodb 的早期版本,如何使用 HomeBrew 安装早期版本?

以下无效:(

dream-2:app2 star$ brew install mongodb-2.6.10
Error: No available formula for mongodb-2.6.10 
Searching formulae...
Searching taps...
dream-2:app2 star$ 

编辑:
我收到一条消息,解释 post 与另一个问题相比有何独特之处,好吧,另一个问题的答案超长且复杂,它特定于 postgresql,并没有真正回答我的问题。

当尝试使用自制软件安装旧版本时,从 brew search packagename 开始通常很有用,在这种情况下,homebrew/versions/mongodb26

下有一个 2.6 版本可用

因此,要安装该版本:

brew install homebrew/versions/mongodb26

编辑

这个答案肯定已经过时了。查看 ,了解在 2021 年实现此目标的有效方法。

我能够使用这些说明安装它:

Installing MongoDB on OSX for local development

Over the last week, I’ve been building our MongoDB cluster on EC2 for production. For development, however, we’ll still need to install MongoDB locally. I’m running OSX 10.6.8, but these install instructions should be the same on all modern OSX versions.

Installing on OSX is much more pleasant than on EC2 (actually it’s just as easy on EC2, but since it’s a simpler setup there’s n real configuration or head scratching).

Download the latest binary:

curl -O http://fastdl.mongodb.org/osx/mongodb-osx-x86_64-2.0.2.tgz

Note!: If you don’t have wget installed, simply download the file above by visiting the link in your web browser and move it into your home directory.

We’re going to install everything under /usr/local/mongodb to keep things organized.

Create the directories (switch 'youruser' with your home user name):

sudo mkdir /usr/local/mongodb

sudo mkdir /usr/local/mongodb/log

sudo mkdir/usr/local/mongodb/data

sudo chown youruser /usr/local/mongodb/log

sudo chown youruser /usr/local/mongodb/data

sudo chgrp staff /usr/local/mongodb/log

sudo chgrp staff /usr/local/mongodb/data

Un-tar the binaries and move them into the correct folder:

tar -xvzf ~/mongodb-osx-x86_64-2.0.2.tgz

sudo mv ~/mongodb-osx-x86_64-2.0.2/* /usr/local/mongodb/

Create a config file for mongod:

sudo vi /usr/local/mongodb/mongod.conf

Paste:

dbpath=/usr/local/mongodb/data

logpath=/usr/local/mongodb/log/mongod.log

logappend=false

bind_ip=127.0.0.1

Note: dbpath and logpath specify the path to their respective files, logappend is set to overwrite the log file on each start of the database server, bind_ip only allows local connections.

Create an alias so that issuing mongod always read the config file:

vi ~/.profile

Paste:

# MongoDB Alias'

alias mongod="/usr/local/mongodb/bin/mongod --config=/usr/local/mongodb/mongod.conf"

All done, you should be able to simply type mongod after you reload the shell to start MongoDB. I preferred not to start mongod on boot, but there are other who prefer to and there’s plenty of documentation online to show you how to set that up with launchd and creating a .plist.

http://alexanderwong.me/post/15259867190/installing-mongodb-on-osx-for-local-development

curl -O https://fastdl.mongodb.org/osx/mongodb-osx-x86_64-3.2.12.tgz
tar -zxvf mongodb-osx-x86_64-3.2.12.tgz
mkdir -p mongodb
cp -R -n mongodb-osx-x86_64-3.2.12/ mongodb
export PATH=<mongodb-install-directory>/bin:$PATH #path to the dir created in step 3
mkdir -p /data/db
sudo chown -R $(whoami) /data/
mongod

Note: In September 2019 mongodb was removed from homebrew core, so these instructions have been updated to use mongodb-community instead, installed from the external tap.

If your current installation is still the pre-September mongodb package then you will need to use that name when you unlink, stop, relink and start, on the lines marked with #*# below.

Another option is to simply away from the deprecated package now.

我已经安装了最新版本的 mongo,谢谢。

brew tap mongodb/brew

brew install mongodb-community

但有时我想切换到旧版本。首先,安装它:

brew search mongo

brew install mongodb-community@3.2

让我们停止当前的mongodb,如果它是运行:

brew services stop mongodb/brew/mongodb-community           #*#

# or if you had started it manually

killall mongod

现在我想在我的 PATH 上使用 3.2 而不是最新的:

brew unlink mongodb-community                               #*#

brew link --force mongodb-community@3.2

(显然它需要 --force 因为它只装桶。)

现在我的 PATH 上有 3.2,我可以启动测试数据库了:

mongod --version

brew services start mongodb/brew/mongodb-community

# or start your own mongod from the command-line

完成后,我可以反向切换回最新版本:

brew services stop mongodb/brew/mongodb-community

brew unlink mongodb-community@3.2

brew link mongodb-community                                 #*#

brew services start mongodb/brew/mongodb-community          #*#

然后重新启动。

您可以使用 docker 来安装任意多个版本的 mongodb,而不是使用自制软件。然后每个 mongodb 可以 运行 在不同的端口上。

使用 brew cask install docker 安装 docker,然后打开 Docker.app。在 docker 是 运行ning 之后,转到终端并通过从 https://hub.docker.com/_/mongo/ 中选择图像来安装您的 mongodb 版本,如下所示:docker run -d -p 28017:27017 --name mongo4 mongo:latest

验证它是 运行 docker ps,您可以使用端口 28017 从您的应用程序连接到 mongodb。使用不同的名称和端口重复这些步骤以安装更多版本。享受吧!

除了 joeytwiddle 的出色回答:

如果您不想link然后取消link旧版本的软件,您可以运行它来自"cellar" (/usr/local/Cellar/), brew 安装它的地方。 使用 ls /usr/local/Cellar/ 查找可执行文件的确切路径。例如在我的例子中,运行 mongo shell:

/usr/local/Cellar/mongodb@3.6/3.6.7/bin/mongo

如果您想在 mac 上安装较早的 MongoDB 版本。转到 link https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-os-x/ 和 select 您要安装的版本,安装非常简单,请尝试一下。将有大约 2-3 个安装命令。

例如,如果你想安装版本 3.6

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

如果出现错误

If you need to have mongodb-community@3.6 first in your PATH run:
  echo 'export PATH="/usr/local/opt/mongodb-community@3.6/bin:$PATH"' >> ~/.bash_profile

然后运行

export PATH="/usr/local/opt/mongodb-community@3.6/bin:$PATH"

确认是否安装成功:

mongod -version