Choorker's Field Notes.

トップウォータープラッギング

MacにCouchDBをインストール

f:id:hsaitou:20130126161916j:plain
こないだの入門 ソーシャルデータ - FNTA™の続き。
3章でCouchDBを扱っているのでインストールした。

  • やったこと
    1. Homebrewのインストール
      1. Command Line Toolsをインストール
      2. brew doctor
      3. brew update
    2. rubyのバージョンアップ
    3. CouchDBのインストール

Homebrewのインストール

  • Command Line Toolsをインストール

Homebrewを利用する時に必要になるので入れておく。
XCodeを開き、DownloadsからCommand Line Toolsをインストールする。
f:id:hsaitou:20130126102725p:plain

  • TerminalからHomebrewをインストール
$ ruby <(curl -fsSk https://raw.github.com/mxcl/homebrew/go)
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
==> The following directories will be made group writable:
/usr/local/.
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share
/usr/local/share/man
/usr/local/share/man/man1
==> The following directories will have their group set to admin:
/usr/local/bin
/usr/local/include
/usr/local/lib
/usr/local/share/man
/usr/local/share/man/man1
Press ENTER to continue or any other key to abort
==> /usr/bin/sudo /bin/chmod g+rwx /usr/local/. /usr/local/bin /usr/local/include /usr/local/lib /usr/local/share /usr/local/share/man /usr/local/share/man/man1
Password:
==> /usr/bin/sudo /usr/bin/chgrp admin /usr/local/bin /usr/local/include /usr/local/lib /usr/local/share/man /usr/local/share/man/man1
==> Downloading and Installing Homebrew...
remote: Counting objects: 94958, done.
remote: Compressing objects: 100% (41768/41768), done.
remote: Total 94958 (delta 66570), reused 77929 (delta 52332)
Receiving objects: 100% (94958/94958), 14.04 MiB | 273 KiB/s, done.
Resolving deltas: 100% (66570/66570), done.
From https://github.com/mxcl/homebrew
 * [new branch]      master     -> origin/master
HEAD is now at b8ed4c1 scm-manager 1.27
==> Installation successful!
You should run `brew doctor' *before* you install anything.
Now type: brew help
$ brew doctor
Warning: /usr/bin occurs before /usr/local/bin
This means that system-provided programs will be used instead of those
provided by Homebrew. The following tools exist at both paths:

    2to3

Consider amending your PATH so that /usr/local/bin
occurs before /usr/bin in your PATH.

インストールの問題をチェックするため、brew doctorを実行。するとワーニングがでた。


パスを追加して再度試すとうまくできた。.bashrcに書いておこう。

$ export PATH=/usr/local/bin:$PATH
$ brew doctor
Your system is raring to brew.
  • brew update(アップデートのチェック)
$ brew update
Already up-to-date.


参考にさせて頂いた記事
[Mac] Mountain Lionへパッケージ管理「Homebrew」をインストールする手順のメモ | Tools 4 Hack

rubyのバージョンアップ

rubyのバージョンを確認したら1.8.7だったので、アップデート。

$ ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [universal-darwin12.0]


HomebrewでRubyをインストール。

$ brew install ruby
==> Installing ruby dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.27.1.mountainlion.bottle.tar
######################################################################## 100.0%
==> Pouring pkg-config-0.27.1.mountainlion.bottle.tar.gz
 /usr/local/Cellar/pkg-config/0.27.1: 9 files, 624K
==> Installing ruby dependency: readline
==> Downloading http://ftpmirror.gnu.org/readline/readline-6.2.tar.gz
######################################################################## 100.0%
==> Patching
patching file callback.c
patching file input.c
patching file patchlevel
patching file support/shobj-conf
patching file vi_mode.c
==> ./configure --prefix=/usr/local/Cellar/readline/6.2.4 --mandir=/usr/local/Cellar/readline/6.2.4/share/man 
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
 /usr/local/Cellar/readline/6.2.4: 31 files, 1.6M, built in 37 seconds
==> Installing ruby dependency: gdbm
==> Downloading http://ftpmirror.gnu.org/gdbm/gdbm-1.10.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/gdbm/1.10 --mandir=/usr/local/Cellar/gdbm/1.10/share/man --infodir=
==> make install
 /usr/local/Cellar/gdbm/1.10: 11 files, 240K, built in 25 seconds
==> Installing ruby dependency: libyaml
==> Downloading http://pyyaml.org/download/libyaml/yaml-0.1.4.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/libyaml/0.1.4
==> make install
 /usr/local/Cellar/libyaml/0.1.4: 7 files, 336K, built in 22 seconds
==> Installing ruby
==> Downloading http://ftp.ruby-lang.org/pub/ruby/1.9/ruby-1.9.3-p374.tar.gz
######################################################################## 100.0%
==> Patching
patching file missing/setproctitle.c
==> ./configure --prefix=/usr/local/Cellar/ruby/1.9.3-p374 --enable-shared --disable-tcltk-framework --with-ou
==> make
==> make install
==> Caveats
NOTE: By default, gem installed binaries will be placed into:
  /usr/local/Cellar/ruby/1.9.3-p374/bin

You may want to add this to your PATH.
==> Summary
 /usr/local/Cellar/ruby/1.9.3-p374: 785 files, 17M, built in 3.0 minutes

※おまけ

f:id:hsaitou:20130126162915p:plain
ビール?これなんなの?


終わったら、バージョンを再度確認する。

$ export PATH=/usr/local/bin:$PATH
$ ruby -v
ruby 1.9.3p374 (2013-01-15 revision 38858) [x86_64-darwin12.2.0]

CouchDBのインストール

時間掛かった。20分くらい。
なので気長に。

$ brew install erlang --no-docs
==> Installing erlang dependency: autoconf
==> Downloading http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
######################################################################## 100.0%
==> Patching
patching file bin/autoreconf.in
==> ./configure --prefix=/usr/local/Cellar/autoconf/2.69
==> make install
 /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M, built in 14 seconds
==> Installing erlang dependency: automake
==> Downloading http://ftpmirror.gnu.org/automake/automake-1.13.1.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/automake/1.13.1
==> make install
/usr/local/Cellar/automake/1.13.1: 126 files, 2.3M, built in 13 seconds
==> Installing erlang dependency: libtool
==> Downloading http://ftpmirror.gnu.org/libtool/libtool-2.4.2.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/libtool/2.4.2 --program-prefix=g --enable-ltdl-install
==> make install
==> Caveats
In order to prevent conflicts with Apple's own libtool we have prepended a "g"
so, you have instead: glibtool and glibtoolize.
==> Summary
/usr/local/Cellar/libtool/2.4.2: 66 files, 2.2M, built in 27 seconds
==> Installing erlang
==> Downloading https://github.com/erlang/otp/tarball/OTP_R15B03-1
######################################################################## 100.0%
==> Compilation takes a long time; use `brew install -v erlang` to see progress
==> ./otp_build autoconf
==> ./configure --prefix=/usr/local/Cellar/erlang/R15B03-1 --enable-kernel-poll --enable-threads --enable-dyna
==> make
==> make install
/usr/local/Cellar/erlang/R15B03-1: 4693 files, 112M, built in 21.4 minutes
$

CouchDBのインストール

ここから、ようやくCouchDBのインストール。
これ自体は割とすぐ終わる。

$ brew install couchdb
==> Installing couchdb dependency: help2man
==> Downloading http://ftpmirror.gnu.org/help2man/help2man-1.41.1.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/help2man/1.41.1
==> make install
/usr/local/Cellar/help2man/1.41.1: 7 files, 96K, built in 5 seconds
==> Installing couchdb dependency: nspr
==> Downloading https://ftp.mozilla.org/pub/mozilla.org/nspr/releases/v4.9.3/src/nspr-4.9.3.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/nspr/4.9.3 --enable-strip --enable-pthreads --enable-ipv6 --enable-
==> make
==> make install
/usr/local/Cellar/nspr/4.9.3: 99 files, 1.3M, built in 22 seconds
==> Installing couchdb dependency: spidermonkey
==> Downloading http://ftp.mozilla.org/pub/mozilla.org/js/js185-1.0.0.tar.gz
######################################################################## 100.0%
==> Downloading http://ftpmirror.gnu.org/autoconf/autoconf-2.13.tar.gz
######################################################################## 100.0%
==> ./configure --program-suffix=213 --prefix=/private/tmp/spidermonkey-5Lfy/js-1.8.5/ac213
==> make install
==> /private/tmp/spidermonkey-5Lfy/js-1.8.5/ac213/bin/autoconf213
==> ../js/src/configure --prefix=/usr/local/Cellar/spidermonkey/1.8.5 --enable-readline --enable-threadsafe --
==> make
==> make install
==> Caveats
This formula installs Spidermonkey 1.8.5.
If you are trying to compile MongoDB from scratch, you will need 1.7.x instead.
==> Summary
/usr/local/Cellar/spidermonkey/1.8.5: 101 files, 11M, built in 2.7 minutes
==> Installing couchdb dependency: icu4c
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/icu4c-50.1.mountainlion.bottle.1.tar.gz
######################################################################## 100.0%
==> Pouring icu4c-50.1.mountainlion.bottle.1.tar.gz
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Conflicts; see: https://github.com/mxcl/homebrew/issues/issue/167

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/icu4c/lib
    CPPFLAGS: -I/usr/local/opt/icu4c/include

==> Summary
/usr/local/Cellar/icu4c/50.1: 235 files, 55M
==> Installing couchdb
==> Downloading http://www.apache.org/dyn/closer.cgi?path=/couchdb/1.2.1/apache-couchdb-1.2.1.tar.gz
==> Best Mirror http://ftp.jaist.ac.jp/pub/apache/couchdb/1.2.1/apache-couchdb-1.2.1.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/couchdb/1.2.1 --localstatedir=/usr/local/var --sysconfdir=/usr/loca
==> make
==> make install
==> Caveats
If this is your first install, automatically load on login with:
    mkdir -p ~/Library/LaunchAgents
    cp /usr/local/Cellar/couchdb/1.2.1/Library/LaunchDaemons/org.apache.couchdb.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.apache.couchdb.plist

If this is an upgrade and you already have the org.apache.couchdb.plist loaded:
    launchctl unload -w ~/Library/LaunchAgents/org.apache.couchdb.plist
    cp /usr/local/Cellar/couchdb/1.2.1/Library/LaunchDaemons/org.apache.couchdb.plist ~/Library/LaunchAgents/
    launchctl load -w ~/Library/LaunchAgents/org.apache.couchdb.plist

Alternatively, automatically run on startup as a daemon with:
    sudo launchctl list org.apache.couchdb >/dev/null 2>&1 && \
      sudo launchctl unload -w /Library/LaunchDaemons/org.apache.couchdb.plist
    sudo cp /usr/local/Cellar/couchdb/1.2.1/Library/LaunchDaemons/org.apache.couchdb.plist /Library/LaunchDaemons/
    sudo launchctl load -w /Library/LaunchDaemons/org.apache.couchdb.plist

Or start manually as the current user with:
    couchdb
==> Summary
/usr/local/Cellar/couchdb/1.2.1: 334 files, 3.6M, built in 82 seconds
$
  • LaunchDaemonsを設定

これを実行しておくとPCを起動したときに必ず CouchDB サーバーが起動するようになる。

$ cp /usr/local/Cellar/couchdb/1.2.1/Library/LaunchDaemons/org.apache.couchdb.plist ~/Library/LaunchAgents/
$ launchctl load -w ~/Library/LaunchAgents/org.apache.couchdb.plist

インストールの確認

  • 管理ツールへアクセス

ここをたたいてみる。
http://localhost:5984/_utils/
すると・・・

f:id:hsaitou:20130126160336p:plain
これが出ればOK!


参考にさせて頂いた記事
Installing_on_OSX - Couchdb Wiki