Search code examples
ruby-on-railsrubyrailsinstaller-windows

rails --version command not working on Windows


I installed Rails from http://railsinstaller.org/en on my Windows 7 desktop and the installation went fine. However, after installation when I do:

C:\Sites>rails --version
The system cannot find the path specified.

C:\Sites>ruby -v
ruby 2.2.4p230 (2015-12-16 revision 53155) [i386-mingw32]

C:\Sites>gem -v
2.4.5.1

Solution

  • After much digging around I found errors in a few of the *.bat (nokogiri, scss,...) files located in C:\path\to\RailsInstaller\Ruby2.2.0\bin.

    This was the content of rails.bat:

    @ECHO OFF
    IF NOT "%~f0" == "~f0" GOTO :WinNT
    @"C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe" "C:/Users/emachnic/GitRepos/railsinstaller-windows/stage/Ruby2.2.0/bin/rails" %1 %2 %3 %4 %5 %6 %7 %8 %9
    GOTO :EOF
    :WinNT
    @"C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe" "%~dpn0" %*`
    

    After removing the hardcoded paths C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\, the rails command reports the correct version:

    C:\path\to\RailsInstaller3.2\Ruby2.2.0\bin>rails -v
    Rails 4.2.5.1