MongoDB entries sinde my .bash_profile are not recognized (Mac OS) - mongodb

I installed MongoDB on my Macbook (Catalina 10.15.3) and placed all the necessary entries in my .bash_profile. However, these entries are not recognized, so I have to manually enter the following again and again in order to start MongoDB (for each new terminal):
export MONGO_PATH=/Users/codehan/Desktop/MongoDB/mongodb-macos-x86_64-4.2.3
export PATH=$MONGO_PATH/bin:$PATH
Otherwise I always get the following in the terminal:
zsh: command not found: mongo
But as soon as I enter export MONGO_PATH=/Users/codehan/Desktop/MongoDB/mongodb-macos-x86_64-4.2.3 and export PATH=$MONGO_PATH/bin:$PATH in my terminal it works again.
How can I fix this problem?

With zsh, the configuration file is $HOME/.zshrc

Related

Bun Not Found After Running Installation Script

I have ran the installation script by pasting this code:
$ curl https://bun.sh/install | bash
However, when I try to get the version of bun, it says it could not find it:
$ bun --version
Command 'bun' not found, did you mean:
command 'ben' from deb ben (0.9.0ubuntu2)
command 'bus' from deb atm-tools (1:2.5.1-4)
command 'zun' from deb python3-zunclient (4.0.0-0ubuntu1)
Try: sudo apt install <deb name>
I had the same issue running on Windows 10 WSL2 Ubuntu-22.04 with Bun v0.1.5.
The solution (and more detail just in case anyone needs it) below:
The executable for bun is in the directory "/home/username/.bun". You need to add this to your $PATH so that this can be found when typing bun commands such as "bun --help".
The bun setup process does not add this path so you need to do it yourself.
Two ways to do this :
(1) Manual method
Type in the terminal:
export BUN_INSTALL="/home/YOUR_USERNAME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
Replacing YOUR_USERNAME with your real username (the current username can be found by typing 'whoami' in the terminal).
Note: This process will have to be REPEATED for every new shell you open.
(2) Automatic method
Edit the .bashrc file :
nano ~/.bashrc
at the end of this file add
BUN_INSTALL="/home/YOUR_USERNAME/.bun"
PATH="$BUN_INSTALL/bin:$PATH"
Replacing YOUR_USERNAME with your real username (the current username can be found by typing 'whoami' in the terminal).
(Remember to save your changes with Ctrl-O)
Note: You will NEED TO OPEN A NEW SHELL for this to work OR type 'source ~/.bashrc' to use in the current terminal.
You should now be able to run bun commands in any new shell.
The installation script says a message at the end telling you how to add bun to your PATH manually. Here is that output:
Manually add the directory to your $HOME/.bashrc (or similar)
BUN_INSTALL="/home/sno2/.bun"
PATH="$BUN_INSTALL/bin:$PATH"
I advise you re-run the installation command and copy the environment variables and add them to your PATH.
export BUN_INSTALL="/Users/manendra/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
add these to your .bashrc, .zshrc or you can use export command to use for current session.
Note: Change your username place of (manendra) "/Users/manendra/.bun"
Manually add the directory to ~/.bashrc (or similar):
export BUN_INSTALL="$HOME/.bun"
export PATH="$BUN_INSTALL/bin:$PATH"
From the installer, last message is:
To get started, run
exec /bin/zsh
bun --help

When can I use the command 'mongod' in Command Line?

I recently installed the version 4.4 of MongoDB,I followed all the instructions as in the documentation of mongodb.
As instructed by my tutor I created another folder named 'mongodb'in my pc,inside which I created another folder named 'data' as well.Now i went to the command prompt and entered into the same mongodb folder i created earlier and typed the following command.
C:\Users\Dell\mongodb>mongod --dbpath=data --bind_ip 127.0.0.1
When I press Enter I see an error :
'mongod' is not recognized as an internal or external command,operable program or batch file.
I am totally stuck in this.I even reinstalled mongodb again,but it is not working.
You might have a problem with path in Mongodb. After the installation process ends open a
Command Interpreter with Administrative privileges and run:
"C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe"
Now afterward you can use the 'mongod' Command. If still you are unable go to the pre insatlled Mongodb folder copy the path upto bin .
Now go to :
controlpanel>system and security>system>Advanced system settings.
A dialogue box appears and then at the bottom there is the option for Environment Variables.Click on that.
If Mongodb variable already exit delete that and click on the path option. You might see a new option somewhere around click on that and input box appears.Now paste the copied path in that box and click save/Ok or sth to end the options.
Now you can use the 'mongod' command .

mongod and mongo commands not working on windows 10

