MongoDB - upgrade from 3.2 to 3.4 - mongodb

I updated with this commands from MongoDB 3.2 to 3.4:
https://medium.com/mongoaudit/how-to-upgrade-mongodb-to-latest-stable- version-9607266834cf:
sudo rm /etc/apt/sources.list.d/mongodb*.list
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
sudo apt-get install -y mongodb-org shows this lines:
root#accounting:/home/accounting# sudo apt-get install -y mongodb-org
Paketlisten werden gelesen... Fertig
Abhängigkeitsbaum wird aufgebaut.
Statusinformationen werden eingelesen.... Fertig
»mongodb-org« ist bereits die neuste Version (3.4.17).
Afterwards I started mongo and the following lines are shown:
root#accounting:/home/accounting# mongo
MongoDB shell version: 3.2.17
How can I update MongoDB shell version to 3.4.17?
[SOLVED]
sudo service mongod stop
sudo apt-get purge mongodb-org*
mongod --shutdown

Related

MongoDB is not installed correctly in Ubuntu 18.04 server

Specs: Ubuntu 18.04 Nginx server, Vestacp control panel.
MongoDB was pre-installed in my server, in 3.6.3 version. It was working but I wanted to upgrade it to version 4.4 (current release).
The problem now is that I can't start the mongo service (community edition).
Steps I followed so far:
Stop MongoDB service, Remove packages and remove Data Directories.
sudo service mongod stop
sudo apt-get purge mongodb-org*
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
Trying to install the new version 4.4 the exact steps from the documentation. Below are the commands with an order:
wget -qO - https://www.mongodb.org/static/pgp/server-4.4.asc | sudo apt-key add -
sudo apt-get install gnupg
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 bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org
echo "mongodb-org 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
ps --no-headers -o comm 1
sudo systemctl start mongod
sudo systemctl daemon-reload
sudo systemctl enable mongod
mongo
Errors:
sudo apt-get update
It throws an error:
Skipping acquire of configured file 'nginx/binary-i386/Packages' as repository 'http://nginx.org/packages/mainline/ubuntu bionic InRelease' doesn't support architecture 'i386'
On the step:
sudo apt-get install -y mongodb-org
E: Sub-process /usr/bin/dpkg returned an error code (1)
On the step:
sudo systemctl start mongod
Failed to start mongod.service: Unit mongod.service not found.
Directories:
/var/lib/mongodb
and
/var/log/mongodb
are not auto-created after the installation and I can't find them on the above paths.
The port I am trying to begin the server is the default 27017 and I set the rules to ufw.
I am tried to find a solution from similar posts but nothing. I'm stuck for two days now.
Any thought or help?
The problem was in uninstallation of previous MongoDB version 3.6.3.
The command in terminal...
sudo apt-get purge mongodb-org*
...Doesn't uninstall all the packages correctly.
The correct uninstallation was to type in the command line:
sudo apt list --installed | grep mongo
...In order to see if there are any packages left from MongoDB. I had 2 packages left that "purge mongodb-org*" couldn't delete.
So the correct removing executions are the below:
sudo apt remove mongodb
sudo apt purge mongodb
sudo apt autoremove
After that, the installation of the new MongoDB version 4.4 was successfully completed without errors!

How to install Mongo 3.4 on Ubuntu 18.04 bionic

So the things I have tried are:
1)
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
2)
echo "deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list deb [ arch=amd64 ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/3.4 multiverse
3)
sudo apt-get update
4)
sudo apt-get install -y mongodb-org=3.4.10 mongodb-org-server=3.4.10 mongodb-org-shell=3.4.10 mongodb-org-mongos=3.4.10 mongodb-org-tools=3.4.10
But I got this error:
E: Version '3.4.10' for 'mongodb-org' was not found
E: Version '3.4.10' for 'mongodb-org-server' was not found
E: Version '3.4.10' for 'mongodb-org-shell' was not found
E: Version '3.4.10' for 'mongodb-org-mongos' was not found
E: Version '3.4.10' for 'mongodb-org-tools' was not found
I have read the other article about this, but it did not work for me and I don't want to use a docker image.
ok so the things to do to install this version are
Step 1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Step 2
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Step 3
sudo apt update
Step 4
sudo apt-get install -y mongodb-org=3.4.17 mongodb-org-server=3.4.17 mongodb-org-shell=3.4.17 mongodb-org-mongos=3.4.17 mongodb-org-tools=3.4.17
here is the really helpful source: https://askubuntu.com/questions/1089312/install-and-use-mongodb-3-4-17-on-ubuntu-18-04

Cannot install postgres on Ubuntu (E: Unable to locate package postgresql)

So I'm having this problem where for some reason I can't install any package on my ubuntu system.
I'm currently on Ubuntu 16.10.
terminal install logs
Update:
I've done entered those commands and got this.
after update and apt-cache
What should I do now?
sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt-get install postgresql postgresql-contrib
After installing the PostgreSQL database server, by default, it creates a user ‘postgres’ with role ‘postgres’. Also creates a system account with the same name ‘postgres’. So to connect to Postgres server, log in to your system as user postgres and connect database.
sudo su - postgres
psql
First do
sudo apt-get update
You should get no errors upon updating. In case you do, then you might have issues with your firewall, or something blocking you from updating repositories. Check the output carefully.
And then search for the correct (exact!) package name using this command:
apt-cache search postgresql
As a last resort you could add external 3rd Party repository as described in this answer. Just remember to use your distribution name instead of "xenial".
It should work.
$ sudo apt-get install postgresql postgresql-client
If you are getting (E: Unable to locate package postgresql-12) while migrating following step may helps you:
sudo apt-get -y install bash-completion wget
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc |
sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql-12 postgresql-client-12
sudo systemctl status postgresql
ref:install postgres12 in ubuntu-18.04
Following Commands worked for me: sudo apt-get install wget ca-certificates
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -
sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ lsb_release -cs-pgdg main" >> /etc/apt/sources.list.d/pgdg.list'
sudo apt-get update
sudo apt install postgresql-11 libpq-dev

Getting error status:unknown job while starting MongoDB using Ubuntu

I am not able to start MongoDB in my Ubuntu machine. First I follow below steps to install MongoDB in my Ubuntu system.
1->sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7F0CEB10
2-> echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
3-> sudo apt-get update
4-> sudo apt-get install -y mongodb-org
5-> service mongod start
While I tried to start the MongoDB I got the following message rather than its starting.
status:unknown job : mongod
I am trying to also remove the mongodb.lock file from /var/lib/mongodb folder but unable to remove here I need to start the MongoDB service.
ok try this one:
sudo apt-get purge mongodb-stable
sudo apt-get install mongodb-stable
(remove the lock file if present in /var/lib/mongodb)
Then edit /etc/init/mongodb.conf removing the line "limit nofile 20000"

MongoDB GPG - Invalid Signatures

