[ruby-on-rails] no such file to load -- rubygems (LoadError)

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.

This question is related to ruby-on-rails ruby rubygems

The answer is


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

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


gem install bundler

fixed the issue for me.


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

Running sudo apt-get install rubygems solved the issue!


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.


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


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

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.


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'

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


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.


Try starting the project with:

./script/server

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


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.


Examples related to ruby-on-rails

Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Where do I put a single filter that filters methods in two controllers in Rails Empty brackets '[]' appearing when using .where How to integrate Dart into a Rails app Rails 2.3.4 Persisting Model on Validation Failure How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? Rails: Can't verify CSRF token authenticity when making a POST request Uncaught ReferenceError: React is not defined

Examples related to ruby

Uninitialized Constant MessagesController Embed ruby within URL : Middleman Blog Titlecase all entries into a form_for text field Ruby - ignore "exit" in code Empty brackets '[]' appearing when using .where find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) How to update Ruby Version 2.0.0 to the latest version in Mac OSX Yosemite? How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting Is the server running on host "localhost" (::1) and accepting TCP/IP connections on port 5432? How to update Ruby with Homebrew?

Examples related to rubygems

You don't have write permissions for the /Library/Ruby/Gems/2.3.0 directory. (mac user) find_spec_for_exe': can't find gem bundler (>= 0.a) (Gem::GemNotFoundException) How to fix "Your Ruby version is 2.3.0, but your Gemfile specified 2.2.5" while server starting You don't have write permissions for the /var/lib/gems/2.3.0 directory Can't install gems on OS X "El Capitan" How to avoid "cannot load such file -- utils/popen" from homebrew on OSX How can I set a proxy server for gem? How to install CocoaPods? Error while installing json gem 'mkmf.rb can't find header files for ruby' How to downgrade or install an older version of Cocoapods