我如何确保Mongo二进制文件在我的路径中——在我的shell的rc (~/.bashrc)中,在Mac上?

时间:2020-12-04 00:21:47

I am learning mongoDb.
I did the following: I understand this.

我正在学习mongoDb。我做了以下的事:我理解这一点。

mkdir -p mongodb
cp -R -n mongodb-osx-x86_64-2.6.7/ mongodb

These next ** instructions are not crystal clear to me.

我不太清楚下面的说明。

** Ensure the location of the binaries is in the PATH variable. The MongoDB binaries are in the bin/ directory of the archive. To ensure that the binaries are in your PATH, you can modify your PATH.

** *确保二进制文件的位置在PATH变量中。MongoDB二进制文件位于存档的bin/目录中。为了确保二进制文件在您的路径中,您可以修改您的路径。

For example, you can add the following line to your shell’s rc file (e.g. ~/.bashrc):

例如,您可以向shell的rc文件(例如~/.bashrc)添加以下一行:

export PATH=<mongodb-install-directory>/bin:$PATH

Replace with the path to the extracted MongoDB archive.

用提取的MongoDB存档的路径替换。

End of the instructions.

结束指令。

From terminal on my Mac

从我Mac上的终端

$which bash
/bin/bash

The bin directory has a bunch of commands: bash, chmod, ln, pid, mkdir.

bin目录有一系列命令:bash、chmod、ln、pid、mkdir。

I cannot find the directory where I should include the PATH code above.

我找不到应该包含上面路径代码的目录。

Thanks

谢谢

Abhay's instructions worked ! Sorry that the following is long but I believe it is necessary because you were so clear last time and I want you to see my file structure.
If email is easier let me know but this will more likely than not help others :) I really want to understand my file structure so if you do not mind a bit of further clarification. Thanks again for your expertise.

Abhay指导工作!很抱歉,下面的内容很长,但是我认为这是必要的,因为您上次讲得很清楚,我想让您看看我的文件结构。如果电子邮件更容易让我知道,但这更可能帮助别人:)我真的想了解我的文件结构,如果你不介意进一步澄清。再次感谢您的专业知识。

1. But why are all of the binaries (the executables) listed individually in this bin folder ? Are they the 'only' files that should 'live' in this folder ? Perhaps when I was installing bower grunt etc. I should installed those (bower grunt etc) into a different location. I am trying to keep my file structures logical and clean. Here is what I have.

1。但是为什么所有的二进制文件(可执行文件)都单独列出在这个bin文件夹中呢?它们是应该在这个文件夹中“存活”的“唯一”文件吗?也许当我在安装一个向下的咕哝时。我应该把那些(向下的咕哝)安装到一个不同的位置。我试图保持我的文件结构的逻辑和干净。这是我的。

MacBookPro:usr regina$ cd ..
MacBookPro:/ regina$ ls
Applications        bin         net
CoreSyncInstall.log cores           private
Library         data            sbin
Network         dev         tmp
System          etc         usr
Users           home            var
Volumes         mach_kernel
MacBookPro:/ regina$ cd usr/local/bin
MacBookPro:bin regina$ ls
bower       grunt       mongod      mongorestore    npm
browserify  gulp        mongodump   mongos      statsd
bsondump    http-server mongoexport mongosniff  yo
cake        karma       mongofiles  mongostat
coffee      lessc       mongoimport mongotop
cordova     mkdirp      mongooplog  node
express     mongo       mongoperf   nodemon
MacBookPro:bin regina$ 

2. Also, I wanted to look at my .bashrc file. I do not have one. I am on osx 10.8.5 I want to 'view' my $PATH variable. I believe I found it somewhere months ago. I was using nano to open a bunch of files because I was curious. Was it listed as an environmental variable ?

2。还有,我想看看我的。bashrc文件。我没有。我在osx 10.8.5上,我想“查看”我的$PATH变量。我想我是几个月前在什么地方找到的。我用nano来打开一堆文件,因为我很好奇。它被列为环境变量吗?

