在Ubuntu 16.04上安装MongoDB时,指定版本的记录备忘

按照《在Ubuntu上安装MongoDB Community Edition》的公式进行操作。在Azure虚拟机的Ubuntu 16.04上安装MongoDB。

执行以下命令基本上是可以的,但是出现了一些错误。

    publivk keyの設定
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2930ADAE8CAF5059EE73BB4B58712A2291FA4AD5
    Ubuntu 16.04でリストファイル作成
echo "deb [ arch=amd64,arm64 ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.6 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.6.list
    ローカルパッケージの更新
sudo apt-get update
    MongoDBのインストール

最新版本似乎是3.6.0,因此需要指定版本进行安装。只要更改这个数字,就可以进行版本的指定。

$ sudo apt-get install -y mongodb-org=3.6.0 mongodb-org-server=3.6.0 mongodb-org-shell=3.6.0 mongodb-org-mongos=3.6.0 mongodb-org-tools=3.6.0

出现了错误。

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-server mongodb-org-shell
  mongodb-org-tools
0 upgraded, 5 newly installed, 0 to remove and 201 not upgraded.
Need to get 66.8 MB of archives.
After this operation, 276 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  mongodb-org-shell mongodb-org-server mongodb-org-mongos mongodb-org-tools
  mongodb-org
E: There were unauthenticated packages and -y was used without --allow-unauthenticated

E:由于存在未验证的软件包,并且使用了不带 –allow-unauthenticated 参数的 -y 选项,所以一旦去掉了 -y 选项,安装成功了。

$ sudo apt-get install mongodb-org=3.6.0 mongodb-org-server=3.6.0 mongodb-org-shell=3.6.0 mongodb-org-mongos=3.6.0 mongodb-org-tools=3.6.0

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-server mongodb-org-shell
  mongodb-org-tools
0 upgraded, 5 newly installed, 0 to remove and 201 not upgraded.
Need to get 66.8 MB of archives.
After this operation, 276 MB of additional disk space will be used.
WARNING: The following packages cannot be authenticated!
  mongodb-org-shell mongodb-org-server mongodb-org-mongos mongodb-org-tools
  mongodb-org
Install these packages without verification? [y/N] ← yをタイプ

成功地安装完成了。

在中文中,可以使用mongod –version命令来检查版本。

$ mongod --version
db version v3.6.0
git version: a57d8e71e6998a2d0afde7edc11bd23e5661c915
OpenSSL version: OpenSSL 1.0.2g  1 Mar 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: ubuntu1604
    distarch: x86_64
    target_arch: x86_64

启动

$ sudo service mongod start
广告
将在 10 秒后关闭
bannerAds