Cannot load gem installed using bundler in rails console - ruby-on-rails

I am trying to install the latest version of Globalize gem - the only one compatible with Rails 5. To do that I have to install it from Github. So I added the following line to the Gemfile as suggested by the Readme file:
gem 'globalize', git: 'https://github.com/globalize/globalize'
bundle install command is performed smoothly. But, globalize gem is not shown in gem list (I think all gems installed from Github does not show as well) but is shown in bundle list.
When I run bundle exec irb then require 'globalize' works fine. But it doesn't work in rails console. Why? How can I make the gem available for rails?
> rails c
2.4.0 :001 > require 'globalize'
LoadError: cannot load such file -- globalize
from (irb):1
> gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.6.12
- RUBY VERSION: 2.4.0 (2016-12-24 patchlevel 0) [x86_64-darwin16]
- INSTALLATION DIRECTORY: /Users/wael/.rvm/gems/ruby-2.4.0#rails5
- USER INSTALLATION DIRECTORY: /Users/wael/.gem/ruby/2.4.0
- RUBY EXECUTABLE: /Users/wael/.rvm/rubies/ruby-2.4.0/bin/ruby
- EXECUTABLE DIRECTORY: /Users/wael/.rvm/gems/ruby-2.4.0#rails5/bin
- SPEC CACHE DIRECTORY: /Users/wael/.gem/specs
- SYSTEM CONFIGURATION DIRECTORY: /Users/wael/.rvm/rubies/ruby-2.4.0/etc
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-16
- GEM PATHS:
- /Users/wael/.rvm/gems/ruby-2.4.0#rails5
- /Users/wael/.rvm/gems/ruby-2.4.0#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
- SHELL PATH:
- /Users/wael/.rvm/gems/ruby-2.4.0#rails5/bin
- /Users/wael/.rvm/gems/ruby-2.4.0#global/bin
- /Users/wael/.rvm/rubies/ruby-2.4.0/bin
- /Users/wael/.rvm/bin
....
rvm version is 1.29.2.
I couldn't find globalize gem in /Users/wael/.rvm/gems/ruby-2.4.0#rails5.
Update:
> rvm gemset list
gemsets for ruby-2.4.0 (found in /Users/wael/.rvm/gems/ruby-2.4.0)
(default)
global
=> rails5

I found this to resolve the issue for me:
> bundle exec rails console

Related

Invalid spec cache file in .../latest-specs.rb

I have a similar problem to: Invalid spec cache file
but it does not have an answer.
Our rails app recently upgraded from ruby 2.1.2 to 2.1.5
When I downloaded this onto my laptop (desktop working fine) it required be to rvm install 2.1.5, then create a new gemset for 2.1.5
I tried to run bundle and bundler isn't installed so I tried gem install bundler and it responded with the following error message:
ERROR: While executing gem ... (Gem::Exception)
Invalid spec cache file in /my_dir/.gem/specs/api.rubygems.org%443/latest_specs.4.8
On checking that directory, I find that there is a specs.4.8 file but not a latest_specs.4.8 file
Things I tried:
I deleted and re-created the gemset, same problem.
I ran gem update
I blew away /my_dir/.gem/specs and reran gem update
I ran gem update --system
I reinstalled ruby 2.1.5 and did it all again...
When I changed the ruby-version back to 2.1.2 and used rvm use 2.1.2; bundle it didn't have a problem (but then bundler already exists in that gemset).
Gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.2.2
- RUBY VERSION: 2.1.5 (2014-11-13 patchlevel 273) [x86_64-darwin10.0]
- INSTALLATION DIRECTORY: /my_dir/.rvm/gems/ruby-2.1.5
- RUBY EXECUTABLE: /my_dir/.rvm/rubies/ruby-2.1.5/bin/ruby
- EXECUTABLE DIRECTORY: /my_dir/.rvm/gems/ruby-2.1.5/bin
- SPEC CACHE DIRECTORY: /my_dor/.gem/specs
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /my_dir/.rvm/gems/ruby-2.1.5
- /my_dir/.rvm/gems/ruby-2.1.5#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- https://rubygems.org/
Try this:
gem sources --clear-all
gem sources --update
If that doesn't work, see my longer answer here: Corrupted ruby gem system
Eventually I gave up and reinstalled ruby 2.1.5 and deleted the gemset.
Then it turned out I could install without bothering to first create a gemset.
Just rvm use 2.1.5 then gem install bundler then bundle
So: no idea what went wrong (and would still encourage others to answer for an explanation), but this is what worked for me.

