没有要加载的文件 -- ruby​​gems (LoadError)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2896485/
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-02 22:41:57  来源:igfitidea点击:

no such file to load -- rubygems (LoadError)

ruby-on-railsrubyrubygems

提问by Vineeth Pradhan

I recently installed rails in fedora 12. I'm new to linux as well. Everything works fine on Windows 7. But I'm facing lot of problems in linux. Help please!

我最近在 Fedora 12 中安装了 rails。我也是 linux 新手。在 Windows 7 上一切正常。但我在 linux 中面临很多问题。请帮忙!

I've installed all the essentials to my knowledge to get the basic script/server up and running. I have this error from boot.rb popping up when I try script/server. Some of the details I'd like to give here:

我已经根据我的知识安装了所有必需品,以使基本脚本/服务器启动并运行。当我尝试脚本/服务器时,我从 boot.rb 弹出这个错误。我想在这里提供的一些细节:

The directories where rails, ruby and gem are installed,

安装 rails、ruby 和 gem 的目录,

[vineeth@localhost my_app]$ which ruby
/usr/local/bin/ruby

[vineeth@localhost my_app]$ which rails
/usr/bin/rails

[vineeth@localhost my_app]$ which gem
/usr/bin/gem

And when I run the script/server, this is the error.

当我运行脚本/服务器时,这是错误。

[vineeth@localhost my_app]$ script/server
./script/../config/boot.rb:9:in `require': no such file to load -- rubygems (LoadError)
 from ./script/../config/boot.rb:9
 from script/server:2:in `require'
 from script/server:2

And the PATH file looks like this

PATH 文件看起来像这样

[vineeth@localhost my_app]$ cat ~/.bash_profile
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
 . ~/.bashrc
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

export PATH="/usr/local/bin:/usr/local/sbin:/usr/bin/ruby:$PATH"

I suppose it is something to do with the PATH file. Let me know what I need to change here. If there are other changes I should make, please let me know.

我想这与 PATH 文件有关。让我知道我需要在这里改变什么。如果我应该做其他更改,请告诉我。

回答by Eimantas

I have a hunch that you have two ruby versions. Please paste the output of following command:

我有一种预感,你有两个 ruby​​ 版本。请粘贴以下命令的输出:

$ which -a ruby

updated regarding to the comment:

关于评论的更新:

Nuke one version and leave only one. I had same problem with two versions looking at different locations for gems. Had me going crazy for few weeks. Put up a bounty here at SO got me same answer I'm giving to you.

核弹一个版本,只留下一个。我有两个版本在不同位置寻找宝石时遇到同样的问题。让我疯狂了几个星期。在 SO 上悬赏赏金给了我同样的答案。

All I did was nuke one installation of ruby and left the one managable via ports. I'd suggest doing this:

我所做的只是安装了一个 ruby​​,然后通过端口留下了一个可管理的安装。我建议这样做:

  1. Remove ruby version installed via ports (yum or whatever package manager).
  2. Remove ruby version that came with OS (hardcore rm by hand).
  3. Install ruby version from ports with different prefix (/usrinstead of /usr/local)
  4. Reinstall rubygems
  1. 删除通过端口安装的 ruby​​ 版本(yum 或任何包管理器)。
  2. 删除操作系统附带的 ruby​​ 版本(手动硬核 rm)。
  3. 从具有不同前缀(/usr而不是/usr/local)的端口安装 ruby​​ 版本
  4. 重新安装 rubygems

回答by Daniel Thomas - drt24

I had a similar problem on Ubuntu due to having multiple copies of ruby installed. (1.8 and 1.9.1) Unfortunately I need both of them. The solution is to use:

由于安装了多个 ruby​​ 副本,我在 Ubuntu 上遇到了类似的问题。(1.8 和 1.9.1) 不幸的是我需要它们。解决方法是使用:

$ sudo update-alternatives --config ruby
There are 2 choices for the alternative ruby (providing /usr/bin/ruby).

  Selection    Path                Priority   Status
------------------------------------------------------------
* 0            /usr/bin/ruby1.8     50        auto mode
  1            /usr/bin/ruby1.8     50        manual mode
  2            /usr/bin/ruby1.9.1   10        manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/bin/ruby1.9.1 to provide /usr/bin/ruby (ruby) in manual mode.

After doing that bundle install succeeded.

完成捆绑安装成功后。

回答by Brian Moeskau

OK, I am a Ruby noob, but I did get this fixed slightly differently than the answers here, so hopefully this helps someone else (tl;dr: I used RVM to switch the system Ruby version to the same one expected by rubygems).