I've installed mongoDB on my windows 10 OS. Then I tried setting its database path to some directory by moving to it and typing mongod --datapath=data in cmd, where data is the folder which is to contain the db(I've used the relative path because I'm in that directory). But message comes that mongod is unrecognized command. After some searching I found that by specifying mongod path, i.e. "C:\Program Files\MongoDB\Server\3.4\bin\mongod.exe" --datapath=data works. Similar thing happens for mongo.
I want to directly run mongod and mongo commands, I have seen people directly using it(without going to the directory or specifying the path).
For a Windows installation, by default you have to use the full path to the exe unless you add it to the PATH.
To add it to the PATH:
01) Get path to bin, something like: C:\Program Files\MongoDB\Server\4.0\bin
02) Press the Windows key, type env, select Edit the system environment variables
03) On the Advanced tab, click Environment Variables
04) In the User variables for xxxx section, select path and then click the Edit... button
05) Click New and paste your path with a trailing slash, eg:
C:\Program Files\MongoDB\Server\4.0\bin\
06) Click OK, OK, OK and restart your command window.
Source
The examples you have seen are probably based on UNIX installations which I think by default install mongo as a service (which Windows doesn't) and that is what is called in those examples.
To simplify startup and configuration on Windows, you can also install it as a service. See the Mongo documentation here and the
"Configure Windows Service for MongoDB' section".
This will then allow you to start and stop Mongo by simply calling
net start MongoDB
Or
net stop MongoDB
If installed MongoDB version is 6.0 or above, mongo command will not work on Powershell/cmd. If you run the command you will get the following error:
'mongo' is not recognized as an internal or external command,
operable program or batch file.
To run mongo commands, you have to install MongoDB Shell from
After installing the shell, extract the zip file, you can rename the extracted folder (mongosh-1.6.0-win32-x64) as "MongoDB Shell" and move that folder to Windows(:C) > Program Files
Now open the folder, go to bin and copy the path:
C:\Program Files\MongoDB Shell\mongosh-1.6.0-win32-x64\bin (or
C:\Program Files\mongosh-1.6.0-win32-x64\mongosh-1.6.0-win32-x64\bin)
Go to
Settings > System > About > Advanced system settings > Environment
Variables > Under System Variables, click on 'Path' then 'Edit' >
Click 'New' and paste the above copied path > Click 'Ok' 'Ok' 'Ok'
Now open Powershell/cmd, run the command 'mongosh'
You're all set to work with MongoDB
To add it to the PATH:
Add Mongo’s bin folder to the Path Environment Variable
Kindly check the link:
here
After adding bin folder to the path Environment Variable
then simply type mongo in terminal it will start working
reference : Microsoft document
set your path like this
;C:\Program Files\MongoDB\Server\4.0\bin
this is worked for me.
Based on welshGaz answer above, I edited the User Path variable but it did not work for me yet. I wasn't able to access the System Path variables.
What I noticed from the errors on the command prompt is that it what missing the "C:\data\db" directory to store its files (I don't know what those files are for just yet). So I created that directory myself and it worked.
Same problem here. I installed through the .msi file provided for windows X64bit. In the installer instructions from MongoDB (https://docs.mongodb.com/manual/tutorial/install-mongodb-on-windows/), I read that you can add C:\Program Files\MongoDB\Server\4.2\bin to the System Path. Then it asks to omit the full path to the the MongoDB binaries. That is where I think some information is missing. How are we supposed to omit the full path to the MongoDB binaries?
Currently I can get MongoDB to run mongod using:
"C:\Program Files\MongoDB\Server\4.2\bin\mongod.exe" --dbpath="c:\data\db"
For --dbpath="c:\data\db" you can replace "c:\data\db" with the path to your database.
I can also run mongo using:
"C:\Program Files\MongoDB\Server\4.2\bin\mongo.exe"
Another reason to it if you enabled any property in YAML file and it is not formatted properly. YAML looks for specific syntax like colon":"+space" ".
E.g.-
security:
authorization: enabled
use mongosh command from your terminal. mongo command no longer works for 6.0 and above.
if you are trying to connect from connection url eg mongodb://localhost:27017/yourdb try changing it to something like mongodb://127.0.0.1/yourdb

Trouble setting up Sublime Text 3 to work with MongoDB [duplicate]

I'm using Mac Lion. I was using mongodb version 1.4. I wanted to upgrade to 1.8.5 and I followed http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x step wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5. Everything goes smooth. I tried:
mongod
it's ok. I can access localhost:28017
but,
mongo
shows command not found
How can I fix this?
You need to add the path to "mongo" to your terminal shell.
export PATH=$PATH:/usr/local/mongodb/bin
Did you do the last step with paths.d? If so, try restarting your terminals.
Do you have a good reason for using 1.8.5? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x
Starting from Mongodb version 6.0 mongo was replaced by mongosh
For readers in 2021:
export PATH="$PATH:/usr/local/opt/mongodb-community#3.6/bin"
You'll have to add the location of the Mongo binary to PATH.
Follow the steps below in order to make the PATH variable permanent:
Open Terminal and navigate to your user directory.
Run touch ~/.bash_profile and then open ~/.bash_profile.
In TextEdit, add export PATH="<mongo-directory>/bin:$PATH" (Keep the quote marks - related to white spaces).
Save the .bash_profile file and Quit (Command + Q) Text Edit.
Run source ~/.bash_profile.
Run echo $PATH and check if the you see that the Mongo binary was added.
(*) Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session.
In order to make it available outside the current terminal - you'll have to logout and login.
1.Go to your [mongodb installation dir]:
cd <mongodb installation dir>
2.Type ./bin/mongo to start mongo:
./bin/mongo
Read More
Note :
If above command gives error
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_ environment variables are set correctly.*
Run bellow command: Read More
export LC_ALL=C
How can find installation directory
find / -name "mongodb"
You can also set path
export PATH=$PATH:<mongodb installation dir>/bin
documentation
export PATH={mongodb-install-directory}/bin:$PATH
In Mac:
Go into Bash Profile:
vi ~/.bash_profile
Add Path of Installation of MongoDB:
export PATH=$PATH:/usr/local/opt/mongodb-community#4.2/bin
Reload the Bash Profile:
source ~/.bash_profile
You can navigate to the mongo directory using the command line and then start MongoDB with
./mongodb
I was facing the same problem this worked for me.
you need to install mongodb shell to ge the mongo command working.
Download link
I didn't have the right mongo command line tools installed. This from Brew worked for me though.
brew install mongodb-community
just a little recommandation, if your path has a space just wrap the whole path with quote or doublequote
example : C:\Program Files\MongoDB\Server\4.2 . notice the space in "Program Files"
export PATH=$PATH:"C:/Program Files/MongoDB/Server/X.X/bin"
in place of mongo command use mongosh command and it will work.

Can we run mongoDB shell at any location/directory in unix [duplicate]

I'm using Mac Lion. I was using mongodb version 1.4. I wanted to upgrade to 1.8.5 and I followed http://shiftcommathree.com/articles/how-to-install-mongodb-on-os-x step wise replacing each mongodb-osx-x86_64-1.4.0 by mongodb-osx-x86_64-1.8.5. Everything goes smooth. I tried:
mongod
it's ok. I can access localhost:28017
but,
mongo
shows command not found
How can I fix this?
You need to add the path to "mongo" to your terminal shell.
export PATH=$PATH:/usr/local/mongodb/bin
Did you do the last step with paths.d? If so, try restarting your terminals.
Do you have a good reason for using 1.8.5? The current stable is 2.0.4, and it has many useful upgrades from 1.8.x
Starting from Mongodb version 6.0 mongo was replaced by mongosh
For readers in 2021:
export PATH="$PATH:/usr/local/opt/mongodb-community#3.6/bin"
You'll have to add the location of the Mongo binary to PATH.
Follow the steps below in order to make the PATH variable permanent:
Open Terminal and navigate to your user directory.
Run touch ~/.bash_profile and then open ~/.bash_profile.
In TextEdit, add export PATH="<mongo-directory>/bin:$PATH" (Keep the quote marks - related to white spaces).
Save the .bash_profile file and Quit (Command + Q) Text Edit.
Run source ~/.bash_profile.
Run echo $PATH and check if the you see that the Mongo binary was added.
(*) Notice that the PATH variable is now available only for the current terminal and not to processes that were already started in the session.
In order to make it available outside the current terminal - you'll have to logout and login.
1.Go to your [mongodb installation dir]:
cd <mongodb installation dir>
2.Type ./bin/mongo to start mongo:
./bin/mongo
Read More
Note :
If above command gives error
Failed global initialization: BadValue Invalid or no user locale set. Please ensure LANG and/or LC_ environment variables are set correctly.*
Run bellow command: Read More
export LC_ALL=C
How can find installation directory
find / -name "mongodb"
You can also set path
export PATH=$PATH:<mongodb installation dir>/bin
documentation
export PATH={mongodb-install-directory}/bin:$PATH
In Mac:
Go into Bash Profile:
vi ~/.bash_profile
Add Path of Installation of MongoDB:
export PATH=$PATH:/usr/local/opt/mongodb-community#4.2/bin
Reload the Bash Profile:
source ~/.bash_profile
You can navigate to the mongo directory using the command line and then start MongoDB with
./mongodb
I was facing the same problem this worked for me.
you need to install mongodb shell to ge the mongo command working.
Download link
I didn't have the right mongo command line tools installed. This from Brew worked for me though.
brew install mongodb-community
just a little recommandation, if your path has a space just wrap the whole path with quote or doublequote
example : C:\Program Files\MongoDB\Server\4.2 . notice the space in "Program Files"
export PATH=$PATH:"C:/Program Files/MongoDB/Server/X.X/bin"
in place of mongo command use mongosh command and it will work.