Có 2 công cụ phổ biến để cài đặt và quản lý các phiên bản Ruby là rbenv và rvm. Chúng ta sẽ sử dụng rbenv. Để cài đặt, chạy các lệnh sau trên Terminal:
brew install rbenv ruby-build
# Add rbenv to bash so that it loads every time you open a terminal
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
source ~/.bash_profile
rbenv install 2.2.3
rbenv global 2.2.3
ruby -v
Rất đơn giản:
gem install rails -v 4.2.4
Để sử dụng được lệnh rails, chúng ta cần cho rbenv thấy nó:
rbenv rehash
Và giờ chúng ta có thể xác nhận được Rails đã được cài:
rails -v
# Rails 4.2.4
Tạo ứng dụng Rails của bạn:
rails new myapp
#### If you want to use MySQL
rails new myapp -d mysql
#### If you want to use Postgres
# Note you will need to change config/database.yml's username to be
# the same as your OSX user account. (for example, mine is 'chris')
rails new myapp -d postgresql
# Move into the application directory
cd myapp
# If you setup MySQL or Postgres with a username/password, modify the
# config/database.yml file to contain the username/password that you specified
# Create the database
rake db:create
rails server