sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 echo "deb [ arch=amd64,arm64 ] 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
2017-08-19T22:43:46.437-0700 E NETWORK [initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
2017-08-19T22:43:46.437-0700 E NETWORK [initandlisten] addr already in use
sudo service mongod startStarts listening for port 0.0.0.0:27017
sudo service mongodb stop
sudo mongodandsudo mongod
sudo service mongodb start
If i runsudo service mongodb start
I did not get a return statement
Hi William,
You shouldn’t be expecting an output from Ubuntu 16.04 service mongod start, if you would like to know the status you should instead execute sudo service mongod status
Example status output:
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: active (running) since Thu 2017-08-24 09:26:26 AEST; 2s ago
Docs: https://docs.mongodb.org/manual
Main PID: 14321 (mongod)
CGroup: /system.slice/mongod.service
└─14321 /usr/bin/mongod --config /etc/mongod.conf
[initandlisten] listen(): bind() failed Address already in use for socket: 0.0.0.0:27017
This is because mongod was executed twice, first using sudo service mongodb start and afterward sudo mongod ; both tried to bind on the same port number 27017 (default). See also guide Ubuntu: Run MongoDB.
Now, I’m wondering what is the difference
One of the differences that you can see from the output of status, is that service mongod executes the equivalent of /usr/bin/mongod --config /etc/mongod.conf. You can check the default content of /etc/mongod.conf for more information. Please see also MongoDB Configuration Options file.
If you would like to know more about the differences between executing a command via service or directly, I would recommend to ask/browse on Ask Ubuntu Forum as it would be more related to Ubuntu than MongoDB.
Regards,
Wan.