MacBookPro:/ regina$ ls
Applications        bin         net
CoreSyncInstall.log cores           private
Library         data            sbin
Network         dev         tmp
System          etc         usr
Users           home            var
Volumes         mach_kernel
MacBookPro:/ regina$ cd home
MacBookPro:home regina$ ls -la
total 2
dr-xr-xr-x   2 root  wheel     1 Feb  3 08:29 .
drwxr-xr-x  33 root  wheel  1190 Jan 25 17:21 ..
MacBookPro:home regina$ 
  1. I start the mongo shell like this. I am not showing all of the lines output in terminal.
    Look at my file structure. I originally followed a cp command but it did not explain 'where' to copy the archived (desktop) mongodb-osx-x84.... folder so look where I copied it to. Now I have these files in 2 locations - yes ? And I have a mongodb folder inside of a higher level mongodb folder. Why ? How did I manage this ? It seems illogical. I have been indented 4 spaces but the below will not format so I just added line breaks. sorry.

    我这样开始蒙高壳。我没有在终端中显示所有的输出。看看我的文件结构。我原来是cp命令但没有解释“地方”复制存档(桌面)mongodb-osx-x84 ....文件夹,看看我把它复制到哪里了。现在我在两个地方有这些文件,请讲?我在一个更高级别的mongodb文件夹中有一个mongodb文件夹。为什么?我是怎么做到的?似乎不合逻辑。我已经被缩进了4个空格,但是下面的不会格式化,所以我只添加了换行符。对不起。

    MacBookPro:home regina$ cd ..

    MacBookPro:家里雷吉娜$ cd . .

    MacBookPro:/ regina$ ls Applications bin net CoreSyncInstall.log cores private Library data sbin Network dev tmp System etc usr Users home var Volumes mach_kernel

    MacBookPro:/ regina$ ls应用程序包含net CoreSyncInstall。日志核心私有库数据sbin网络开发tmp系统等用户家庭var卷mach_kernel

    MacBookPro:/ regina$ cd data

    MacBookPro:/ regina $ cd数据

    MacBookPro:data regina$ ls

    regina $ ls MacBookPro:数据

    db mongodb

    db mongodb

    MacBookPro:data regina$ cd mongodb

    MacBookPro:数据regina $ cd mongodb

    MacBookPro:mongodb regina$ ls

    MacBookPro:mongodb雷吉娜$ ls

    mongodb MacBookPro:mongodb regina$ cd mongodb MacBookPro:mongodb regina$ ls GNU-AGPL-3.0 THIRD-PARTY-NOTICES README bin

    mongodb MacBookPro:mongodb regina$ cd mongodb MacBookPro:mongodb regina$ ls GNU-AGPL-3.0第三方通知README bin

    MacBookPro:mongodb regina$ cd bin

    MacBookPro:mongodb雷吉娜$ cd箱

    MacBookPro:bin regina$ ls

    MacBookPro:本regina $ ls

    bsondump mongodump mongoimport mongorestore mongostat mongo mongoexport mongooplog mongos mongotop mongod mongofiles mongoperf mongosniff

    蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古大蒙古

  2. This is what happens when I try and type 'mongo' as another forum suggested.

    这就是当我尝试输入“mongo”时发生的事情。

    MacBookPro:bin regina$ mongo MongoDB shell version: 2.6.7 connecting to: test 2015-02-03T08:36:54.157-0500 warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

    MacBookPro:bin regina$ mongo MongoDB shell版本:2.6.7连接到:test 2015-02-03t08:36: 54.57 -0500警告:未能连接到127.0.1:27017,原因:errno:61连接被拒绝

So I typed this which still failed.

我输入了这个,但还是失败了。

MacBookPro:bin regina$ ./mongo
MongoDB shell version: 2.6.7
connecting to: test
2015-02-03T08:37:03.599-0500 warning: Failed to connect to    127.0.0.1:27017, reason: errno:61 Connection refused

Then I tried this which connected - opened port 27017 - and is listening. Why did I need the daemon command ?