好的,我是一个 Ruby 菜鸟,但我确实解决了这个问题,与这里的答案略有不同,所以希望这可以帮助其他人(tl; dr:我使用 RVM 将系统 Ruby 版本切换到 ruby​​gems 期望的相同版本)。

First off, listing all Rubies as mentioned by Eimantaswas a great starting point:

首先,列出Eimantas提到的所有Ruby是一个很好的起点:

> which -a ruby
/opt/local/bin/ruby
/Users/Brian/.rvm/rubies/ruby-1.9.2-p290/bin/ruby
/Users/Brian/.rvm/bin/ruby
/usr/bin/ruby
/opt/local/bin/ruby

The default Ruby instance in use by the system appeared to be 1.8.7:

系统使用的默认 Ruby 实例似乎是 1.8.7:

> ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin10]

while the version in use by Rubygems was the 1.9.2 version managed by RVM:

而 Rubygems 使用的版本是由 RVM 管理的 1.9.2 版本:

> gem env | grep 'RUBY EXECUTABLE'
  - RUBY EXECUTABLE: /Users/Brian/.rvm/rubies/ruby-1.9.2-p290/bin/ruby

So that was definitely the issue. I don't actively use Ruby myself (this is simply a dependency of a build system script I'm trying to run) so I didn't care which version was active for other purposes. Since rubygems expected the 1.9.2 that was already managed by RVM, I simply used RVM to switch the system to use the 1.9.2 version as the default:

所以这绝对是问题所在。我自己并没有主动使用 Ruby(这只是我试图运行的构建系统脚本的一个依赖项),所以我不在乎哪个版本是用于其他目的的。由于rubygems期望的是已经由RVM管理的1.9.2,所以我简单地使用RVM切换系统以使用1.9.2版本作为默认:

> rvm use 1.9.2
Using /Users/Brian/.rvm/gems/ruby-1.9.2-p290

> ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.3.0]

After doing that my "no such file" issue went away and my script started working.

这样做之后,我的“没有这样的文件”问题消失了,我的脚本开始工作。

回答by miguelcobain

I would just like to add that in my case rubygemswasn't installed.

我只想补充一点,在我的情况下rubygems没有安装。

Running sudo apt-get install rubygemssolved the issue!

运行sudo apt-get install rubygems解决了这个问题!

回答by ohho

Try starting the project with:

尝试使用以下命令启动项目:

./script/server

instead of script/serverif you are using ruby 1.9.2 (from strange inability to require config/boot after upgrading to ruby 1.9.2)

而不是script/server如果您使用的是 ruby​​ 1.9.2(因为在升级到 ruby​​ 1.9.2 后奇怪地无法要求配置/启动

回答by Andrew Kvochick

In case anyone else is googling this problem: I was able to fix mine by finding the elusive "rubygems" folder that I wanted to use and adding it to my $RUBYLIB environment variable.

万一其他人在谷歌上搜索这个问题:我能够通过找到我想要使用的难以捉摸的“rubygems”文件夹并将其添加到我的 $RUBYLIB 环境变量中来修复我的问题。

find / -name "rubygems" -print

Once you find it, add the parent directory to your environment. In bash, like so:

找到后,将父目录添加到您的环境中。在 bash 中,像这样:

export RUBYLIB=/path/to/parent

Now if you run gem, it should pick up the right library directory, and you're off and running.

现在,如果您运行 gem,它应该会选择正确的库目录,然后您就可以开始运行了。

回答by ftravers

I had a similar problem, simply running a trivial ruby script that just required the gem i wanted...got that error message. When I changed the incantation from:

我有一个类似的问题,只是运行一个简单的 ruby​​ 脚本,它只需要我想要的 gem……得到那个错误消息。当我改变咒语时:

ruby test.rb

to

ruby -rubygems test.rb

Seemed to work.

似乎工作。

回答by RobisonSantos

I had a similar problem and solved that by setting up RUBYLIB env.

我有一个类似的问题,并通过设置 RUBYLIB env 解决了这个问题。

In my environment I used this:

在我的环境中,我使用了这个:

export RUBYLIB=$ruby_dir/lib/ruby/1.9.1/:$ruby_dir/lib/ruby/1.9.1/i686-linux/:$RUBYLIB

回答by cande

If you have several ruby installed, it might be sufficient just to remove one of them, on MacosX with extra ports install, remove the ports ruby installation with:

如果您安装了多个 ruby​​,只需删除其中一个就足够了,在安装了额外端口的 MacosX 上,使用以下命令删除端口 ruby​​ 安装:

sudo port -f uninstall ruby

回答by datnt

I also had this issue. My solution is remove file Gemfile.lock, and install gems again: bundle install

我也有这个问题。我的解决方案是删除文件 Gemfile.lock,然后再次安装 gems:bundle install