Hi I'm a bit of a shell n00b.
Can anyone tell me how I would check the version of MongoDB that is installed on my Linux Ubuntu machine?
I see that my MongoDB shell version: 1.2.2 so Im pretty sure that MongoDB itself is out dated too. And does anyone know of any 'How to update MongoDB' docs? I find mongodb.org to be a bit confusing.
Please and thank you.
Ok if I use db.version() inside of mongo shell it says 1.2.2
If I $ mongod --version I get this:
db version v1.2.2, pdfile version 4.5
Wed Oct 16 10:28:22 git version: nogitversion
I ran
sudo apt-get update
sudo apt-get install mongodb
and get
sudo apt-get install mongodb
Reading package lists... Done
Building dependency tree
Reading state information... Done
mongodb is already the newest version.
0 upgraded, 0 newly installed, 0 to remove and 179 not upgraded.
mongod --version
db version v1.2.2, pdfile version 4.5
Wed Oct 16 10:31:07 git version: nogitversion
So why isn't it updating? Is apt-get pointing at the wrong repo / source?
inside shell:
$ mongod --version
To be complete, a short introduction for "shell noobs":
First of all, start your shell - you can find it inside the common desktop environments under the name "Terminal" or "Shell" somewhere in the desktops application menu.
You can also try using the key combo CTRL+F2, followed by one of those commands (depending on the desktop envrionment you're using) and the ENTER key:
xfce4-terminal
gnome-console
terminal
rxvt
konsole
If all of the above fail, try using xterm - it'll work in most cases.
Hint for the following commands: Execute the commands without the $ - it's just a marker identifying that you're on the shell.
After that just fire up mongod with the --version flag:
$ mongod --version
It shows you then something like
$ mongod --version
db version v2.4.6
Wed Oct 16 16:17:00.241 git version: nogitversion
To update it just execute
$ sudo apt-get update
and then
$ sudo apt-get install mongodb
ANSWER: Read the instructions #dua
Ok the magic was in this line that I apparently missed when installing was:
$ sudo apt-get install mongodb-10gen=2.4.6
And the full process as described here http://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/ is
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
$ echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
$ sudo apt-get update
$ sudo apt-get install mongodb-10gen
$ sudo apt-get install mongodb-10gen=2.2.3
$ echo "mongodb-10gen hold" | sudo dpkg --set-selections
$ sudo service mongodb start
$ mongod --version
db version v2.4.6
Wed Oct 16 12:21:39.938 git version: b9925db5eac369d77a3a5f5d98a145eaaacd9673
IMPORTANT: Make sure you change 2.4.6 to the latest version (or whatever you want to install). Find the latest version number here http://www.mongodb.org/downloads
When you entered in mongo shell using "mongo" command , that time only you will notice
MongoDB shell version v3.4.0-rc2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 3.4.0-rc2
also you can try command,in mongo shell ,
db.version()
In the terminal just enter the traditional command:
mongod --version
In the terminal just write :
$ mongod --version
Related
I'm attempting to setup MongoDB on Ubuntu 20.04.02 LTS by following the documentation. I have ensured this is a fresh install. However an error persists when I verify if the MongoDB install started succesfully by typing in:
sudo systemctl status mongod
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor prese>
Active: failed (Result: core-dump) since Wed 2021-08-11 12:59:20 UTC; 49s >
Docs: https://docs.mongodb.org/manual
Process: 3190 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=dum> Main PID: 3190 (code=dumped, signal=ILL)
Aug 11 12:59:19 discorddomagoj systemd1: Started MongoDB Database
Server. Aug 11 12:59:20 discorddomagoj systemd1: mongod.service:
Main process exited,> Aug 11 12:59:20 discorddomagoj systemd1:
mongod.service: Failed with result '>
Picture of problem for clarity:
1.Stop the mongod process by issuing the following command:-
sudo service mongod stop
2.Remove any MongoDB packages that you had previously installed:-
sudo apt-get purge mongodb-org*
3.Remove MongoDB databases and log files:-
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
4.Then reinstall mangodb 4.4.8
5.Import the public key used by the package management system:-
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
6.The following instruction is for Ubuntu 20.04 (Focal):-
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
7.Update Apt
sudo apt-get update
8.Install mongodb
sudo apt-get install mongodb-org=4.4.8 mongodb-org-server=4.4.8 mongodb-org-shell=4.4.8 mongodb-org-mongos=4.4.8 mongodb-org-tools=4.4.8
9.Use mongod --version to check its succesfully installed
10.If u encounter any error while using mongod
sudo mkdir /data
cd /data
sudo mkdir db
sudo pkill -f mongod
11.Then use sudo mongod command.
This error show CPU incompatibly with mongodb. if use proxmox set cpu mode to "HOST".
stop the db
sudo service mongod stop
uninstall it:
sudo apt-get purge mongodb-org*
Import the public key used by the package management system
wget -qO - https://www.mongodb.org/static/pgp/server-5.0.asc | sudo apt-key add -
Create a list file for MongoDB.
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/5.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-5.0.list
Reload local package database
sudo apt-get update
Install a specific release of the MongoDB packages(this was the reason I had that similar error for not specifying the package)
sudo apt-get install -y mongodb-org=5.0.7 mongodb-org-database=5.0.7 mongodb-org-server=5.0.7 mongodb-org-shell=5.0.7 mongodb-org-mongos=5.0.7 mongodb-org-tools=5.0.7
lastly, on one tab of the terminal run:
sudo mongod
on another open the db:
mongo
I have same issue when installing mongodb on virtual machine with proxmox.
Changing processor from kvm to host or sandybridge(my actual pc) solved this problem. Reference link
This is an addition to #AbdulWahhab 's answer. I have recently seen many questions of same type: 'can't start mongodb#5.0.x server on ubuntu#20.0.4'. Having faced this issue myself, I found installing mongodb#4.4.8 version only way out. In addition consider that sudo apt-get update updates all packages including mongodb. Newer version of mongodb gets installed and server does not work anymore(as of 10th december 2021). To prevent unintended upgrades, you can pin the package at the currently installed version:
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-database hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
A possible reason for the dump is a change in the microarchitecture requirements of MongoDB introduced with version 5.0. This causes this exact issue on a Raspberry Pi for instance (see: MongoDB Forum).
This issue might be mitigated by building from source as described in the forum post. I haven't tried this though personally. Installing versions prior to 5.0 (as described by Abdul Wahhab) will solve the problem as well.
If you have tried all of the above solutions, and still can't help, please try to reboot the VM.
I am using 18.04 and initially installed 6.0 mongoDB and it just showed the core-dump error after issuing "sudo systemctl status mongod".
After doing some research, I tried to uninstall the 6.0 and then re-install 4.4, it still couldn't help.
Then I tried to re-install 4.2, it still couldn't help.
Finally, I tried to reboot the VM, then it works..
For MongoDB 5.0+
If you are running on VirtualBox with a Windows host, disable Hyper-V. The issue is a lack of AVX support and to get it you need to disable Hyper-V and be using VirtualBox 5.03 or later.
Using CMD as Administrator
bcdedit /set hypervisorlaunchtype off
DISM /Online /Disable-Feature:Microsoft-Hyper-V
Then hard shutdown and restart the host. After that, starting the guest from cold boot should work.
sudo systemctl start mongodb
sudo systemctl status mongodb
Source: https://forums.virtualbox.org/viewtopic.php?f=25&t=99390
I had the same problem on Ubuntu 22.10 and MongoDB 6.0.
I solved it by put it AVX to AUTO in BIOS.
Just for future help in case of someone else need help.
check if you have the java runtime environment (JRE), if not then install it:
sudo apt install default-jre
That' s all =)
I was trying to install MongoDB in WSL running Ubuntu 18.04 after seeing this documentation. But MongoDB says that:
IMPORTANTThe mongodb package provided by Ubuntu is not maintained by MongoDB Inc. and conflicts with the official mongodb-org package. If you have already installed the mongodb package on your Ubuntu system, you must first uninstall the mongodb package before proceeding with these instructions.
MongoDB also says that WSL doesn't support mongodb-org
WINDOWS SUBSYSTEM FOR LINUX (WSL) - UNSUPPORTEDMongoDB does not support the Windows Subsystem for Linux (WSL).
So, I installed mongod using sudo apt install mongodb and when I ran mongo it shows the error:
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-06-21T13:33:40.606+0530 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017
Is there is a way to install the appropriate package and make it running?
I have come across this situation recently.
Even though MongoDB says that it is not supported in WSL, you can actually install it. So, I suggest you follow that steps given in MongoDB docs.
Note : If you have already installed mongodb please remove all those before you install mongodb-org since it may cause some issues during installation :
sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo apt-get --fix-broken install
For installing mongodb community edition, I have added the commands below:
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
sudo apt-get install gnupg
wget -qO - https://www.mongodb.org/static/pgp/server-4.2.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.2.list
sudo apt-get update
sudo apt-get install -y mongodb-org
Now, to get mongoDB running,
sudo nano /etc/init.d/mongod
and paste the contents in this link into the file and save it.
#give permissions
sudo chmod +x /etc/init.d/mongod
#start the service
sudo service mongod start
Now, you can run mongo to reach the database.
Hope it helps.
#bonyem's solution works if you try on Ubuntu 18.04 (and apparently in 19.10) but not in 20.04. WSL version should be 2 (please see this to update WSL).
You also need to "fake" the bash binary by following the steps mentioned in https://github.com/shayne/wsl2-hacks to make systemctl work.
I tried all the methods above but none of the methods worked. I came across Microsoft's official documentation and everything works like a charm.
https://learn.microsoft.com/en-us/windows/wsl/tutorials/wsl-database#install-mongodb
This worked for me.
Run sudo apt install mongodb
Then after that installs run sudo service mongodb start
It will say * Starting database mongodb
And after that I can connect using mongo
Easiest way to bypass this issue is to run MongoDB on Windows. You'll still be able to connect from WSL2 over localhost.
For me, #bonyem's solution resulted in an error:
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
I'm going to install Mongo 4.4. Many instructions were taken from #Lyubosumaz's directions here.
Get rid of all your Mongo PPAs.
~ ❯ sudo ls /etc/apt/sources.list.d
mongodb-org-4.4.list yarn.list
~ ❯ sudo rm -i /etc/apt/sources.list.d/mongodb-org-4.4.list
Remove all Mongo packages and bits and pieces.
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
sudo dpkg --remove --force-remove-reinstreq mongo-tools
sudo dpkg --remove --force-remove-reinstreq mongodb-org
sudo dpkg --remove --force-remove-reinstreq mongodb-org-server
sudo dpkg --remove --force-remove-reinstreq mongodb-server-core
sudo dpkg --remove --force-remove-reinstreq mongodb-org-mongos
sudo dpkg --remove --force-remove-reinstreq mongodb-org-shell
sudo dpkg --remove --force-remove-reinstreq mongodb-org-tools
sudo apt-get --fix-broken install
yes | sudo apt autoremove
Add new PPA and install Mongo 4.4.
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get upgrade
sudo apt-get install -y mongodb-org
You'll get the same error from before. This is caused by mongodb-org package trying to use systemctl to start the DB after install (source). Notice that the same error is thrown when running the command manually.
~ ❯ sudo systemctl start mongod
System has not been booted with systemd as init system (PID 1). Can't operate.
Failed to connect to bus: Host is down
However, running mongod should still work!
If you run into errors when running mongod, you might need to modify some permissions and create a data directory. I found the answer to these issues here, here, and here.
sudo chown $USER /tmp/mongodb-27017.sock
sudo mkdir -p /data/db
sudo chown -R $USER /data/db
I have tried some of the answers above, it did not work for me.
Then I followed a guide 1:
Update ubuntu packages
Install MongoDB on the command line
Set up your local database
Creating the folders and permissions
It worked in my case!
How to uninstall mongodb v3.4.4 completely from my system ubuntu 14.
found Uninstall mongoDB from ubuntu
But not sure if it works on v 3.4.4
First Stop MongoDB Service if Available
sudo service mongod stop
Remove MongoDB Packages
sudo apt-get purge mongodb-org*
Remove Data Directories
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
If your Custom Define Database and log path than u manually remove as above.
Hope this may solve your issue
I'm aware of how one can upgrade the PostgreSQL version on an RDS instance by using the management console's point-and-click. However, doing so leaves me with mismatched client and server psql versions. I want to upgrade the psql client on my ec2 instance. How does one do so?
You can also use amazon-linux-extras command to install new major versions of postgresql, for example:
$ sudo amazon-linux-extras install postgresql13
$ psql --version
psql (PostgreSQL) 13.3
Note that previous versions will remain enabled, but you can explicitly disable them (even though there's no uninstall, try yum to get rid of packages):
$ sudo amazon-linux-extras disable postgresql11
Tested on:
$ hostnamectl | grep -E -w 'Operating|Kernel|Architecture'
Operating System: Amazon Linux 2
Kernel: Linux 4.14.243-185.433.amzn2.aarch64
Architecture: arm64
The exact solution is going to vary depending on your AMI, but here's what worked for me on Amazon Linux:
sudo yum erase postgresql92 -y
sudo yum install https://download.postgresql.org/pub/repos/yum/9.6/redhat/rhel-6-x86_64/pgdg-ami201503-96-9.6-2.noarch.rpm -y
sudo yum install postgresql96 postgresql96-devel -y
sudo ln -sf /usr/pgsql-9.6/bin/pg_config /usr/bin/
You might not need the last step unless you're trying to get the pg gem working in Ruby on Rails.
I'm looking for the easiest and the most recommended way to upgrade mongodb version (standalone server and mongodb shell).
Are there any terminal (for mac) commands that i can follow in order to upgrade?
I tried to stop the server by
$ mongo
use admin
db.shutdownServer()
i get :
Sat Mar 17 20:38:15 DBClientCursor::init call() failed
Sat Mar 17 20:38:15 query failed : admin.$cmd { shutdown: 1.0 } to: 127.0.0.1:27017
server should be down...
Sat Mar 17 20:38:15 trying reconnect to 127.0.0.1:27017
Sat Mar 17 20:38:15 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
I understand that after stopping the server i need to change the bin folder of mongodb. (which i'm failing to do because mongo is in use)
If someone knows an easier way to only upgrade the mongodb version i would really thank him/her!
thank you.
To Upgrade MongoDB on Ubuntu
First, Backup your data using Mongoexport
e.g:
mongoexport --db sales --collection contacts --out contacts.json --journal
Then check which version of MongoDB you are running by issuing the command:
$ mongod --version
db version v1.8.2, pdfile version 4.5 -
Wed Oct 24 15:43:13 git version: nogitversion
Confirm if mongo is currently running:
$ ps -deaf | grep mongod
mongodb 15408 1 0 Jun06 ? 13:50:00 /usr/bin/mongod --config /etc/mongodb.conf
To Shutdown MongoDB
$ ./mongo
> use admin
> db.shutdownServer()
server should be down...
Then upgraded following these instructions: How to Install MongoDB on Ubuntu
Add the 10 Gen (creators of MongoDB) public key to apt-get so you trust their package:
$ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
$ echo "deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen" >> /etc/apt/sources.list.d/10gen.list
Update your packages:
$ sudo apt-get update
install 10gen's MongoDB Debian/Ubuntu package:
$ sudo apt-get install mongodb-10gen
The following packages will be REMOVED:
mongodb
The following NEW packages will be installed:
mongodb-10gen
If you get an error, try:
$ apt-get autoremove
Confirm that the mongodb user/group has permission to write to the data directory:
$ sudo chown -R mongodb:mongodb /var/lib/mongodb/.
Start up MongoDB as a Daemon (background process) using the following command:
$ mongod --fork --dbpath /var/lib/mongodb/ --smallfiles --logpath
/var/log/mongodb.log --logappend
To Shut Down MongoDB enter the Mongo CLI, access the admin and issue the shutdown command:
$ ./mongo
> use admin
> db.shutdownServer()
shutdown mongodb with:
/usr/bin/mongodb --config $PATH-TO-CONFIG --shutdown
(replace /usr/bin with the right directory)
copy new mongodb and restart mongodb afterwards.
Depends on the version upgrade, but usually if it's a major upgrade (example from 1.8.xx to 2.0.XX) you should do at least the following steps:
backup your data (mongoexport or check this MongoDB backup documentation)
stop the server (use admin db.shutdownServer() )
copy or symbolic link the new mongodb binaries
run mongod with the --upgrade flag (mongod - f --upgrade)
when upgrade done, restart the mongod server
After that make sure that everything is working properly. If not switch back to the old version, import the data from the backup and check mongoDB jira :)
1.Import the public key used by the package management system
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
2. Create a list file for MongoDB.
echo 'deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.list
3. Reload local package database.
sudo apt-get update
4. stop the existing service
sudo service mongodb stop
5. first migrate to 2.4 to 2.6
Install a specific release of MongoDB
sudo apt-get install -y mongodb-org=2.6.12 mongodb-org-server=2.6.12 mongodb-org-shell=2.6.12 mongodb-org-mongos=2.6.12 mongodb-org-tools=2.6.12
6.unlink the temp links
remove the lock file.
rm /tmp/mongodb-27017.sock
7.restart mongo service
sudo service mongodb restart
8. Now finally migrate from 2.6 to 3.0
sudo apt-get install -y mongodb-org=3.0.12 mongodb-org-server=3.0.12 mongodb-org-shell=3.0.12 mongodb-org-mongos=3.0.12 mongodb-org-tools=3.0.12
restart again and voila !!!!
For more details follow the official documentation:
mongo doc
To upgrade from version 2 to version 3
I was unsuccessful using the methods in the other answers here, and was finally successful when following the offical document's "Upgrade Binaries" approach, like so:
Stop mongo from running :
$ sudo service mongod stop
Download the correct binaries
(from here, and for help getting the correct version see this
answer)
Copy the downloaded binaries over :
$ sudo cp downloaded_binaries/bin/* /usr/bin
Restart mongo :
$ sudo service mongod start