Mac OS X 10.10 Yosemite安装Mongodb小记

最近学习mongodb,安装mongodb的时候,本想使用Homebrew简便的方式进行安装。可是发现在升级到Mac OS X10.10后,Homebrew突然不能用了。小折腾了一下,小记如下:

1. 卸载Homebrew

貌似是ruby版本的问题,我的解决方法就是卸载重装,简单粗暴,不过也可以参照Mac OS X 10.10 Yosemite 开发者升级指南之Homebrew 。卸载Homebrew命令为:rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup

2. 重新安装Homebrew

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
Mac-mini:~ pengloo53$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
It appears Homebrew is already installed. If your intent is to reinstall you
should do the following before running this installer again:
rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
Mac-mini:~ pengloo53$
Mac-mini:~ pengloo53$ rm -rf /usr/local/Cellar /usr/local/.git && brew cleanup
Mac-mini:~ pengloo53$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
Press RETURN to continue or any other key to abort
==> Downloading and installing Homebrew...
remote: Counting objects: 229572, done.
remote: Compressing objects: 100% (60208/60208), done.
remote: Total 229572 (delta 168116), reused 229559 (delta 168108)
Receiving objects: 100% (229572/229572), 52.53 MiB | 37.00 KiB/s, done.
Resolving deltas: 100% (168116/168116), done.
From https://github.com/Homebrew/homebrew
* [new branch] master -> origin/master
HEAD is now at 4842aa9 ht: basic test added
==> Installation successful!

3. 检查错误

执行brew doctor,如果报错如下请接着往下走,不然跳过第4步

4. 升级XQuartz

在官网下载最新版本XQuartz

5. 更新相关组件

执行命令brew update

1
2
3
4
5
6
Mac-mini:~ pengloo53$ brew update
Updated Homebrew from c83f453a to 9a0fbf6a.
==> Updated Formulae
botan git-annex jpeg-turbo mpd spoof-mac x264
d-bus gnu-getopt libraw node v8
geoip iojs moreutils notmuch vnu

6. 安装mongodb

通过Homebrew安装mongodb,执行brew install mongodb

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Mac-mini:~ pengloo53$ brew install mongodb
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mongodb-2.6
Already downloaded: /Library/Caches/Homebrew/mongodb-2.6.7.yosemite.bottle.tar.gz
==> Pouring mongodb-2.6.7.yosemite.bottle.tar.gz
==> Caveats
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
==> Summary
🍺 /usr/local/Cellar/mongodb/2.6.7: 17 files, 332M
Mac-mini:~ pengloo53$ mongo --config /usr/local/etc/mongod.conf
Error parsing command line: unknown option config
try 'mongo --help' for more information

7. 启动mongodb服务

命令行sudo mongod ,若报错如下图

手动创建/data/db文件目录,mkdir -p /data/db,可能会报没有权限的错误,sudo !!再执行一遍。重新启动mongodb服务,sudo mongod,正常情况应该没有问题了,如下图

8. 进入mongo

命令行mongo,默认连接到了test数据库,进入后,db.stats()查看数据库相关信息。

##异常错误
如果报错误,errno61 Connection refused,请按照此步骤处理。MongoDB reason: errno:61 Connection refused - 推酷