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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30379127/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 20:26:49  来源:igfitidea点击:

How to install earlier version of mongodb with homebrew?

mongodbhomebrew

提问by Agent Zebra

I'm on osx6.8 and need to install an earlier version of Mongodb, how do I install an earlier version with HomeBrew? The below didn't work :(

我在 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$ 

((( **edit: I'm getting a message to explain how this post is unique compared to another one, well, the answer to the other question is super long and complex and it's specific to postgresql and doesn't really answer my question.)))

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

采纳答案by Cody Haines

When trying to install old versions of something with homebrew, it's usually useful to start with brew search packagename, in this case, there's a 2.6 version available under homebrew/versions/mongodb26

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

So, to install that version:

因此,要安装该版本:

brew install homebrew/versions/mongodb26

回答by joeytwiddle

Note: In September 2019 mongodbwas removedfrom homebrew core, so these instructions have been updated to use mongodb-communityinstead, installed from the external tap.

If your current installation is still the pre-Septembermongodbpackage 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 upgradeaway from the deprecated package now.

注意:2019 年 9 月已从 Homebrew 核心mongodb删除,因此这些说明已更新为使用mongodb-community,从外部水龙头安装。

如果您当前的安装仍然是9 月之前的mongodb软件包,那么您在取消链接、停止、重新链接和启动时将需要在#*#以下标记的行中使用该名称。

另一种选择是现在简单地从弃用的软件包升级

I already have the latest version of mongo installed, thanks to.

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

brew tap mongodb/brew

brew install mongodb-community

But I want to switch to the old version sometimes. First, install it:

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

brew search mongo

brew install [email protected]

Let's stop the current mongodb, if it is running:

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

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

# or if you had started it manually

killall mongod

Now I want 3.2 on my PATH instead of the latest:

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

brew unlink mongodb-community                               #*#

brew link --force [email protected]

(Apparently it needs --forcebecause it is keg-only.)

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

Now I have 3.2 on my PATH, I can start the test DB:

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

mongod --version

brew services start mongodb/brew/mongodb-community

# or start your own mongod from the command-line

When I am finished, I can do the reverse to switch back to the latest version:

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

brew services stop mongodb/brew/mongodb-community

brew unlink [email protected]

brew link mongodb-community                                 #*#

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

And restart again.

并重新启动。

回答by Vidar

Instead of using homebrew you can use docker to install as many versions of mongodb as you want. Each mongodb can then run on separate ports.

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

Install docker with brew cask install dockerand then open Docker.app. After docker is running, go to Terminal and install your mongodb version by selecting an image from https://hub.docker.com/_/mongo/like so: docker run -d -p 28017:27017 --name mongo4 mongo:latest

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

Verify that it's running with docker psand you can connect to mongodb from you app using port 28017. Repeat the steps with a different name and port to install more versions. Enjoy!

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

回答by xiaoju

Addition to the excellent answer of joeytwiddle :

除了 joeytwiddle 的优秀答案:

if you don't want to link then unlink the old version of the software, you can just run it from the "cellar" (/usr/local/Cellar/), where brew installed it. Use ls /usr/local/Cellar/to find the exact path of the executable. For example in my case, to run mongo shell:

如果您不想链接然后取消旧版本软件的链接,您可以从/usr/local/Cellar/安装了 brew的“地窖”( ) 运行它。使用ls /usr/local/Cellar/查找可执行文件的确切路径。例如在我的情况下,运行 mongo shell:

/usr/local/Cellar/[email protected]/3.6.7/bin/mongo

回答by Livi17

I was able to install it using these instructions:

我能够使用以下说明安装它:

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.

在 OSX 上安装 MongoDB 进行本地开发

上周,我一直在 EC2 上构建我们的 MongoDB 集群以进行生产。但是,对于开发,我们仍然需要在本地安装 MongoDB。我正在运行 OSX 10.6.8,但这些安装说明在所有现代 OSX 版本上都应该相同。

在 OSX 上安装比在 EC2 上安装要愉快得多(实际上在 EC2 上安装也一样容易,但由于它的设置更简单,因此无需进行真正的配置或头疼)。

下载最新的二进制文件:

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

注意!:如果您没有安装 wget,只需通过访问 Web 浏览器中的链接下载上面的文件并将其移动到您的主目录中。

我们将把所有东西都安装在 /usr/local/mongodb 下以保持井井有条。

创建目录(使用您的家庭用户名切换“您的用户”):

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

解压二进制文件并将它们移动到正确的文件夹中:

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

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

为 mongod 创建一个配置文件:

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

粘贴:

dbpath=/usr/local/mongodb/data

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

logappend=false

bind_ip=127.0.0.1

注意:dbpath 和 logpath 指定各自文件的路径,logappend 设置为每次启动数据库服务器时覆盖日志文件,bind_ip 只允许本地连接。

创建一个别名,以便发出 mongod 始终读取配置文件:

vi ~/.profile

粘贴:

# MongoDB Alias'

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

全部完成后,您应该能够在重新加载 shell 以启动 MongoDB 后简单地输入 mongod。我不想在启动时启动 mongod,但还有其他人更喜欢,并且有大量在线文档向您展示如何使用 launchd 进行设置并创建 .plist。

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

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

回答by CodeShadow

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

回答by am2505

If you want to install an earlier MongoDB version on mac. Go to the link https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-os-x/and select the version which you want to install and its very easy to install, just give a try. There will be around 2-3 commands for installation.

如果要在 mac 上安装较早的 MongoDB 版本。转到链接https://docs.mongodb.com/v3.6/tutorial/install-mongodb-on-os-x/并选择您要安装的版本,它很容易安装,试一试. 将有大约 2-3 个用于安装的命令。

For example if you want to install version 3.6

例如,如果您要安装3.6 版

brew tap mongodb/brew
brew install [email protected]

If you got some error

如果你有一些错误

If you need to have [email protected] first in your PATH run:
  echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

Then run

然后运行

export PATH="/usr/local/opt/[email protected]/bin:$PATH"

To confirm if it successfully installed:

确认是否安装成功:

mongod -version