'Creating mongoDB alias with .bash_profile on the cmder is not working
this is my first ever question. Okay..
Relevant to this problem :
- I am using cmder
- I am new to the terminal
- I am using a windows PC
I'm following a tutorial on how to install mongoDB locally, after running the setup my first problem came when On the terminal The tutor did
Cd ~
To go to the home directory but when I tried the same command on the cmder I received
The system cannot find the path specified
So I navigated manually using "cd.. " to
c:\Users\<username>
Which I think is the home directory,I created the ".bash_profile" file and saved the following commands in it
alias mongod = "/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo = "/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
But when I run the mongod or test if it's installed completely it returns
'mongod' is not recognized as an internal or external command, operable program or batch file
Please I don't know my way round the terminal that much, please be detailed with answers Thanks in advance
Solution 1:[1]
alias mongod="/c/Program\ Files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/Program\ Files/MongoDB/server/4.4/bin/mongo.exe"
Removing spaces and making uppercase the first letters of program files worked for me.
Solution 2:[2]
cmder doesn't interpret shell arguments like ~
, which means tilde won't work in paths. Also, be aware the way you spelled Cd
. It can cause an error in other command line tools (case sensitive ones like Git Bash).
1 - If you're using cmder/cmd.
Use doskey to create an alias/shortcut:
- Create
C:\bat\macros.txt
to store your macros/aliases and paste:
cdhome=cd /d %HOMEDRIVE%%HOMEPATH%
mongo="C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe" $*
mongod="C:\Program Files\MongoDB\Server\4.4\bin\mongod.exe" $*
Rename everything you want but %HOMEDRIVE%%HOMEPATH%
. $*
at the end means the command accepts arguments, like mongo --version
.
Keep in mind that .bash_profile
isn't related with cmder/cmd, that's why your mongo commands are there too.
Then
Windows + R
and type regedit.Go to
HKEY_LOCAL_MACHINE\Software\Microsoft\Command Processor\
Right-click and add a new "String Value". Name it Autorun.
Right-click it and modify the value data to
DOSKEY /MACROFILE="C:\bat\macros.txt"
2 - If you're using Git Bash, Hyper terminal, etc.
On .bash_profile
, just remove the spaces around the equals sign. Like:
alias mongod="/c/program\ files/MongoDB/server/4.4/bin/mongod.exe"
alias mongo="/c/program\ files/MongoDB/server/4.4/bin/mongo.exe"
Solution 3:[3]
or on Windows, you can just go to System properties/Advanced/Environment Variables. Under System variables, find the Variable called Path. Click edit, then New and paste in the path of the mongoDB bin folder: C:\Program Files\MongoDB\Server\4.4\bin keep in mind to write version your mongodb correctly in path, now its 4.4
By adding a path to the path variable you can access the .exe files from that path no matter where you are in the directory. It serves the same purpose as the .bash_profile file. Doing it this way allows this to work with windows cmd prompt or cmder as well. Upon launching, the bash emulator gets the environment variables from Windows anyways.
After adding the mongoDB path, open cmd prompt or any bash emulator and type in mongo. It will load up mongo.exe regardless of your current working directory.
Solution 4:[4]
Be Specific about the spaces after alias.
alias alias_name ="path.."
Solution 5:[5]
I faced alot of issues despite so many answers so this worked for me.
1.First install git and hyper terminal
2.Click the '~' sign to enter the home directory and then make a new file ".bash_profile"
- Enter the command "vim .bash_profile"
- Now enter 'i' key to enter the insert mode
- Copy paste the exact command below:
alias mongod="C:/Program\ Files/MongoDB/Server/5.0/bin/mongod.exe"
alias mongo="C:/Program\ Files/MongoDB/Server/5.0/bin/mongo.exe"
(make sure that you use forward slash '/' for path and "\" backward slash to indicate space between program and files)
- enter esc
- write the command ':wq!' and click enter
- restart hyper terminal and check the installation by running the command 'mongo --version'
Solution 6:[6]
Use git bash instead of CMDER
OR
Try to install mongosh from this link: [1]: https://www.mongodb.com/try/download/shell?jmp=docs
And after setup go to hyper terminal and write mongosh => to connect to MongoDB on port 27017 and then you will see => test>
now you are ready to use the Database and you can write help to see Shell Help.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | smeric |
Solution 2 | |
Solution 3 | Nika Maisuradze |
Solution 4 | Shubham Auddy |
Solution 5 | |
Solution 6 |