Ruby-on-rails Rails - 系统找不到指定的路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35545361/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 00:23:06  来源:igfitidea点击:

Rails - The system cannot find the path specified

ruby-on-railsrubywindows

提问by Javid Askerov

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

我已经使用 railsinstaller 在 Windows 上安装了 Rails 和 Ruby。问题是,当我运行 rails 命令时,它给了我:“系统找不到指定的路径。”

I am running windows 7 x64 and Ruby 2.20.

我正在运行 Windows 7 x64 和 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.

我尝试卸载 Rails 并重新安装;那没有帮助。Ruby 命令像 一样执行,ruby -vrails -v=不起作用。

回答by Raymond R

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

进入 C:\RailsInstaller\Ruby2.2.0。在某些 .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/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" %*

回答by Al Sweigart

This is due to a bug in RailsInstaller, where two files have the location of ruby.exehard-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.batsomewhere else if you picked a different install folder) you'll find these two lines:

这是由于 RailsInstaller 中的一个错误,其中两个文件的ruby.exe硬编码位置只能在 RailsInstaller 开发人员的机器上工作。在C:\RailsInstaller\Ruby2.2.0\bin\rails.bat(这是默认的安装文件夹,rails.bat如果您选择不同的安装文件夹,您可能还有其他地方)您会找到这两行:

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

emachnic 用户是 RailsInstaller 开发人员。作为解决方法,您可以将这些文件夹更改为您计算机上的文件夹。对于默认安装文件夹,您可以将这些更改为:

@"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.batas well.

您还必须对两个相似的行重复此更改C:\RailsInstaller\Ruby2.2.0\bin\bundle.bat

Run rails -vto verify that rails is now working.

运行rails -v以验证 rails 现在是否正常工作。

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

你可以在他们的 git repo 上关注这个问题:https: //github.com/railsinstaller/railsinstaller-windows/issues/70

回答by Javid Askerov

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

解决方案是在 railsinstaller 的 github 问题上指定的 - https://github.com/railsinstaller/railsinstaller-windows/issues/73

回答by Jayant Bhawal

I opened all the .batfiles under C:\RailsInstaller\Ruby2.2.0\binin Sublime Text, and replaced with Ctrl+Shift+F,

我在Sublime Text 中打开C:\RailsInstaller\Ruby2.2.0\bin.bat下的所有文件,并替换为,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.


@"C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe"
与此
@"%~dp0ruby.exe"
匹配的所有文件。

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.

只用了几秒钟。这可能会帮助那些在我之后偶然发现它并且对在多个文件上执行查找和替换的想法感到畏惧的人。

回答by Serge_k

I solved this problem on my windows machine by doing

我通过做在我的 Windows 机器上解决了这个问题

  1. gem install bundler
  2. bundler install
  3. Number 1 and 2 fixed the problem and installed all gems.
  1. 宝石安装捆绑器
  2. 捆绑安装
  3. 1 号和 2 号修复了问题并安装了所有 gem。

回答by feihcsim

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.exewith %~dp0ruby.exein the .bat files. Just open up Powershell, cd to C:\RailsInstaller\Ruby2.3.0\bin, and copy this small script:

我已经创建了一个超级简单的方法来使用Windows Powershell来执行@JayantBhawal 的解决方案(对我来说非常好),你们都应该拥有它,因为这似乎是 Windows 机器独有的问题。看起来比较复杂,但真正意义它做的是替换的所有实例C:\Users\emachnic\GitRepos\railsinstaller-windows\stage\Ruby2.2.0\bin\ruby.exe%~dp0ruby.exe在.bat文件。只需打开 Powershell,cd 到C:\RailsInstaller\Ruby2.3.0\bin,然后复制这个小脚本:

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

按 Enter 键后,您应该会发现该字符串的所有实例都已被替换。GL

edit: updated version 2.2.0 -> 2.3.0

编辑:更新版本 2.2.0 -> 2.3.0

回答by Ernie Plez

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"

几天前我遇到了这个问题。在 Windows 上运行 Rails 很多次之后,突然之间,使用 cmd 命令提示符,更改命令背景和文本颜色或同时打开多个命令提示符窗口,然后尝试运行命令 'rails server' 'rails new App' 或 'bundle install' 您会收到消息“系统找不到指定的路径”

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.

我通过运行以下命令解决了这个问题:'gem install _____'(用:'bundle'、'bundler' 和 'byebug' 填写该行),它们是三个 .bat 文件的名称(用每个 .bat 运行该命令)。 bat 文件名一次)。完成后,测试一下!尝试创建一个新的应用程序,捆绑安装和 Rails 服务器。它对我有用。

回答by Paddler

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

我遇到了同样的问题并gem install rails在命令提示符下运行它可以工作。

Regards, T.S.

问候, TS

回答by Pranjal Prakash Srivastava

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 installNow 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:

出现问题是因为在安装目录中,您拥有的批处理采用默认路径。例如,假设您正在运行以下命令: bundle install现在为了执行此命令,您的捆绑批处理文件应该正确配置。默认情况下,批处理文件的结构类似于以下结构:

@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 Cdrive : C:\RailsInstaller\Ruby2.3.0\binhence the above bundle file should be configured something like below:

对我来说,rails 安装在C盘:C:\RailsInstaller\Ruby2.3.​​0\bin因此上面的包文件应该配置如下:

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

上面的解决方案应该适用于我们在运行命令时遇到问题的任何地方。

回答by Allen

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:

我之前在研究同一问题时发现了您的问题,我只是为自己(Windows 8.1)修复了它,所以我想我会回答它。我试图使用 RailsInstaller 在 Windows 8.1 上运行 Ruby 2.2。我现在可以运行 Ruby 和 Rails,尽管是旧版本。我认为这是 64 位架构与 32 位架构的问题,后者似乎运行良好。这是我如何做到的:

  1. First, read this blog postand see if this solves your problem, though I don't think it will. I used regedit.exeto 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 featuresthen uninstall RailsInstaller.

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

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

  1. 首先,阅读这篇博文,看看这是否能解决您的问题,尽管我认为不会。我曾经regedit.exe找到有问题的 AutoRun 实例。我没有,所以我尝试了下一步。

  2. 卸载 Ruby 2.2 版本的 RailsInstaller(进入control panel>programs and features然后卸载RailsInstaller.

  3. 然后,安装 1.9.3 版本。转到此处并按 CTRL+F "1.9" 找到 RailsInstaller 的 Ruby 1.9.3 版本。

  4. 安装后,请确保运行 agem update --system来更新您的所有 gem。在进行rails newgem 更新之前,我一直无法运行。现在一切正常。

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.

因此,您将使用稍旧版本的 Ruby,但一切都应该正常。这个解决方案对我有用,我希望它对你有用。