Gem environment/install location and bundler

it's been a while since I setup a brand new Rails environment.
I am trying to get gems to install under ~/.gems as opposed to /usr to avoid sudo-ing constantly.
Here is my gem env:
RubyGems Environment:
- RUBYGEMS VERSION: 2.0.3
- RUBY VERSION: 2.0.0 (2013-06-27 patchlevel 247) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/myname/.gems
- RUBY EXECUTABLE: /usr/local/bin/ruby
- EXECUTABLE DIRECTORY: /home/myname/.gems/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/myname/.gems
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :backtrace => false
- :bulk_threshold => 1000
- "gem" => "--no-rdoc --no-ri"
- "gemhome" => "/home/myname/.gems"
- "gempath" => ["/home/myname/.gems"]
- REMOTE SOURCES:
- https://rubygems.org/
$ which bundle
/home/myname/.gems/bin/bundle
now I did rails new SomeApp and when I run
bundle install
I get:
Errno::EACCES: Permission denied - /usr/local/lib/ruby/gems/2.0.0/build_info/jquery-rails-3.0.4.info
An error occurred while installing jquery-rails (3.0.4), and Bundler cannot continue
Which tells me that it's still trying to install the gem NOT where I want it. Any thoughts what to check? (I do have a ~/.gemrc file, the contents are the last 3 lines of the GEM CONFIGURATION section above).
Many thanks for all tips -- this was supposed to be a quick and easy step :)
highly recommend rbenv and rbenv-gemset, installing here with homebrew:
brew install rbenv rbenv-gemset
cd into/project/
echo specialgemsetname > .rbenv-gemsets
now start a new terminal (to ensure environment is correct) and setup your project.

Can't bundle gems with capistrano and rbenv

