31 May, 2012

Windows Portable Rails Development Environment

To set a fully functional Ruby on Rails development environment in Windows you need to download the following:
  1. Ruby binaries archive (Ruby 1.8.7 recommended)
  2. Latest RubyGems (if the binaries doen't already contain them)
  3. Ruby Development Kit from rubyinstaller.org
  4. (Optional) Eclipse IDE for JavaScript Web Developers
  5. (Optional) Notepad++ Portable

  • Firstly choose and create a folder which will contain all the development environment (i.e. C:\RailsPortableEnv) and don't use weird characters on the folder name and on its complete path. Inside this folder create the following folder organization (this is only a suggestion):
  • Inside the ruby\ruby folder extract the ruby files downloaded on (1).
  • Extract the RubyGems file into ruby\rubygems
  • Move the self-extracting file you downloaded on (3) inside the ruby\devkit folder. Run the file and click right away the Extract button right away because it will extract the files to this folder.
  • Now lets start building a console to use the Ruby on Rails and Development-Kit binaries and funcionallities
    • Create a script: ruby\setpaths.bat with the commands:
      @set PATH=%PATH%;%cd%\ruby\bin
      @set PATH=%PATH%;%cd%\devkit\bin
      @set PATH=%PATH%;%cd%\devkit\mingw\bin
      @set PATH=%PATH%;%cd%\devkit\mingw\libexec\gcc\mingw32\4.5.2
      @set PATH=%PATH%;%cd%\devkit\mingw\mingw32\bin
      @set PATH=%PATH%;%cd%\devkit\sbin\awk
    • Create a script: ruby\console.bat with the commands:
      @cmd /K setpaths.bat
    • You can now run the console.bat executable and have a console in which you can create and run Rails projects
  • Rails will be installed through ruby gems with the following steps:
    • Run the console ( console.bat )
    • Input the following command:  gem install rails
    • If the console was properly set the gem installation will detect the development kit and will build the gem that require compilation
  • Test your rails installation by creating a rails project 
    • Create the directory Projects\InstallTest
    • Run the console and enter the created folder
    • Input the following command: rails new .
    • If no errors are reported then your installation is ok

    Now for the optional configuration of the IDE with debugger follow this:

        • Inside eclipse folder extract the content of the file downloaded on (4)
        • Install the plugins for ruby development found in the DLTK plugins in eclipse site
        • Run the eclipse IDE and when you are asked for a workspace location insert ..\..\Projects and check Use this as the default and do not ask again to prevent future mistakes. This way you will always have your projects inside the portable structure.
        • Configure the ruby binaries in Windows/Preferences -> Ruby -> Ruby Path and input the ruby binary path
          • This step is the only that has to be redone everytime you change this portable environment place. In mu case, I have it on my usb pen drive so it is ok
        • Install ruby debugger for IDEs like eclipse
          • Type in the console:   gem install ruby-debug-ide
        • After creating a new Ruby project and created a rails project inside it you can debug it by debugging the script\rails.rb script like a normal ruby script with the script argument  server

        No comments: