Mac上配置 Ruby on Rails跟Git

Mac上配置 Ruby on Rails和Git
Ruby on Rails on Mac
====================================================================================
http://morizyun.github.io/blog/marvericks-rails-setup-ruby-rvm-msyql/
for general : useful : http://qiita.com/keneo/items/0a58b188183b5100e3af
for mysql : http://qiita.com/hkusu/items/cda3e8461e7a46ecf25d
http://dev.classmethod.jp/server-side/language/build-ruby-environment-by-rbenv/
1.安装Homebrew 
$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.安装rbenv
$brew install ruby-build
$brew install rbenv
设置path
$ echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> .bash_profile
$ echo 'eval "$(rbenv init -)"' >> .bash_profile
$ source .bash_profile
3.安装可能用的工具,包
3.1 安装sublime和配置用命令行打开 sublime
https://gist.github.com/olivierlacan/1195304
安装好sublime以后,在/usr/local/bin下面创建它的快捷方式,这样就能在任何地方都能执行subl来启动sublime
$ln -s /Applications/Sublime\ Text\ 2.app/Contents/SharedSupport/bin/subl /usr/local/bin/sub
3.2 装git
$rew install git
3.3 使用irb(interactive ruby)的包
$ brew install readline
3.4 安装使用https的包
$ brew install openssl
4.安装ruby
$ rbenv install -l 确定可以安装的ruby
$ rbenv install 2.1.4 安装要使用的版本
$ rbenv global 2.1.4 设定使用的版本,如果不设置,直接ruby -v看到的可能是其他版本
$ rbenv versions 确认
$ ruby -v 会显示ruby 2.1.4p265 (2014-10-27 revision 48166) [x86_64-darwin14.0]
5.安装rails
$ gem install rails
$ gem install bundler
$ rbenv rehash
$ source ~/.bash_profile
$ rails -v 会显示 rails 4.2.1
6.安装 MySql
$ brew update
$ brew install mysql
$ brew infö mysql 确认,也可以mysql —version 只看版本号
7.启动rails
$ rails server
打开http://localhost:3000确认是否成功
Ctrl+c 退出
8.使用MySql
$ mysql.server start
$ mysql -uroot 默认没有密码 如果要设密码执行以下语句
$ mysql_secure_installation 
$ mysql -uroot -p 带密码
mysql>exit 退出
$ mysql.server stop
9.第二次启动电脑后,执行rails -v 提示未安装,执行ruby -v显示的是2.0.0,执行rbenv global 2.1.4后还是不变。此时执行
$ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile (把rbenv的初始化脚本写入该文件)(如果权限不够,修改该文件拥有者为用户)
$ source ~/.bash_profile(执行该文件)
再执行ruby -v rails -v就可以了。
10.开发Ruby on Rails
http://openbook4.me/projects/92
11. 创建工程及上传到github
$git config --global user.name "ユーザー名"
$git config --global user.email email@example.com
$git config --global core.editor "subl -w" //配置编辑器,这里是subl
$subl ~/.netrc 追加以下 //如果不执行,每次push需要输入username和password
machine github.com
login USERNAME
password PASSWORD

$rails new larry-twitter //创建app
$cd larry-twitter
$ git init //会在app目录下创建git repo, larry-twitter
$ git add .
$ git commit -m "Initialize repository"
网页github上创建repository,获取https
$ git remote add origin https://github.com/yangpeng-chn/larry-twitter.git
$ git push -u origin master
====================================================================================