Friday, June 20, 2014

Cài đặt Ruby on Rails trên Windows

Mình sẽ hướng dẫn các bạn cài đặt Ruby on Rails trên Windows. Nội dung trong dấu { và } là mình ví dụ cụ thể cho dễ hiểu.
  1. Tải RubyInstaller và cài đặt, chọn thiết lập biến môi trường trong quá trình cài đặt để có thể sử dụng lệnh của Ruby trên Command line bất cứ đâu. { ví dụ: Ruby 1.9.3-p545 }
  2. Tải Development Kit (cùng trang với RubyInstaller) với phiên bản tương ứng { ví dụ: DevKit-tdm-32-4.5.2-20111229-1559-sfx.exe }
  3. Cài đặt Development Kit
    • Giải nén file vừa tải { C:\ruby_dk }
    • Mở command line [cmd] (thao tác nhanh: Windows + R -> Open: cmd -> OK/Enter)
    • Nhảy đến thư mục vừa giải nén Development Kit bằng lệnh cd { cd C:\ruby_dk }
    • cmd:  ruby dk.rb init 
    • Sau đó chạy tiếp lệnh cmd:  ruby dk.rb install 
  4. Cài đặt Rails
    • cmd:  gem install rails 
    • Nếu lệnh chạy thất bại (do lỗi kết nối chẳng hạn) thì bạn chạy lại nó thêm lần nữa
  5. Tạo sườn ứng dụng
    • cmd:  rails new your_path  { rails new helloworld }
    • Lưu ý: nếu your_path bạn không để đường dẫn đầy đủ { C:\abc\helloworld } thì sẽ tạo thư mục ứng dụng trong thư mục hiện hành của cmd
    • Tương tự, nếu có lỗi kết nối xảy ra bạn chịu khó chạy lại câu lệnh
    • Lỗi quá trình cài đặt Bundle, bạn cd đến thư mục your_path và chạy lệnh  bundle install  {  cd helloworld  ->  bundle install  }
  6. Khởi động server
    • cd đến thư mục ứng dụng {  cd helloworld  }
    • cmd:  rails server 
    • Trên trình duyệt, gõ địa chỉ http://localhost:3000
Hướng dẫn gốc ở đây

Sẵn đây mình tập viết tiếng Anh luôn ^^!

++ Brief instruction in English (How to install Ruby on Rails on Windows)

  1. Download  RubyInstaller for Windows and corresponding Development Kit at HERE (notice RubyInstaller version vs Development Kit version)
  2. Install RubyInstaller (choose Add Ruby executables to your PATH option for using Ruby command everywhere)
  3. Install Development Kit
    • Extract downloaded file to somewhere
    • cd to it (open command line panel: Windows + R -> Open: cmd -> OK/Enter)
    •  ruby dk.rb init 
    •  ruby dk.rb install 
  4. Install Rails
    •  gem install rails 
    • If there is any failure i.e connection problem, run it again :)
  5. Create your application skeleton
    •  rails new your_path 
    • If bundle installation fails, cd to your application folder and run  bundle install  until no error
  6. Start server
    • cd to your application folder
    •  rails server 
    • Browser address: http://localhost:3000
The original Ruby on Rails instruction is at HERE

No comments:

Post a Comment