然后我尝试了这个连接-打开端口27017 -并且正在听。为什么我需要守护程序命令?

MacBookPro:bin regina$ ./mongod
./mongod --help for help and startup options
2015-02-03T08:37:08.712-0500 [initandlisten] MongoDB starting :    pid=487 port=27017 dbpath=/data/db 64-bit host=macbookpro.home
more lines of code
2015-02-03T08:37:09.018-0500 [initandlisten] waiting for connections on port 27017

1 个解决方案

#1


29  

When you download MongoDB for Mac, you get an archive file. First thing you need to is uncompress the archive. To do that you just double click on the archive. The uncompressed folder will have the binaries in the bin folder, like mongodb-osx-x86_64-2.6.7/bin. What you need to do next is to make sure these binaries are accessible. So, for this you can do either of the two things -

当你下载MongoDB的Mac时,你会得到一个存档文件。首先需要解压归档文件。为此,只需双击归档文件。未压缩的文件夹将在bin文件夹中包含二进制文件,如mongodb-osx- 86_64-2.6.7/bin。接下来需要做的是确保这些二进制文件是可访问的。对于这个,你可以做这两件事中的任何一件

  1. Copy the binaries to /usr/local/bin folder. As /usr/local/bin is always in PATH, so you don't have to add it to the PATH.

    将二进制文件复制到/usr/local/bin文件夹。因为/usr/local/bin总是在路径中,所以您不必将其添加到路径中。

    This is pretty simple. Run cp mongodb-osx-x86_64-2.6.7/bin/* /usr/local/bin/. That's it. You are all done.

    这是非常简单的。cp mongodb-osx-x86_64-2.6.7 / bin / * /usr/local/bin/.运行就是这样。你们都完成了。

  2. Add the binary folder's path to your $PATH variable.

    将二进制文件夹的路径添加到$ path变量。

    Open the .bashrc file, which is located in your home folder, and put export PATH=$HOME/mongodb/bin:$PATH line in the end. I am assuming that mongodb uncompressed in downloads.

    打开位于home文件夹中的.bashrc文件,并将导出路径=$ home /mongodb/bin:$PATH放在末尾。我假设mongodb在下载中没有被压缩。

If going by the second method, make sure you don't accidently delete the mongodb folder that is added in the PATH.

如果使用第二个方法,请确保不会意外地删除路径中添加的mongodb文件夹。

Once you have finished doing this, close the terminal, open a new terminal window and run:

完成此操作后,关闭终端,打开新的终端窗口并运行:

mongo --version

If you get the mongodb info with version, then good.

如果你得到mongodb的版本信息,那很好。

If you still get something like command mongo not found, then make sure you followed above instructions right. Also make sure you are not using any other shell, like zsh. If you are, then you have to add the export statement in the respective shell file. For zsh the file name is .zshrc.

如果您仍然没有找到像mongo这样的命令,那么请确保您遵循了上面的指示。还要确保没有使用任何其他shell,比如zsh。如果是,则必须在相应的shell文件中添加export语句。对于zsh,文件名是.zshrc。


Okay! So as you have updated the initial question with some more questions. So here goes the explanation point by point:

好吧!当你用更多的问题更新了最初的问题。这里是一个点一个点的解释

  1. The files you see in /usr/local/bin folder are binaries. In simple language, they are executable programs. These executable binaries live there though you can run them from anywhere in the command line.

    在/usr/local/bin文件夹中看到的文件是二进制文件。在简单的语言中,它们是可执行程序。尽管您可以在命令行中的任何地方运行这些可执行二进制文件。

  2. The .bashrc file is found in user's home directory. On Mac it's /Users/username. In your case, it should be /Users/regina because your name is Regina.

    .bashrc文件在用户的主目录中找到。在Mac /用户/用户名。在您的情况下,应该是/用户/regina,因为您的名字是regina。

  3. mongo is the client application. It is used to interact with the mongodb database. And, mongod is the database deamon that stores the data. So first you have to run mongod, and then only you can connect to it using the client mongo and start querying.

    mongo是客户端应用程序。它用于与mongodb数据库交互。mongod是存储数据的数据库deamon。因此,首先必须运行mongod,然后只有您可以使用客户端mongo连接到它并开始查询。

#1


29  

When you download MongoDB for Mac, you get an archive file. First thing you need to is uncompress the archive. To do that you just double click on the archive. The uncompressed folder will have the binaries in the bin folder, like mongodb-osx-x86_64-2.6.7/bin. What you need to do next is to make sure these binaries are accessible. So, for this you can do either of the two things -

当你下载MongoDB的Mac时,你会得到一个存档文件。首先需要解压归档文件。为此,只需双击归档文件。未压缩的文件夹将在bin文件夹中包含二进制文件,如mongodb-osx- 86_64-2.6.7/bin。接下来需要做的是确保这些二进制文件是可访问的。对于这个,你可以做这两件事中的任何一件

  1. Copy the binaries to /usr/local/bin folder. As /usr/local/bin is always in PATH, so you don't have to add it to the PATH.

    将二进制文件复制到/usr/local/bin文件夹。因为/usr/local/bin总是在路径中,所以您不必将其添加到路径中。

    This is pretty simple. Run cp mongodb-osx-x86_64-2.6.7/bin/* /usr/local/bin/. That's it. You are all done.

    这是非常简单的。cp mongodb-osx-x86_64-2.6.7 / bin / * /usr/local/bin/.运行就是这样。你们都完成了。

  2. Add the binary folder's path to your $PATH variable.

    将二进制文件夹的路径添加到$ path变量。

    Open the .bashrc file, which is located in your home folder, and put export PATH=$HOME/mongodb/bin:$PATH line in the end. I am assuming that mongodb uncompressed in downloads.

    打开位于home文件夹中的.bashrc文件,并将导出路径=$ home /mongodb/bin:$PATH放在末尾。我假设mongodb在下载中没有被压缩。

If going by the second method, make sure you don't accidently delete the mongodb folder that is added in the PATH.

如果使用第二个方法,请确保不会意外地删除路径中添加的mongodb文件夹。

Once you have finished doing this, close the terminal, open a new terminal window and run:

完成此操作后,关闭终端,打开新的终端窗口并运行:

mongo --version

If you get the mongodb info with version, then good.

如果你得到mongodb的版本信息,那很好。

If you still get something like command mongo not found, then make sure you followed above instructions right. Also make sure you are not using any other shell, like zsh. If you are, then you have to add the export statement in the respective shell file. For zsh the file name is .zshrc.

如果您仍然没有找到像mongo这样的命令,那么请确保您遵循了上面的指示。还要确保没有使用任何其他shell,比如zsh。如果是,则必须在相应的shell文件中添加export语句。对于zsh,文件名是.zshrc。


Okay! So as you have updated the initial question with some more questions. So here goes the explanation point by point:

好吧!当你用更多的问题更新了最初的问题。这里是一个点一个点的解释

  1. The files you see in /usr/local/bin folder are binaries. In simple language, they are executable programs. These executable binaries live there though you can run them from anywhere in the command line.

    在/usr/local/bin文件夹中看到的文件是二进制文件。在简单的语言中,它们是可执行程序。尽管您可以在命令行中的任何地方运行这些可执行二进制文件。

  2. The .bashrc file is found in user's home directory. On Mac it's /Users/username. In your case, it should be /Users/regina because your name is Regina.

    .bashrc文件在用户的主目录中找到。在Mac /用户/用户名。在您的情况下,应该是/用户/regina,因为您的名字是regina。

  3. mongo is the client application. It is used to interact with the mongodb database. And, mongod is the database deamon that stores the data. So first you have to run mongod, and then only you can connect to it using the client mongo and start querying.

    mongo是客户端应用程序。它用于与mongodb数据库交互。mongod是存储数据的数据库deamon。因此,首先必须运行mongod,然后只有您可以使用客户端mongo连接到它并开始查询。