我很长一段时间都遇到了同样的错误,在Google上尝试了几乎所有安装istruciton,但找不到答案...
我遵循了https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/中的说明,但始终收到错误无法启动mongod.service:未找到单元mongod.service
我首先使用以下命令进行安装:sudo apt-get install -y mongodb-org然后注意到我在运行:
$ sudo apt-get install -y mongodb-org
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
mongodb-org-mongos mongodb-org-shell mongodb-org-tools
The following NEW packages will be installed
mongodb-org mongodb-org-mongos mongodb-org-shell mongodb-org-tools
0 to upgrade, 4 to newly install, 0 to remove and 46 not to upgrade.
Need to get 0 B/40.1 MB of archives.
After this operation, 178 MB of additional disk space will be used.
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 379307 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.0.3_amd64.deb ...
Unpacking mongodb-org-shell (4.0.3) ...
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
Preparing to unpack .../mongodb-org_4.0.3_amd64.deb ...
Unpacking mongodb-org (4.0.3) ...
Setting up mongodb-org-shell (4.0.3) ...
Setting up mongodb-org-mongos (4.0.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up mongodb-org-tools (4.0.3) ...
Setting up mongodb-org (4.0.3) ...
$ mongod --version
db version v2.6.12
2018-10-26T12:03:12.362+0200 git version: d73c92b1c85703828b55c2916a5dd4ad46535f6a
数据库版本是2.6.12,而不是最新的4.0.3。因此,请确保您尚未安装mongodb-org-server,如果是,则请确保将其更新到目标版本(如@ https://docs.mongodb.com/manual/tutorial/install-mongodb-on所示) -ubuntu / ->步骤4-安装特定版本的MongoDB。
target_version = 4.0.3
sudo apt-get install -y mongodb-org = target_version mongodb-org-server = target_version mongodb-org-shell = target_version mongodb-org-mongos = target_version mongodb-org-tools = target_version
$ sudo apt-get install -y mongodb-org=4.0.3 mongodb-org-server=4.0.3 mongodb-org-shell=4.0.3 mongodb-org-mongos=4.0.3 mongodb-org-tools=4.0.3
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following NEW packages will be installed
mongodb-org mongodb-org-mongos mongodb-org-shell mongodb-org-tools
The following packages will be upgraded:
mongodb-org-server
1 to upgrade, 4 to newly install, 0 to remove and 45 not to upgrade.
Need to get 15.7 MB/55.8 MB of archives.
After this operation, 217 MB of additional disk space will be used.
Get:1 https:
Fetched 15.7 MB in 2s (6,289 kB/s)
Selecting previously unselected package mongodb-org-shell.
(Reading database ... 379306 files and directories currently installed.)
Preparing to unpack .../mongodb-org-shell_4.0.3_amd64.deb ...
Unpacking mongodb-org-shell (4.0.3) ...
**Preparing to unpack .../mongodb-org-server_4.0.3_amd64.deb ...
Failed to stop mongod.service: Unit mongod.service not loaded.
invoke-rc.d: initscript mongod, action "stop" failed.
dpkg: warning: old mongodb-org-server package pre-removal script subprocess returned error exit status 5
dpkg: trying script from the new package instead ...
dpkg: ... it looks like that went OK
Unpacking mongodb-org-server (4.0.3) over (2.6.12) ...**
Selecting previously unselected package mongodb-org-mongos.
Preparing to unpack .../mongodb-org-mongos_4.0.3_amd64.deb ...
Unpacking mongodb-org-mongos (4.0.3) ...
Selecting previously unselected package mongodb-org-tools.
Preparing to unpack .../mongodb-org-tools_4.0.3_amd64.deb ...
Unpacking mongodb-org-tools (4.0.3) ...
Preparing to unpack .../mongodb-org_4.0.3_amd64.deb ...
Unpacking mongodb-org (4.0.3) ...
Processing triggers for ureadahead (0.100.0-20) ...
Setting up mongodb-org-shell (4.0.3) ...
Setting up mongodb-org-mongos (4.0.3) ...
Processing triggers for systemd (237-3ubuntu10.3) ...
Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Setting up mongodb-org-tools (4.0.3) ...
Setting up mongodb-org-server (4.0.3) ...
Installing new version of config file /etc/mongod.conf ...
Setting up mongodb-org (4.0.3) ...
在完成此操作之后,对我来说都是:D