Mac OS X Mountain Lion 10.8.5 開発環境構築

# Items to install

* Homebrew
* JDK
* MySQL
* Git
* Ruby, rbenv, rails
* Python, virtualenv, django
* Node.js, nvm, grunt

# Install JDK

[Java SE Development Kit 8 Downloads](http://www.oracle.com/technetwork/java/javase/downloads/index.html)

```
$ java -version
java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)
```

# Install homebrew

```
$ ruby -e "$(curl -fsSL https://raw.github.com/mxcl/homebrew/go/install)"
=> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1
 .
 .
 .
$ brew doctor
Your system is ready to brew.
$ brew update
Already up-to-date.
$ brew -v
Homebrew 0.9.5
```

# Install MySQL
```
$ brew install mysql
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/mysql-5.6.17_1.mountain_lion.bottle.tar.gz
Already downloaded: /Library/Caches/Homebrew/mysql-5.6.17_1.mountain_lion.bottle.tar.gz
 .
 .
 .
```

# Install Git
```
$ git --version
git version 1.8.5.2 (Apple Git-48)
$ brew install git
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/git-1.9.2.mountain_lion.bottle.tar.gz
 .
 .
 .
$ brew link git
$ git --version
git version 1.9.2
```

# Install rbenv, Ruby, and Rails

```
$ brew install rbenv ruby-build
==> Downloading https://github.com/sstephenson/rbenv/archive/v0.4.0.tar.gz
######################################################################## 100.0%
 .
 .
 .
$ sudo cat >> ~/.bash_profile << EOF
export PATH="$HOME/.rbenv/bin:$PATH"
eval "$(rbenv init -)"
EOF
$ source ~/.bash_profile
$ rbenv -l
1.9.3-p545
 .
 .
 .
# Install Ruby 1.9.3
$ CONFIGURE_OPTS="--with-readline-dir=`brew --prefix readline` --with-openssl-dir=`brew --prefix openssl`" rbenv install 1.9.3-p545
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
 .
 .
 .
# Install Ruby 2.0.0
$ RUBY_CONFIGURE_OPTS="--with-readline-dir=$(brew --prefix readline) --with-openssl-dir=$(brew --prefix openssl)" rbenv install 2.0.0-p451
Downloading yaml-0.1.6.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/5fe00cda18ca5daeb43762b80c38e06e
Installing yaml-0.1.6...
 .
 .
 .
$ rbenv rehash
$ rbenv global 1.9.3-p545
$ ruby -v
ruby 1.9.3p545 (2014-02-24 revision 45159) [x86_64-darwin12.5.0]
$ sudo cat >> ~/.gemrc << EOF
install: --no-rdoc --no-ri
update: --no-rdoc --no-ri
EOF
$ sudo cat >> ~/.gemrc << EOF
--skip-bundle
--skip-test-unit
EOF
$ gem install rails
Fetching: rails-4.1.0.gem (100%)
 .
 .
 .
$ rbenv rehash
```

# Install Python

```
$ brew install python --universal --framework
==> Installing dependencies for python: pkg-config, readline, sqlite, gdbm, openssl
==> Installing python dependency: pkg-config
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/pkg-config-0.28.mountain_lion.bottle.2.tar.gz
######################################################################## 100.0%
 .
 .
 .
$ brew install python3 --universal --framework
==> Installing python3 dependency: xz
==> Downloading http://fossies.org/linux/misc/xz-5.0.5.tar.gz
######################################################################## 100.0%
 .
 .
 .
$ echo 'export PATH=/usr/local/bin:/usr/local/share/python:/usr/local/share/python3:$PATH' >> ~/.bash_profile
$ source ~/.bash_profile
$ python --version
Python 2.7.6
$ python3 --version
Python 3.4.0
$ brew update
$ pip install --upgrade setuptools
$ pip install --upgrade pip
$ pip3 install --upgrade setuptools
$ pip3 install --upgrade pip
$ brew linkapps
Linking /usr/local/Cellar/python/2.7.6_1/IDLE.app
Linking /usr/local/Cellar/python/2.7.6_1/Python Launcher.app
Linking /usr/local/Cellar/python3/3.4.0_1/IDLE 3.app
Linking /usr/local/Cellar/python3/3.4.0_1/Python Launcher 3.app
Finished linking. Find the links under /Applications.
```

# Install distribute
```
$ curl http://python-distribute.org/distribute_setup.py | sudo python
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17672  100 17672    0     0  18731      0 --:--:-- --:--:-- --:--:-- 18740
 .
 .
 .
$ curl http://python-distribute.org/distribute_setup.py | sudo python3
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 17672  100 17672    0     0  11731      0  0:00:01  0:00:01 --:--:-- 19484
 .
 .
 .

```

# Install virtualenv

```
$ pip install virtualenv virtualenvwrapper
Downloading/unpacking virtualenv
  Downloading virtualenv-1.11.4-py2.py3-none-any.whl (1.7MB): 1.7MB downloaded
 .
 .
 .
$ pip3 install virtualenv virtualenvwrapper
Downloading/unpacking virtualenv
  Downloading virtualenv-1.11.4-py2.py3-none-any.whl (1.7MB): 1.7MB downloaded
 .
 .
 .
$ sudo cat >> ~/.bashrc << EOF
source /usr/local/bin/virtualenvwrapper.sh
EOF
$ source ~/.bashrc
# virtualenv for Python 2.7.6
$ mkvirtualenv VIRTUALENV_NAME
# virtualenv for Python 3.4.0
$ mkvirtualenv VIRTUALENV_NAME --python /usr/local/bin/python3
$ workon VIRTUALENV_NAME
(VIRTUALENV_NAME)$ deactivate
$ exit
```

# Install Django and python modules to virtualenv

```
$ workon VIRTUALENV_NAME
(VIRTUALENV_NAME)$ cat >> ./pip-install.txt << EOF
django
django-debug-toolbar
BeautifulSoup
South
feedparser
lxml
mysql-python
pattern
python-dateutil
readability-lxml
requests
six
unicodecsv
urllib3
EOF
(VIRTUALENV_NAME)$ pip install -r pip-install.txt
Downloading/unpacking django (from -r pip-install.txt (line 1))
  Downloading Django-1.6.3-py2.py3-none-any.whl (6.7MB): 6.7MB downloaded
 .
 .
 .
(VIRTUALENV_NAME)$ rm -f pip-install.txt
(VIRTUALENV_NAME)$ pip freeze
(VIRTUALENV_NAME)$ deactivate
$ exit
```

# Install node.js, nvm, and grunt

```
$ brew install node
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/node-0.10.26.mountain_lion.bottle.tar.gz
######################################################################## 100.0%
 .
 .
 .
$ git clone git://github.com/creationix/nvm.git ~/.nvm
Cloning into '/Users/gumob/.nvm'...
remote: Reusing existing pack: 1256, done.
 .
 .
 .
$ source ~/.nvm/nvm.sh
$ node -v
v0.10.26
$ nvm --version
nvm v0.5.1
$ npm --version
1.4.7
$ gem install sass compass
Fetching: sass-3.3.6.gem (100%)
Successfully installed sass-3.3.6
 .
 .
 .
$ npm install -g grunt-cli
npm http GET https://registry.npmjs.org/grunt-cli
npm http 200 https://registry.npmjs.org/grunt-cli
 .
 .
 .
/usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt
grunt-cli@0.1.13 /usr/local/lib/node_modules/grunt-cli
├── resolve@0.3.1
├── nopt@1.0.10 (abbrev@1.0.4)
└── findup-sync@0.1.3 (lodash@2.4.1, glob@3.2.9)
```

# Other configuration

```
$ sudo visudo
$ sudo cat /etc/sudoers
# User privilege specification
 .
 .
 .
# User privilege specification
root    ALL=(ALL) ALL
%admin  ALL=(ALL) ALL
username  ALL=(ALL) NOPASSWD: /usr/bin/rsync
 .
 .
 .
```