When I added my first gem dependency to config/environment.rb, (will_paginate), I'm encountering an error when running rspec as follows:
nik$ spec spec/
Missing these required gems:
will_paginate
You're running:
ruby 1.8.6.369 at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby
rubygems 1.3.7 at /Users/nik/.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.
It's not picking up the first ruby binary in my $PATH, which I installed with macports:
nik$ ruby -v
ruby 1.8.7 (2010-06-23 patchlevel 299) [i686-darwin9]
nik$ which ruby
/opt/local/bin/ruby
Curiously, rake spec succeeds:
nik$ rake spec
(in /Users/nik/rails_projects/bigchan)
....................................................................................
Finished in 2.314131 seconds
84 examples, 0 failures
You have different commands looking up different versions of ruby, hence - different sets of gems.
$ which -a ruby
will show you at least two versions of ruby.
ruby 1.8.6.369 probably in /usr/bin (used when running spec spec/)
ruby 1.8.7.299 in /opt/local/bin (used when running rake spec)
Nuke the one you don't need and everything related to it.
Related
I am an absolute beginner when it comes to Ruby - I just follow a step by step tutorial to install OpenProject.
Right now I have problems with the following line of command:
RAILS_ENV=production bundle exec rake db:create
It returns
Could not find rake-11.3.0 in any of the sources
When I check the ruby version with "ruby -v" it prints
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-linux]
Now, when I check for rake:
gem list | grep rake
the output is:
rake (12.0.0)
... so why is it complaining that it could not find rake-11.3.0 even tough version 12 is installed?
Thanks!
You application seems to have a hard dependency on rake 11.3.0, i.e. 12.0.0 is not acceptable to it.
Have you run Bundler first?
Run this command and it should install the version of rake you need, then your original command should work:
bundle
meaning you have to downgrade your rake version to version 11.3.0
you may try this command
bundle update rake
this will try to update just rake to follow your setting in your Gemfile
I am using rails 4.1.4, ruby 2.1.2 and rvm.
Gemfile (extract)
gem 'rails-perftest'
gem 'ruby-prof', group: :test
I installed ruby using these commands (in order to apply patch which enables memory profiling)
rvm get stable
rvm reinstall 2.1.2 --patch railsexpress
But still no luck and memory reports are empty with rake test:benchmark or rake test:profile
I was trying to get the same Ruby patch and version working with a Rails 3 benchmark and that was broken too, albeit in a different way. It looks to me like this is an oversight in Rails. I'm seeing this warning string on a Rails 3.2 app
$ bundle exec rake test:benchmark
Update your ruby interpreter to be able to run benchmarks.
$ bundle exec rails -v
Rails 3.2.21
The problem seems to be that ActiveSupport 3.2 isn't aware of Ruby versions higher that 2.0 for this particular piece of code
if RUBY_VERSION.between?('1.9.2', '2.0')
require 'active_support/testing/performance/ruby/yarv'
elsif RUBY_VERSION.between?('1.8.6', '1.9')
require 'active_support/testing/performance/ruby/mri'
else
$stderr.puts 'Update your ruby interpreter to be able to run benchmarks.'
exit
end
see https://www.omniref.com/ruby/gems/activesupport/3.2.12/symbols/ActiveSupport::Testing::Performance::Metrics::CpuTime#line=145
After editing the version check manually I can confirm that the patch does work in Rails 3 with version 2.1.2. Perhaps you could check your RUBY_VERSION and RUBY_ENGINE constants for anything unusual?
(I understand this isn't really an answer but I don't have enough reputation to comment. Also it hopefully rules out the rvm patch and ruby-prof as a problem)
My heroku app is crashing because it can't find the module 'SecureRandom'. I am specifying my Ruby version in the gemfile, and my computer, gemfile and Heroku all seem to match Ruby version numbers, though not the patch numbers.
Other posts have suggested pointing usr/bin/heroku to a specific Ruby file, but I'm not sure how to do that (I have no Heroku bin in my app). This does seem like a Ruby version error. How can I try to fix this?
class OrderItem < ActiveRecord::Base
require 'SecureRandom'
...
end
Heroku log:
/app/vendor/bundle/ruby/2.0.0/gems/activesupport-4.0.3/lib/active_support/dependencies.rb:229:in `require': No such file to load -- SecureRandom (LoadError)
Gemfile:
source 'https://rubygems.org'
ruby '2.0.0'
Command line:
/ $ heroku run ruby -v
Running `ruby -v` attached to terminal... up, run.9318
ruby 2.0.0p481 (2014-05-08 revision 45883) [x86_64-linux]
/ $ ruby -v
ruby 2.0.0p451 (2014-02-24 revision 45167) [x86_64-darwin12.5.0]
Thanks in advance.
The actual name is securerandom, all lowercase. Linux filesystems are usually case sensitive.
So, change your require to:
require 'securerandom'
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
Recently I installed jruby and put it in my home directory. This apparently hijacked rake:
$ which ruby
/usr/bin/ruby
$ which rake
/home/user/jruby-1.5.5/bin/rake
Which seemed to be causing problems. So I moved the jruby folder and reinstalled rake, which at first seemed to fix it:
$ which rake
/usr/bin/rake
But when I run rake it's still trying to use the one in jruby:
user#user-desktop:~/rails/appname$ rake db:migrate
bash: /home/user/jruby-1.5.5/bin/rake: No such file or directory
How do I fix this?
Try RVM. It is invaluable for isolating different Ruby versions. Once installed do
rvm install jruby
That gets you a separate environment for running JRuby. You can switch between versions with
rvm system
rvm jruby