Rubygems. LoadError in Rails - ruby-on-rails

Everytime I start my Rails applications I get LoadError with the following output.
On Rails 2.3.8:
no such file to load -- sqlite3/sqlite3_native
<internal:lib/rubygems/custom_require>:29:in `require'
On Rails 3.0.0:
no such file to load -- bundler
<internal:lib/rubygems/custom_require>:29:in `require'
I run the applications in the production mode on a development machine using Nginx + Passenger.
What is the reason of this issue? How can I solve it?
Thanks.
Debian GNU/Linux 5.0.6;
Ruby 1.9.2;
Rubygems 1.3.7;
Ruby on Rails 2.3.8, 3.0.0;
Nginx 0.8.50;
Passenger 2.2.15;
sqlite3-ruby 1.3.1;
bundler 1.0.0.rc.6.
Updated
All of my gems is installed by the unprivileged user in the local directory /home/<usernam>/.gem. If it helps, here's the gem env output:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-08-18 patchlevel 0) [i686-linux]
- INSTALLATION DIRECTORY: /home/<username>/.gem
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /home/<username>/.gem/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /home/<username>/.gem
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-ri --no-rdoc"
- :gemhome => "/home/<username>/.gem"
- :gempath => ["/home/<username>/.gem"]
- REMOTE SOURCES:
- http://rubygems.org/
Updated
I tackled with the problem. Its source was that I defined a custom gem path. That is I added to the ~/.gemrc file the following lines:
:gemhome: /home/<username>/.gem
:gempaths:
- /home/<username>/.gem
Thus all of my gems was placed in the specified directory but not the default one. For some reason Rubygems coundn't find it there and rose an exception.
When I removed that lines from the file the default paths was set for Rubygems and after I installed all the required gems and loaded my Rails applications all began to work.
Once again, the bug conditions are:
Nginx + Passenger;
The gempath is set to /home/<unprivileged_user>/.gem in ~/.gemrc;
An init.d script is creaded and added to the boot sequence (update-rc.d nginx defaults);
System is rebooted, server is started atomaticlally;
http://localhost/my_rails_app;
LoadError; no such file to load -- <gem_name>; <internal:lib/rubygems/custom_require>:29:in `require'.
Why can't Rubygems find gems in the custom location but can find them in default? That's the question.

I too had this problem when using RVM - I must have specified a gemset or something and not made it project specific. At any rate, read this rvm guide if you want to know the basics of RVM and try to specify a new gemset for your current folder / project, install a new rails gem to that gemset, and then use that gemset. For example, to create a new gemset for rails version 2.3.8:
$ rvm gemset create rails238
$ rvm ruby-1.8.7#rails238
$ gem install rails -v 2.3.8
Then if all went according to plan type rvm gemset use [gemsetName], or do rvm gemset list to see a list of installed gemsets, and to see if rails is working fine try rails -v and you should see rails 2.3.8

Check your system to locate where your rubies and gems are installed ( you can do this by "which ruby" and "which gem"). Usually, they're installed in the same folder (/usr/bin or /usr/local). If they are in different locations, there might be load error. Just a suggestion.

Related

Debian Passenger error: cannot load such file -- bundler (LoadError)

I am running Apache on my Raspberry Pi (Raspbian) and struggling to get Passenger working properly with my site. When I go to visit my site (which is set up as a VirtualHost), I get the error: "cannot load such file -- bundler". The first line of the backtrace is
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb
To install Passenger, I followed the instructions here: http://www.modrails.com/documentation/Users%20guide%20Apache.html#install_on_debian_ubuntu.
In particular, I ran the command
sudo apt-get install libapache2-mod-passenger
This link says, "The Apache package provides configuration snippets for you, so you don’t need to modify any Apache configuration to get it to load Phusion Passenger". The way the installation went on my machine was that it automatically added and enabled the passenger module through the files "passenger.conf" and "passenger.load":
passenger.conf:
<IfModule mod_passenger.c>
PassengerRoot /usr
PassengerRuby /usr/bin/ruby
</IfModule>
passenger.load:
LoadModule passenger_module /usr/lib/apache2/modules/mod_passenger.so
Running "gem env" gives me the following output:
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.7
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [armv6l-linux-eabihf]
- INSTALLATION DIRECTORY: /home/user/.rvm/gems/ruby-2.0.0-p247
- RUBY EXECUTABLE: /home/user/.rvm/rubies/ruby-2.0.0-p247/bin/ruby
- EXECUTABLE DIRECTORY: /home/user/.rvm/gems/ruby-2.0.0-p247/bin
- RUBYGEMS PLATFORMS:
- ruby
- armv6l-linux
- GEM PATHS:
- /home/user/.rvm/gems/ruby-2.0.0-p247
- /home/user/.rvm/gems/ruby-2.0.0-p247#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
I tried looking all over for a mod_passenger.so file elsewhere in the file system with no luck. I am reluctant to simply reinstall rails or passenger because I am unsure what the implications will be for the modules and configuration. Any advice is appreciated, thanks!
Maybe you didn't configure your app to use Ruby 2.0.0? If you don't do that explicitly, it will use the default Ruby, which is /usr/bin/ruby. This section from the manual tells you how to specify a different Ruby: http://www.modrails.com/documentation/Users%20guide%20Apache.html#PassengerRuby
Note that multiple Ruby supports requires Phusion Passenger >= 4.0.0.
The problem ended up being that I needed to set the environment variable for the GEM_PATH within a .htaccess file!

Syntax error when creating a Rails model

I am creating Car model in Rails 3 by using command:
rails generate model Car name:string id_str:string
but I got the error:
/home/XX/.rvm/gems/ruby-1.9.2-p290/gems/activesupport-3.1.1/lib/active_support/dependencies.rb:234:in `load': /home/XX/myapp/config/initializers/session_store.rb:3: syntax error, unexpected ':', expecting $end (SyntaxError)
...sion_store :cookie_store, key: '_myapp_session'
why?
my session_store.rb
Myapp::Application.config.session_store :cookie_store, key: '_myapp_session'
What's wrong with my session_store.rb?
This error usually happens when you are trying to use the Ruby 1.9.2 Hash syntax with Ruby < 1.9.
In Ruby 1.9.2 the following code works perfectly
Myapp::Application.config.session_store :cookie_store, key: '_myapp_session'
while in Ruby < 1.9 you must use
Myapp::Application.config.session_store :cookie_store, :key => '_myapp_session'
This is strange, because your stack trace references Ruby 1.9.2. Are you sure you are running the generator with Ruby 1.9.2?
In any case, you can convert your session_store.rb file to the hash-rocket syntax. If it works, it means you are not using Ruby 1.9.2 and you pasted an invalid error message.
Well through a bit of debugging and playing around, this is what I ended up doing:
for x in `gem list --no-versions`; do sudo gem uninstall $x; done
This forces all 'old' gems to be removed. I then proceeded to verify the gem environment to confirm that gem was using the correct ruby version:
sudo gem env
The error experienced is due to the fact that rails is still trying to use ruby 1.8, which causes all sorts of issues.
Once all of the above checks out properly do:
sudo gem update --system
sudo gem install rubygems-update
sudo update_rubygems
Which will make sure that you are at the latest gem version. Then:
sudo gem install rails
This will install everything you need. I ran all of the gem commands as sudo, to make sure that my root install was properly configured/setup.
Your final gem env should look something like:
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.13
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-darwin10.8.0]
- INSTALLATION DIRECTORY: /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /usr/local/Cellar/ruby/1.9.3-p0/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/Cellar/ruby/1.9.3-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /usr/local/Cellar/ruby/1.9.3-p0/lib/ruby/gems/1.9.1
TL;DR: uninstall then reinstall the railties gem
Long answer:
In your project directory, if you type in which rails, what do you see? On mine, I saw /usr/bin/rails. This gave me a clue that it's using the wrong rails executable. If I look at my $PATH, I can see that RVM's bin path (/Users/ramon/.rvm/gems/ruby-1.9.3-p194/bin) did not contain the rails file (as to how this got deleted -- I don't have a clue). That must have been why the /usr/bin/rails got picked up by my system instead.
Looking at the Rails source, I saw that the railties gem has the rails bin file. I uninstalled railties (gem uninstall railties), then reinstalled it again. Voila - which rails shows /Users/ramon/.rvm/gems/ruby-1.9.3-p194/bin/rails
I was able to resolve this by adding an .rvmrc file to my application.
echo "rvm ruby-2.0.0#rails32 --create" > .rvmrc
I resolved this by deleting my ~/.rvm directory and reinstalling RVM.
really strange question as error is self decribing
you have some mess in this file, and missing end statement
`load': /home/XX/myapp/config/initializers/session_store.rb:3

Command Not Found even after changing path variable

Using heroku for deployment while learning Rails with the Ruby On Rails tutorial by Michael Hartl, on Ubuntu 11.04 Natty Narwhal. I installed it using
sudo gem install heroku
and the commands seemed to run fine for that session in the terminal. The next time I went to work, I tried the command "heroku open" and I was told "heroku: command not found". Looking at some of the answers to similar problems here, it seemed the answer was to run
gem enviroment
which returned the following:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.8
- RUBY EXECUTABLE: /usr/bin/ruby1.8
- EXECUTABLE DIRECTORY: /var/lib/gems/1.8/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-linux
- GEM PATHS:
- /var/lib/gems/1.8
- /home/richard/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
I then ran
$ export PATH=$PATH:/var/lib/gems/1.8/bin
which seemed to fix the problem. However, the next time I tried to run heroku in the terminal, I was told "command not found" again! Running the "export PATH=$PATH" command seems to fix the problem every time, but I would rather I didn't have to run this command everytime I want to use heroku. Is there any permanent solution to the problem?
If you're using bash as your shell, then add that export line to .bash_profile in your home directory. The equivalent for zsh is .zshrc, and other shells have their own files to automatically load for every shell session.

Problems getting Rails running on Mac OSX Snow Leopard

Update and Solution
I finally got everything working after
1. Uninstalling everything ruby-related in /usr/local/... as well as uninstalling all versions of rails.
2. Installing RVM as a standard user -> i.e. installed in my home directory and NOT in /usr/local as root
3. rvm install 1.8.7 and set as default
Now everything seems to be working fine.
My conclusion after days of googling and reading about others' solutions is that Snow Leopard just doesn't handle the rails dev environment well unless you sandbox it through RVM in a local director. I resisted going to RVM because I don't have a need to manage multiple ruby versions.
Some of the responses below along with my code excerpts on pastie may provide some helpful advice for others trying to troubleshoot. In particular from #fl00r and #Kelvin:
run which -a for gem, bundle, rails, rake, etc. to see the available versions. Check to see which versions of ruby are being called with head -1 on each.
Original Below
Pretty much at my wit's end after a few days of Googling, uninstalling, and re-installing. I'm trying to get rails running on Mac OS X 10.6.7. I followed the Hivelogic Post on this topic. Apologize for the length of this question.
Has anyone followed a step-by-step uninstall/reinstall process for getting this working? Or a link to advice on troubleshooting? Should I clean out everything following this advice from Chad Wooley and migrate to RVM?
The common theme has been errors related to being unable to find gems even though they are installed. For instance, trying to create a new rails app:
kevindewalt#new-host-4:~/Documents$ $ rails new blog
You don't have i18n installed in your application. Please add it to your Gemfile and run bundle install
Or an existing app I have running on another machine after running bundle install:
kevindewalt#new-host-4:~/Documents/ClaimAway$ (master) $ rake db:setup
(in /Users/kevindewalt/Documents/ClaimAway)
Could not find i18n-0.4.2 in any of the sources
Try running `bundle install`.
kevindewalt#new-host-4:~/Documents/ClaimAway$ (master) $ rails s
/usr/local/lib/ruby/gems/1.8/gems/actionpack-3.0.0/lib/action_dispatch.rb:35:in `require': no such file to load --
-
kevindewalt#new-host-4:~/Documents$ $ gem env
RubyGems Environment:
- RUBYGEMS VERSION: 1.7.2
- RUBY VERSION: 1.8.7 (2009-06-12 patchlevel 174) [i686-darwin10.7.0]
- INSTALLATION DIRECTORY: /usr/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /usr/local/lib/ruby/gems/1.8
- /Users/kevindewalt/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
-
kevindewalt#new-host-4:~/Documents$ $ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/opt/local/bin:/opt/local/sbin:/usr/local/git/bin:/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin
-
kevindewalt#new-host-4:~/Documents$ $ which -a ruby
/usr/local/bin/ruby
/usr/local/bin/ruby
/usr/bin/ruby
/usr/local/bin/ruby
add to Gemfile
gem 'i18n'
Actually you should specify exact version also:
gem 'i18n', '0.4.2'
then run bundle install. But as far your i18n gem will be locked try this:
bundle update i18n
That is all what is written in your error.
rvm is probably your best bet to prevent problems like this. But it might be overkill if you actually don't need multiple ruby version or gemsets.
Let me try to diagnose the issue. If we can solve it, then you don't have to jump through the rvm hoops (unless you want to of course).
I suspect that when you run some of these ruby-based scripts like 'gem', 'bundle', 'rails', and 'rake' the shebang line of these scripts is pointing to a ruby installation that you didn't expect.
Here's my usual checklist of diagnosing gem issues like this.
Run "which -a gem". Do you see multiple unique locations? If so, gem list using the full path to gem. E.g. "/usr/bin/gem list" and "/usr/local/bin/gem list". My guess is that you'll see that one of the lists has i18n and the other doesn't.
Run "which" on rails, bundler, and gem. Run "head -1" on each of those paths. Does the ruby path match in all of them?
My guess is that the "rails" in your PATH is not using the same ruby as the "gem" in your PATH. Maybe you installed it with the preinstalled 'gem' command so it's pointing to the system ruby's gem directory rather than /usr/local. Try reinstalling rails, then closing and reopening your terminal. Then use the "which" and "head -1" above to make sure "rails" is using the same ruby as "gem" is.
Another suspect is the "sudo" command. You may also want to run the "which" command via sudo, e.g. sudo sh -c 'which gem'. It's possible that sudo is running one of the preinstalled scripts.
If in doubt, you could run: "sudo /usr/local/bin/gem install rails" so you know for sure which gem command you're using.
I would do a couple of things.
Start by uninstalling Rails >= 3 from your current systems gem installation. This includes all Rails dependencies. You should be able to boot < Rails3 projects using your normal gem installation now.
Next up install rvm and use rvm to install Ruby 1.9.2 and Rails3. Use the 1.9.2 rvm to work with your Rails3 projects. Part of rails3 and rails2 don't work well together so you should always try to seperate them imho.
See this stack question for step by step instructions for installing rails using rvm. This is the most tried and true method I've found:
Uninstall Ruby on Rails on Mac OS X 10.6

How can I get control of gem installation locations?

Lots of confusion and difficulty related to gem installation. My gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.8.7 (2010-08-16 patchlevel 302) [i686-darwin10]
- INSTALLATION DIRECTORY: /opt/local/lib/ruby/gems/1.8
- RUBY EXECUTABLE: /opt/local/bin/ruby
- EXECUTABLE DIRECTORY: /opt/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86-darwin-10
- GEM PATHS:
- /opt/local/lib/ruby/gems/1.8
- /Users/apple/.gem/ruby/1.8
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- :sources => ["http://gems.rubyforge.org/"]
- REMOTE SOURCES:
- http://gems.rubyforge.org/
The problem is one where I will add (eg) to environment.rb :
config.gem 'authlogic'
All good, now when I run
gem install authlogic
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions into the /opt/local/lib/ruby/gems/1.8 directory.
running it with sudo is fine :
Dans-iMac-335:authlogic apple$ sudo rake gems:install
Password:
(in /Users/apple/Documents/projects/authlogic)
gem install authlogic
Successfully installed authlogic-2.1.6
1 gem installed
Installing ri documentation for authlogic-2.1.6...
Installing RDoc documentation for authlogic-2.1.6...
but running rake tasks throws an error :
Dans-iMac-335:authlogic apple$ rake db:migrate
(in /Users/apple/Documents/projects/authlogic)
Missing these required gems:
authlogic
You're running:
ruby 1.8.7.174 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.3.5 at /Users/apple/.gem/ruby/1.8, /Library/Ruby/Gems/1.8, /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/gems/1.8
Run `rake gems:install` to install the missing gems.
I can't see what the problem is. And I'm going out of my mind. The directory at the 'other' gems location :
Dans-iMac-335:authlogic apple$ ls /Users/apple/.gem/ruby/1.8/gems
actionmailer-2.2.2 activeresource-2.2.2 aws-s3-0.6.2 mysql-2.8.1 rails-2.2.2 xml-simple-1.0.12
actionpack-2.2.2 activeresource-2.3.3 builder-2.1.2 packet-0.1.15 rake-0.8.7
actionwebservice-1.2.3 activesupport-2.2.2 chronic-0.2.3 pg-0.8.0 rest-client-1.3.1
activerecord-2.2.2 activesupport-2.3.3 mime-types-1.16 rack-1.0.0 sqlite3-ruby-1.0.1
activerecord-2.3.5 activesupport-2.3.5 mongrel-1.1.5 rack-1.0.1 taps-0.2.26
This, I assume, is the default OSX rails system? The first location gives the much fuller set that represents my normal environment. Since my projects depend on many of these, and they aren't present in the other directory, this is verifiably the location that gems are being pulled from in my development environment:
Dans-iMac-335:authlogic apple$ ls /opt/local/lib/ruby/gems/1.8/gems
RedCloth-4.2.3 crack-0.1.8 mime-types-1.16 rack-1.1.0 sinatra-0.9.2
actionmailer-2.3.5 daemons-1.0.10 minitest-1.4.2 radiant-0.8.1 sinatra-1.0
actionmailer-2.3.8 faker-0.3.1 mogli-0.0.14 rails-2.2.2 spree-0.10.2
actionpack-2.3.5 fastthread-1.0.7 mongrel-1.1.5 rails-2.3.5 sqlite3-ruby-1.0.1
actionpack-2.3.8 gem_plugin-0.2.3 mutter-0.5.3 rails-2.3.8 sqlite3-ruby-1.2.5
activemerchant-1.5.1 google-geocode-1.2.1 mysql-2.8.1 rc-rest-3.0.0 state_machine-0.8.0
activerecord-2.3.8 hashie-0.4.0 net-scp-1.0.2 rest-client-1.0.3 stringex-1.0.3
activerecord-tableless-0.1.0 heroku-1.10.8 net-sftp-2.0.2 rest-client-1.6.1 taps-0.2.19
activeresource-2.3.5 highline-1.5.1 net-ssh-2.0.15 rmagick-2.13.1 taps-0.3.13
activeresource-2.3.8 hoe-2.3.3 net-ssh-gateway-1.0.1 ruby-hmac-0.4.0 thor-0.9.9
activesupport-2.3.8 hpricot-0.8.1 nokogiri-1.3.3 ruby-openid-2.1.7 treetop-1.4.8
authlogic-2.1.6 httparty-0.6.1 paperclip-2.3.1.1 rubyforge-2.0.2 whenever-0.3.7
authlogic-oid-1.0.4 json-1.1.9 passenger-2.2.5 rubyforge-2.0.4 will_paginate-2.3.11
aws-s3-0.6.2 json_pure-1.1.9 pg-0.8.0 rubygems-update-1.3.5 xml-simple-1.0.12
builder-2.1.2 json_pure-1.2.4 pg-0.9.0 rubygems-update-1.3.7
capistrano-2.5.9 launchy-0.3.3 polyglot-0.3.1 searchlogic-2.3.5
cgi_multipart_eof_fix-2.5.0 less-1.2.20 postgres-0.7.9.2008.01.28 sequel-3.0.0
configuration-1.1.0 libxml-ruby-1.1.3 rack-1.0.1 sequel-3.15.0
So, if the system uses this /opt/local/lib/ruby/gems/1.8/gems directory, why can't it see it when I call rake? And what can I do about it?
I don't see what the problem is, but have you tried running "gem list " to see what gems your system recognizes as having installed?
My solution was to change the #! line of rake.rb to point to the location of the ruby installation that has the gems.
From what I learned, when you're installing gems, rails takes account of the $PATH variable, but when loading the environment when rake is called, it doesn't. So rake doesn't know about those locations. The answer, then, was to direct rake's attention to the right location.

Resources