57

I have installed Rails and Ruby on Windows with railsinstaller. The problem is, when I run the rails command, it gives me: "The system cannot find the path specified."

I am running windows 7 x64 and Ruby 2.20.

I tried uninstalling Rails and installing it again; that does not help. Ruby commands execute, like ruby -v, but rails -v= dont work.

Javid Asgarov
  • 1,511
  • 1
  • 18
  • 32

10 Answers10

103

Go into C:\RailsInstaller\Ruby2.2.0. In some of the .bat files, you'll find the following:

@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/tilt" %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" %*

Delete that and paste in the text below:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
ECHO.This version of Ruby has not been built with support for Windows 95/98/Me.
GOTO :EOF
:WinNT
@"%~dp0ruby.exe" "%~dpn0" %*
Raymond R
  • 1,350
  • 3
  • 12
  • 19
  • 3
    This is how a proper answer should be. :) Saved my time. :) – scripter Apr 03 '16 at 10:15
  • 8
    @scripter "In some of the .bat files," In which batch files we have to make these changes. Do we have to make these changes in all of the batch files because all of my batch files contains the upper code. – Priyansh Apr 04 '16 at 02:20
  • 2
    It's better to do. There are only few batch files. However making changes on rails.bat will work also. – scripter Apr 05 '16 at 16:05
  • @scripter is right, it's the specified files. Took me 5 minutes to go through and paste the code in each, it's not too painful. – Archibald Jun 23 '16 at 02:53
  • 3
    This is still the case on RailsInstaller for Ruby 2.3.0. Commonly, you just need to change the `bin\rails.bat` and `bin\bundle.bat`. – John Isaiah Carmona Jan 06 '17 at 01:28
  • I've had the same problem and I solved it changing the content of the file `C:\RailsInstaller\Ruby2.3.0\bin\rails.exe` for the one in this answer. Sadly RailsInstaller come with a couple of bugs, it would be nice to install Rails over Windows without doing stuff like this. – fsinisi90 Jan 12 '17 at 19:41
  • found this to correct a straight install on Windows, pretty careless that the install doesn't work – Tahbaza Feb 25 '17 at 05:49
  • Works. Thanks for the solution – kunaguvarun Jun 16 '17 at 14:15
43

This is due to a bug in RailsInstaller, where two files have the location of ruby.exe hard-coded to work only on the RailsInstaller dev's machine. In C:\RailsInstaller\Ruby2.2.0\bin\rails.bat (this is the default install folder, you might have rails.bat somewhere else if you picked a different install folder) you'll find these two lines:

@"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

@"C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe" "%~dpn0" %*

The emachnic user is the RailsInstaller developer. As a workaround, you can change these folders to the ones on your computer. For the default install folder, you'd change these to:

@"C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe" "C:\RailsInstaller\Ruby2.2.0\bin\rails" %1 %2 %3 %4 %5 %6 %7 %8 %9

@"C:\RailsInstaller\Ruby2.2.0\bin\ruby.exe" "%~dpn0" %*

You will have to repeat this change for two similar lines in C:\RailsInstaller\Ruby2.2.0\bin\bundle.bat as well.

Run rails -v to verify that rails is now working.

You can follow this issue on their git repo here: https://github.com/railsinstaller/railsinstaller-windows/issues/70

Al Sweigart
  • 11,566
  • 10
  • 64
  • 92
20

The solution is specified on github issues of railsinstaller - https://github.com/railsinstaller/railsinstaller-windows/issues/73

Javid Asgarov
  • 1,511
  • 1
  • 18
  • 32
  • 4
    Yes, it looks like it was a build problem for the Rails Installer leading to broken paths to ruby.exe. You probably don't need to fix them all but affected BAT files are: bundle.bat, bundler.bat, erubis.bat, nokogiri.bat, rails.bat, sprockets.bat, swlite3_ruby.bat, tilt.bat – Glenn Lawrence Mar 07 '16 at 10:19
9

I opened all the .bat files under C:\RailsInstaller\Ruby2.2.0\bin in Sublime Text, and replaced with Ctrl+Shift+F,

this
@"C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe"
with this
@"%~dp0ruby.exe"
across all files that had a match.

Took only a couple of seconds. This might help someone who stumbles across it after me and is daunted by the idea of performing a find and replace over multiple files.

Jayant Bhawal
  • 2,044
  • 2
  • 31
  • 32
9

I solved this problem on my windows machine by doing

  1. gem install bundler
  2. bundler install
  3. Number 1 and 2 fixed the problem and installed all gems.
Dmitry Shvedov
  • 3,169
  • 4
  • 39
  • 51
Serge_k
  • 187
  • 2
  • 2
3

I've created a super easy way to do @JayantBhawal's solution (worked perfectly fine for me) with Windows Powershell, which you should all have since this seems like a problem exclusive to Windows machines. It looks complicated but really all it's doing is replacing all the instances of C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe with %~dp0ruby.exe in the .bat files. Just open up Powershell, cd to C:\RailsInstaller\Ruby2.3.0\bin, and copy this small script:

Get-ChildItem . -Filter *.bat | Foreach-Object {
(Get-Content $_.name ) | ForEach-Object { 
    $_ -replace "C:\\Users\\emachnic\\GitRepos\\railsinstaller-windows\\stage\\Ruby2.2.0\\bin\\ruby.exe", "%~dp0ruby.exe" 
} | Set-Content $_.name}

After you hit enter, you should find that all the instances of that string have been replaced. GL

edit: updated version 2.2.0 -> 2.3.0

feihcsim
  • 1,444
  • 2
  • 17
  • 33
  • 1
    this is a great solution ! Press Win + R then type "powershell" hit enter. Above code works great but current version of Ruby s 2.3.0 as I'm writing this. so proper script would be Get-ChildItem . -Filter *.bat | Foreach-Object { (Get-Content $_.name ) | ForEach-Object { $_ -replace "C:\\Users\\emachnic\\GitRepos\\railsinstaller-windows\\stage\\Ruby2.3.0\\bin\\ruby.exe", "%~dp0ruby.exe" } | Set-Content $_.name} – Nerzid Feb 15 '17 at 16:04
2

I came across this issue a couple of days ago. It seems like all of a sudden after you run Rails many times on Windows, playing with the cmd command prompt, changing the command background and text colors or opening more than one command prompt window at the same time, and then you try to run the command 'rails server' 'rails new App' or 'bundle install' you get the message "The system cannot find the path specified"

I solved that problem by running the command: 'gem install _____' (fill out that line with: 'bundle', 'bundler' and 'byebug'), which are the names of three .bat files (run that command with each .bat file name ONE AT A TIME). Once you have done that, test it! Try to create a new app, bundle install and rails server. It worked for me.

Ernie Plez
  • 21
  • 1
1

I encountered the same issue and running gem install rails in the command prompt it works.

Regards, T.S.

Paddler
  • 111
  • 4
  • 14
0

I found your question while researching the same problem earlier, and I just fixed it for myself (Windows 8.1) so I thought I would answer it. I was trying to run Ruby 2.2 on Windows 8.1 using RailsInstaller. I am now able to run Ruby and Rails, albeit an older version. I think this is a problem with 64-bit architecture versus 32-bit, the latter of which seems to run fine. Here's how I did it:

  1. First, read this blog post and see if this solves your problem, though I don't think it will. I used regedit.exe to find the AutoRun instance in question. I didn't have one, so I tried the next step.

  2. Uninstall the Ruby 2.2 version of RailsInstaller (go into your control panel > programs and features then uninstall RailsInstaller.

  3. Then, install the 1.9.3 version. Go here and CTRL+F "1.9" to find the Ruby 1.9.3 version of RailsInstaller.

  4. Once installed, make sure to run a gem update --system to update all of your gems. I had trouble running rails new until I did the gem update. Now everything works fine.

So, you'll be using a slightly older version of Ruby but everything should be working okay. This solution worked for me and I hope it works for you.

Allen
  • 55
  • 7
0

I believe the fix for the above problem is very simple.

The problem is happening because in the installation directory the batch that you have is taking default path. For e.g., let say that you are running following command: bundle install Now in order to execute this command your bundle batch file should be configured correctly. By default the batch file will have somewhat like below structure:

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

For me rails is installed in C drive : C:\RailsInstaller\Ruby2.3.0\bin hence the above bundle file should be configured something like below:

@ECHO OFF
IF NOT "%~f0" == "~f0" GOTO :WinNT
@"C:/RailsInstaller/Ruby2.3.0/bin/ruby.exe" 
"C:/RailsInstaller/Ruby2.3.0/bin/bundle" %1 %2 %3 %4 %5 %6 %7 %8 %9
GOTO :EOF
:WinNT
@"C:/RailsInstaller/Ruby2.3.0/bin/ruby.exe" "%~dpn0" %

This will solve the above problem.

The above solution should be applied whereever we face the problem running command.

Donald Duck
  • 8,409
  • 22
  • 75
  • 99