I'm installing MongoDB on an Ubuntu 14.04 machine, using the instructions at:
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-ubuntu/
So I run:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
And then:
echo "deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
Followed by:
sudo apt-get update
I then get the following warning at the end of the update:
W: GPG error: http://repo.mongodb.org trusty/mongodb-org/3.2 Release:
The following signatures were invalid: BADSIG D68FA50FEA312927 MongoDB
3.2 Release Signing Key
If I ignore the warning and try to run:
sudo apt-get install -y mongodb-org
I get:
WARNING: The following packages cannot be authenticated!
mongodb-org-shell mongodb-org-server mongodb-org-mongos
mongodb-org-tools mongodb-org E: There are problems and -y was used
without --force-yes
Any ideas on how to resolve? Thanks!
Update all expired keys from Ubuntu key server in one command:
sudo apt-key list | \
grep "expired: " | \
sed -ne 's|pub .*/\([^ ]*\) .*|\1|gp' | \
xargs -n1 sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys
Command explanation:
sudo apt-key list - lists all keys installed in the system;
grep "expired: " - leave only lines with expired keys;
sed -ne 's|pub .*/\([^ ]*\) .*|\1|gp' - extracts keys;
xargs -n1 sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys - updates keys from Ubuntu key server by found expired ones.
Source
Sounds like you need to redo the installation steps for MongoDB.
First, remove any existing repository file for MongoDB. Do as below:
$ sudo rm /etc/apt/sources.list.d/mongodb*.list
Next, add the key (without the key, the repository will not load):
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
Now, create a new MongoDB repository list file:
$ echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
After adding the repository details, we need to update the packages list:
$ sudo apt-get update
Now install MongoDB:
sudo apt install mongodb-org
You don't need to reinstall the mongo packages, but just change the key as following:
List the keys to confirm it is expired:
apt-key list | grep "expired:"
Replace the key:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 0xd68fa50fea312927
The number 0xd68fa50fea312927 is the current valid key id (expires at 2019-10-09), as you can check here.
It seems version 3.2.1 has been released on 11/Jan/2016, and the packages signature is bad since this moment. The packages signature were fine the day before.
refs: https://jira.mongodb.org/browse/SERVER/fixforversion/15908/?selectedTab=com.atlassian.jira.jira-projects-plugin:version-summary-panel
You can either add the --force-yes option, or wait for a few hours that the mongodb team sees and fixes the issue.
There is already a ticket there: https://jira.mongodb.org/browse/SERVER-22144
I also faced this issue when installing MongoDB 4.0 on Ubuntu 16.04.
So I did.
sudo rm /etc/apt/sources.list.d/mongodb*.list - remove any existing file for MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv E52529D4 - add the key
sudo bash -c 'echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.0 multiverse" > /etc/apt/sources.list.d/mongodb-org-4.0.list' - create a new MongoDB repository list file
Now, Complete the installation with an update of repositories then install MongoDB, enable the mongod service and start it up, and last, check your MongoDB version:
sudo apt update
sudo apt install mongodb-org
systemctl enable mongod.service
systemctl start mongod.service
mongo --version
I also faced this issue when installing MongoDB 3.2 on my ubuntu 16.04 using the below commands. The below solution is provided as the question related to the v3.2 installation of MongoDB
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv EA312927
echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.2 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.2.list
sudo apt-get update
After running the above update command i found the following warnings
W: GPG error: http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release: The following signatures were invalid: KEYEXPIRED 1507497109
W: The repository 'http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.2 Release' is not signed.
N: Data from such a repository can't be authenticated and is therefore potentially dangerous to use.
N: See apt-secure(8) manpage for repository creation and user configuration details.
On further investigating using the below command to list all the keys
sudo apt-key list
It shows that the current key is expired on 2017-10-08
pub 4096R/EA312927 2015-10-09 [expired: 2017-10-08]
uid MongoDB 3.2 Release Signing Key <packaging#mongodb.com>
This also made sense as the MongoDB Current Stable Release is now (3.4.9).
To fix the issue first we make a small cleanup (optional)
we remove the old key added
sudo apt-key list // List all keys
sudo apt-key del EA312927 // Find the uid of the key to be deleted
apt-key list | grep Mongodb // Verify if its deleted
Now we remove the MongoDB repo added in /etc/apt/sources.list.d
sudo rm /etc/apt/sources.list.d/mongodb*.list
Now we install the latest stable version of MongoDB(3.4.9) using below commands
Import the Public Key used by the Ubuntu Package Manager
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Create a file list for mongoDB to fetch the current repository
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-3.4.list
Install MongoDB
sudo apt-get update
sudo apt-get install mongodb-org
I had the same problem, and solved it by installing mongodb with tarball method. Refer to the below link for detail.
https://docs.mongodb.org/manual/tutorial/install-mongodb-on-linux/
Adding details below
curl -O https://fastdl.mongodb.org/linux/mongodb-linux-i686-3.2.0.tgz
tar -zxvf mongodb-linux-i686-3.2.0.tgz
mkdir -p mongodb && cp -R -n mongodb-linux-i686-3.2.0/ mongodb
export PATH=/bin:$PATH
then run mongod (db path might needs to be set)
I experienced the similar problem and got the following error while installing MongoDB 4.2 on Ubuntu 18.04 instance on Google Cloud.
W: GPG error: http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 Release: The following signatures couldn't be verified because the public key is not available: NO_PUBKEY 4B7C549A058F8B6B
E: The repository 'http://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.2 Release' is not signed.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details
The solution that worked from me was running the following command to get the key. I found this on MongoDB official Jira Issue Pages.
/usr/bin/curl -sLO https://www.mongodb.org/static/pgp/server-4.2.asc && sudo /usr/bin/apt-key add server-4.2.asc
I found this solution in MongoDB official Jira issues. Here is the link to the issue.
Actually, the following is very important to solve the problem
$ sudo rm /etc/apt/sources.list.d/mongodb*.list
wget -qO - https://www.mongodb.org/static/pgp/server-3.2.asc | sudo apt-key add -
I had the same problem, so I did:
root#skarabi:~# apt remove mongodb-org
Then:
root#skarabi:~# sudo rm /etc/apt/sources.list.d/mongodb*.list
After :
root#skarabi:~# apt update
Using dlopatin's answer I came up with this for Ubuntu 18.04 since that code doesnt work anymore:
sudo apt-key list | \
grep -A 1 "\[expired:" | \
sed -ne 's|^\s\{1,10\}\(\w*\)|\1|gp' | \
xargs -d '\n' sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys
List keys sudo apt-key list
Get the expired one and print the next line with the fingerprint grep -A 1 "\[expired:"
Use sed to extract only the lines starting with space ^\s\{1,10\},and select the alphanumeric characters \(\w*\), replace those lines with the selected group which is the fingerprint \1, repeat for all returned lines g,then print the fingerprint p. That gives: sed -ne 's|^\s\{1,10\}\(\w*\)|\1|gp'
Use xargs with delimiter for '\n' otherwise it will break on spaces: xargs -d '\n', then pass the fingerprints as arguments to apt-key to update them: sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys which gives you: xargs -d '\n' sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys
Hopefully that is clear. Ignore the warning about apt-key output parsing :)
This worked for me on ubuntu focal 20.04.01 LTS for installing MongoDB version 3.4.17:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
sudo apt update
apt-cache policy libssl1.0-dev
sudo apt-get install libssl1.0-dev
sudo apt-get install -y mongodb-org=3.4.17 mongodb-org-server=3.4.17 mongodb-org-shell=3.4.17 mongodb-org-mongos=3.4.17 mongodb-org-tools=3.4.17