Rails - The system cannot find the path specified

Ruby on-RailsRubyWindows

Ruby on-Rails Problem Overview


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.

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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" %*

Solution 2 - Ruby on-Rails

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

Solution 3 - Ruby on-Rails

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

Solution 4 - Ruby on-Rails

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.

Solution 5 - Ruby on-Rails

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.

Solution 6 - Ruby on-Rails

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

Solution 7 - Ruby on-Rails

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.

Solution 8 - Ruby on-Rails

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

Regards, T.S.

Solution 9 - Ruby on-Rails

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.

Solution 10 - Ruby on-Rails

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.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJavid AskerovView Question on Stackoverflow
Solution 1 - Ruby on-RailsRaymond RView Answer on Stackoverflow
Solution 2 - Ruby on-RailsAl SweigartView Answer on Stackoverflow
Solution 3 - Ruby on-RailsJavid AskerovView Answer on Stackoverflow
Solution 4 - Ruby on-RailsJayant BhawalView Answer on Stackoverflow
Solution 5 - Ruby on-RailsSerge_kView Answer on Stackoverflow
Solution 6 - Ruby on-RailsfeihcsimView Answer on Stackoverflow
Solution 7 - Ruby on-RailsErnie PlezView Answer on Stackoverflow
Solution 8 - Ruby on-RailsPaddlerView Answer on Stackoverflow
Solution 9 - Ruby on-RailsAllenView Answer on Stackoverflow
Solution 10 - Ruby on-RailsPranjal Prakash SrivastavaView Answer on Stackoverflow