no such file to load -- rubygems (LoadError)

Ruby on-RailsRubyRubygems

Ruby on-Rails Problem Overview


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!

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:

The directories where rails, ruby and gem are installed,

[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

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

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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

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

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

  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 (/usr instead of /usr/local)
  4. Reinstall rubygems

Solution 2 - Ruby on-Rails

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:

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

Solution 3 - Ruby on-Rails

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

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

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

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

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

Solution 4 - Ruby on-Rails

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

Running sudo apt-get install rubygems solved the issue!

Solution 5 - Ruby on-Rails

Try starting the project with:

./script/server

instead of script/server if you are using ruby 1.9.2 (from https://stackoverflow.com/questions/3865515/strange-inability-to-require-config-boot-after-upgrading-to-ruby-1-9-2/6047615#6047615)

Solution 6 - Ruby on-Rails

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.

find / -name "rubygems" -print

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

export RUBYLIB=/path/to/parent

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

Solution 7 - Ruby on-Rails

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 test.rb

to

ruby -rubygems test.rb

Seemed to work.

Solution 8 - Ruby on-Rails

I had a similar problem and solved that by setting up 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

Solution 9 - Ruby on-Rails

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:

sudo port -f uninstall ruby

Solution 10 - Ruby on-Rails

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

Solution 11 - Ruby on-Rails

gem install bundler

fixed the issue for me.

Solution 12 - Ruby on-Rails

This is the first answer when Googling 'require': cannot load such file -- ubygems (LoadError) after Google autocorrected "ubygems" to "rubygems". Turns out this was an intentional change between Ruby 2.4 and 2.5 (Bug #14322). Scripts that detect the user gems directory without taking into account the ruby version will most likely fail.

Ruby 2.4

ruby -rubygems -e 'puts Gem.user_dir'

Ruby 2.5

ruby -rrubygems -e 'puts Gem.user_dir'

Solution 13 - Ruby on-Rails

I have also met the same problem using rbenv + passenger + nginx. my solution is simply adding these 2 line of code to your nginx config:

passenger_default_user root;
passenger_default_group root;

the detailed answer is here: https://stackoverflow.com/a/15777738/445908

Solution 14 - Ruby on-Rails

Simply running /bin/bash --login did the trick for me, weirdly. Can't explain it.

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
QuestionVineeth PradhanView Question on Stackoverflow
Solution 1 - Ruby on-RailsEimantasView Answer on Stackoverflow
Solution 2 - Ruby on-RailsDaniel Thomas - drt24View Answer on Stackoverflow
Solution 3 - Ruby on-RailsBrian MoeskauView Answer on Stackoverflow
Solution 4 - Ruby on-RailsmiguelcobainView Answer on Stackoverflow
Solution 5 - Ruby on-RailsohhoView Answer on Stackoverflow
Solution 6 - Ruby on-RailsAndrew KvochickView Answer on Stackoverflow
Solution 7 - Ruby on-RailsftraversView Answer on Stackoverflow
Solution 8 - Ruby on-RailsRobisonSantosView Answer on Stackoverflow
Solution 9 - Ruby on-RailscandeView Answer on Stackoverflow
Solution 10 - Ruby on-RailsdatntView Answer on Stackoverflow
Solution 11 - Ruby on-RailsGagan GamiView Answer on Stackoverflow
Solution 12 - Ruby on-RailsNice Guy ITView Answer on Stackoverflow
Solution 13 - Ruby on-RailsSiweiView Answer on Stackoverflow
Solution 14 - Ruby on-Railstemporary_user_nameView Answer on Stackoverflow