I use capistrano to deploy rails app. I have set up rbenv and using capistrano-rbenv in my deploy.rbfile
Error message when deploying:
Could not find rake-10.1.0 in any of the sources
Run `bundle install` to install missing gems.
On server when I run bundle install I get Could not locate Gemfile
$ gem env returns
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.23
- RUBY VERSION: 1.9.3 (2012-04-20 patchlevel 194) [x86_64-linux]
- INSTALLATION DIRECTORY: /var/lib/gems/1.9.1
- RUBY EXECUTABLE: /usr/bin/ruby1.9.1
- EXECUTABLE DIRECTORY: /usr/local/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /var/lib/gems/1.9.1
- /home/deployer/.gem/ruby/1.9.1
- /usr/share/rubygems-integration/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
You should confirm that rake 10.1 is on the server through ssh login. It is a dependency to your process.
Rake is a gem like any other, so on the server run
gem install rake -v=10.1.0
if gem which returns nothing, then you need to first install rubygems, e.g.
apt-get install rubygems
Ensure that apt-get properly configures your PATH. You may need to re-source your .bash_profile (or whichever for your shell — or login again to get a new shell
I will update this answer if more details emerge.
I ended up removing the capistrano-rbenvgem and it finally worked out.
If you are requiring capistrano/bundler in your Capfile, be sure to specify the gemfile location in your deploy.rb:
# setup bundler
set :bundle_gemfile, -> { release_path.join('Gemfile') }
See: https://github.com/capistrano/bundler

how to install the latest version of rails on ubuntu 11.10?

I want to install rails 3.2.1 on ubuntu 11.10.
I already installed rbenv, ruby-build.
When I run
gem install rails
it tells me
Successfully installed rails-3.2.1
1 gem installed
Installing ri documentation for rails-3.2.1...
Installing RDoc documentation for rails-3.2.1...
then after rbenv rehash, if I run "rails", it cannot find the binary file. So I guess rails is NOT installed. How can I do?
edit:
~ » gem environment
RubyGems Environment:
- RUBYGEMS VERSION: 1.8.15
- RUBY VERSION: 1.9.3 (2011-10-30 patchlevel 0) [x86_64-linux]
- INSTALLATION DIRECTORY: /home/jafar/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1
- RUBY EXECUTABLE: /home/jafar/.rbenv/versions/1.9.3-p0/bin/ruby
- EXECUTABLE DIRECTORY: /home/jafar/.rbenv/versions/1.9.3-p0/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-linux
- GEM PATHS:
- /home/jafar/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1
- /home/jafar/.gem/ruby/1.9.1
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
edit 2 :
gem list tells me the rails gem is installed. When I search for the rails binary I find this :
~ » find . -name rails
./.oh-my-zsh/plugins/rails
./Downloads/robbyrussell-oh-my-zsh-3629270/plugins/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.2.1/guides/code/getting_started/script/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.2.1/bin/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/generators/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/generators/rails/app/templates/script/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/generators/rails/plugin_new/templates/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-rails-3.2.4/test/fixtures/engine_project/script/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-rails-3.2.4/test/fixtures/engine_project/test/dummy/script/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-rails-3.2.4/test/fixtures/scss_project/script/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-rails-3.2.4/test/fixtures/sass_project/script/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-rails-3.2.4/lib/sass/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-rails-3.2.4/lib/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/activerecord-3.2.1/lib/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/actionmailer-3.2.1/lib/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/jquery-rails-2.0.0/lib/jquery/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/sass-3.1.12/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/coffee/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/gems/coffee-rails-3.2.2/lib/rails
./.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/bin/rails
The rails binary should be in ~/.rbenv/shims but it's not. ~/.rbenv/shims is in my PATH
You need to add the bin subdirectory of /home/jafar/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1 to your PATH, e.g. edit your ~/.bashrc file and add this line at the end:
export PATH=/home/jafar/.rbenv/versions/1.9.3-p0/lib/ruby/gems/1.9.1/bin:$PATH
And then see what the command rails --version will output.

"LoadError: no such file to load" when requiring gem

I'm using RVM, Ruby 1.9.2 and Rails 3.0.3 installed. I installed the curb-fu gem just now. When I do gem list, curb-fu is listed. When I do require 'curb-fu' in the irb, it returns true.
But when I try the same in the rails console of my app, I get this error:
ruby-1.9.2-p136 :001 > require 'curb-fu'
LoadError: no such file to load -- curb-fu
When I do require 'rubygems', it returns nil, and when I try curb-fu after that it gives the same error.
My gem environment:
RubyGems Environment:
- RUBYGEMS VERSION: 1.3.7
- RUBY VERSION: 1.9.2 (2010-12-25 patchlevel 136) [x86_64-darwin10.5.0]
- INSTALLATION DIRECTORY: /Users/rits/.rvm/gems/ruby-1.9.2-p136
- RUBY EXECUTABLE: /Users/rits/.rvm/rubies/ruby-1.9.2-p136/bin/ruby
- EXECUTABLE DIRECTORY: /Users/rits/.rvm/gems/ruby-1.9.2-p136/bin
- RUBYGEMS PLATFORMS:
- ruby
- x86_64-darwin-10
- GEM PATHS:
- /Users/rits/.rvm/gems/ruby-1.9.2-p136
- /Users/rits/.rvm/gems/ruby-1.9.2-p136#global
- GEM CONFIGURATION:
- :update_sources => true
- :verbose => true
- :benchmark => false
- :backtrace => false
- :bulk_threshold => 1000
- REMOTE SOURCES:
- http://rubygems.org/
What can I do?
You need to list the gem "curb-fu" in your app's Gemfile as
gem 'curb-fu'
and then run "bundle install".
In Rails 3, gem dependencies are handled thru Bundler and must be listed in the Gemfile.

Resources