简体   繁体   English

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

[英]Rails - The system cannot find the path specified

I have installed Rails and Ruby on Windows with railsinstaller.我已经使用 railsinstaller 在 Windows 上安装了 Rails 和 Ruby。 The problem is, when I run the rails command, it gives me: "The system cannot find the path specified."问题是,当我运行 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;我尝试卸载 Rails 并重新安装; that does not help.那没有帮助。 Ruby commands execute, like ruby -v , but rails -v= dont work. Ruby 命令可以执行,就像ruby -v ,但是rails -v=不起作用。

Go into C:\\RailsInstaller\\Ruby2.2.0.进入 C:\\RailsInstaller\\Ruby2.2.0。 In some of the .bat files, you'll find the following:在某些 .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" %*

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.这是由于 RailsInstaller 中的一个错误,其中两个文件的ruby.exe位置ruby.exe硬编码为仅在 RailsInstaller 开发人员的机器上工作。 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:\\RailsInstaller\\Ruby2.2.0\\bin\\rails.bat (这是默认的安装文件夹,如果你选择不同的安装文件夹,你可能在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. emachnic 用户是 RailsInstaller 开发人员。 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.您还必须对C:\\RailsInstaller\\Ruby2.2.0\\bin\\bundle.bat两个类似行重复此更改。

Run rails -v to 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

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

I opened all the .bat files under C:\\RailsInstaller\\Ruby2.2.0\\bin in 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.在所有匹配的文件中。

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.这可能会帮助那些在我之后偶然发现它并且对在多个文件上执行查找和替换的想法感到畏惧的人。

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 号修复了问题并安装了所有 gem。

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.我已经创建了一个超级简单的方法来使用Windows Powershell来执行@JayantBhawal 的解决方案(对我来说非常好),你们都应该拥有它,因为这似乎是 Windows 机器独有的问题。 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.它看起来很复杂,但实际上它所做的只是用 .bat 文件中的%~dp0ruby.exe替换C:\\Users\\emachnic\\GitRepos\\railsinstaller-windows\\stage\\Ruby2.2.0\\bin\\ruby.exe所有实例。 Just open up Powershell, cd to C:\\RailsInstaller\\Ruby2.3.0\\bin , and copy this small script:只需打开 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.按 Enter 键后,您应该会发现该字符串的所有实例都已被替换。 GL GL

edit: updated version 2.2.0 -> 2.3.0编辑:更新版本 2.2.0 -> 2.3.0

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).我通过运行以下命令解决了这个问题:'gem install _____'(用:'bundle'、'bundler' 和 'byebug' 填写该行),它们是三个 .bat 文件的名称(在每个 .bat 文件中运行该命令)。 bat 文件名一次)。 Once you have done that, test it!完成后,测试一下! Try to create a new app, bundle install and rails server.尝试创建一个新的应用程序,捆绑安装和 rails 服务器。 It worked for me.它对我有用。

I encountered the same issue and running gem install rails in the command prompt it works.我遇到了同样的问题,并在命令提示符下运行gem install rails它可以工作。

Regards, TS问候, TS

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.我之前在研究同一问题时发现了您的问题,我只是为自己修复了它(Windows 8.1),所以我想我会回答它。 I was trying to run Ruby 2.2 on Windows 8.1 using RailsInstaller.我试图使用 RailsInstaller 在 Windows 8.1 上运行 Ruby 2.2。 I am now able to run Ruby and Rails, albeit an older version.我现在可以运行 Ruby 和 Rails,尽管是旧版本。 I think this is a problem with 64-bit architecture versus 32-bit, the latter of which seems to run fine.我认为这是 64 位架构与 32 位架构的问题,后者似乎运行良好。 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.我使用regedit.exe来查找有问题的 AutoRun 实例。 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 .卸载 RailsInstaller 的 Ruby 2.2 版本(进入您的control panel > programs and features然后卸载RailsInstaller

  3. Then, install the 1.9.3 version.然后,安装 1.9.3 版本。 Go here and CTRL+F "1.9" to find the Ruby 1.9.3 version of RailsInstaller.转到此处并按 CTRL+F "1.9" 找到 RailsInstaller 的 Ruby 1.9.3 版本。

  4. Once installed, make sure to run a gem update --system to update all of your gems.安装后,请确保运行gem update --system来更新所有 gem。 I had trouble running rails new until I did the gem update.在我进行 gem 更新之前,我在运行rails new遇到了麻烦。 Now everything works fine.现在一切正常。

So, you'll be using a slightly older version of Ruby but everything should be working okay.因此,您将使用稍旧版本的 Ruby,但一切都应该正常。 This solution worked for me and I hope it works for you.这个解决方案对我有用,我希望它对你有用。

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 eg, 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.例如,假设您正在运行以下命令: bundle install现在为了执行此命令,您的捆绑批处理文件应该正确配置。 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:对我来说,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.上面的解决方案应该适用于我们在运行命令时遇到问题的任何地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM