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.
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:
- Remove ruby version installed via ports (yum or whatever package manager).
- Remove ruby version that came with OS (hardcore rm by hand).
- Install ruby version from ports with different prefix (
/usr
instead of/usr/local
) - Reinstall
rubygems
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.
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.
I would just like to add that in my case rubygems
wasn't installed.
Running sudo apt-get install rubygems
solved the issue!
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)
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.
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.
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
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 also had this issue. My solution is remove file Gemfile.lock, and install gems again: bundle install
gem install bundler
fixed the issue for me.
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 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
Simply running /bin/bash --login
did the trick for me, weirdly. Can't explain it.
精彩评论