Missing gem when running rake - ruby

I'm using rbenv with Ruby 1.9.2-p290, Rails 3.1, and the database is MySQL.
When I try
rake db:create
I get the following error:
Could not find multi_json-1.0.3 in any of the sources
I've also tried bundle exec rake db:create.
My GemFile looks like this:
source 'http://rubygems.org'
gem 'rails', '3.1.0'
gem 'mysql2'
gem 'json'
group :assets do
gem 'sass-rails', " ~> 3.1.0"
gem 'coffee-rails', "~> 3.1.0"
gem 'uglifier'
end
gem 'jquery-rails'

Quite old, but in case anyone else comes across this and is looking for the real answer: upgrade your bundler gem.

For me didn't work neither smathy and kalleth answers.
Always getting:
Could not find multi_json-1.3.0 in any of the sources
What it worked for me was deleting Gemfile.lock and running again bundle install
It installed a new version of multi_json:
Installing multi_json (1.3.2)

I ran into this problem too with a Rails 3.1 application + rails engines .
bundle exec rake -T reported the error you're reporting.
What solved it for me was running the following command to tell bundler to install the gems to the local 'vendor/bundle' path within the application with the following command:
bundle install --path=vendor/bundle
After I did that, bundle exec rake -T worked correctly.

I had the same problem, and used Jorge's answer to get to my solution:
bundle update multi_json
This just updates multi_json, and not all the other gems, which would potentially happen when you delete the Gemfile.lock and run "bundle install".

Always run your commands through bundle exec. That way you ensuer that you load the correct environment which is expected by your app. Use it like:
bundle exec rake db:migrate
Also make sure you have actually run bundle install to install all required gems and their dependencies.

Related

Error on require 'motion-cocoapods' with RubyMotion

I just got Ruby motion, and I wanted to try out Cocoapods. I installed it just as it asks on the website:
http://www.rubymotion.com/developer-center/articles/cocoapods/
I add
require 'motion-cocoapods' to my simple 'Hello' project. And I get this error when trying to rake it:
rake aborted!
Unable to activate cocoapods-0.16.1, because rake-10.0.3 conflicts with rake (~> 0.9.4)
I guess this has something to do with my version of rake, but I have no idea what I need to do to fix this problem. Please help!
This is caused by having a version of rake newer than 0.9.x installed. When you just run rake, it loads up the newest version (10.0.3 in your case). Then, when the cocoapod gem tries to load, it tries to activate rake 0.9.x and fails (the ~> 0.9.4 means that it will accept any version starting with 0.9.).
One solution would be to completely remove the rake gem and install the 0.9.4 version explicitly:
gem uninstall rake
gem install rake --version '0.9.6'
However, this could become an issue if you have any other projects that require a newer version of rake. A better solution would be to use Bundler:
gem install bundler
Create a Gemfile in your project folder containing:
source :rubygems
gem 'rake'
gem 'motion-cocoapods'
Add the following to Rakefile, immediately under the require 'motion/project' line:
require 'bundler'
Bundler.require
Then run bundle install from the console. This will lock this specific project on rake 0.9.6. The only catch is that you'll probably need to prefix all of your rake commands with bundle exec.
I was able to solve this issue by following the steps on this japanese blog:
http://blog.amacou.net/post/37702092871/rubymotion-cocoapods-rake
First uninstall:
gem uninstall motion-cocoapods
gem uninstall cocoapods
download cocoapods :
git clone git://github.com/CocoaPods/CocoaPods.git
find the gemspec file
and change this:
s.add_runtime_dependency 'rake', '~> 0.9.4'
to this:
s.add_runtime_dependency 'rake', '> 0.9.4'
then install it as a gem
rake gem:install
then reinstall motion-cocoapods:
gem install motion-cocoapods
My feeling is this is a hack though, and I'm worried it could cause problems else where. If anyone has a better answer, please post it.

Bundler cannot find installed gem

I have a Gemfile with the following contents:
source 'https://rubygems.org'
gem 'knife-cloudstack', :git => 'git://github.com/CloudStack-extras/knife-cloudstack.git'
On doing a bundle-install, i get the following output
bundle install --binstubs
...
Using knife-cloudstack (0.0.13) from git://github.com/CloudStack-extras/knife-cloudstack.git (at master)
...
But now when i do a bundle show, bundler cannot find the knife-cloudstack gem
bundle show knife-cloudstack
Could not find gem 'knife-cloudstack (>= 0) ruby' in the gems available on this machine
I am not sure what i am missing here. Please assist
just tried the exact same thing, and seems to work fine for me. What version of ruby are you using? What's the output of "gem environment"? Does running "bundle show" show any gems? Are you running on a linux machine? if so, you might be able to find out where it writes the gems to using: "strace -f -eopen -o/tmp/strace.log bundle install"
cheers

Rake at wrong version despite fresh uninstall/install procedures

I am trying to install RedMine on a server.
During the procedures as explained here i am supposed to run
rake generate_secret_token
However, i am getting this error:
(in /home/var/redmine)
rake aborted!
uninitialized constant Rake::DSL
/home/var/redmine/Rakefile:7
(See full trace by running task with --trace)
After some research i discovered that rake 0.8.7 is supposedly having problems with this (that, at least, is how i understood it) and that i am supposed to use rake 0.9.2.2
I tried adding
gem 'rake', '0.9.2.2'
to my Gemfile.
I checked
rake --version
And get
rake, version 0.8.7
I ran
gem uninstall rake
Which succeeded, according to the output.
Then i ran
gem install rake -v=0.9.2.2
And the output was
Successfully installed rake-0.9.2.2
1 gem installed
Installing ri documentation for rake-0.9.2.2...
Installing RDoc documentation for rake-0.9.2.2...
However, when then calling
rake --version
I still get
rake, version 0.8.7
I also experimented with adding
gem 'rake', '0.8.7'
to my Gemfile for redmine. However, then i get this response when running rake
You have requested:
rake = 0.8.7
The bundle currently has rake locked at 0.9.2.2.
Try running `bundle update rake`
What am i doing wrong here?
I was able to fix this strange issue by following these steps:
gem uninstall rake
Then
bundle update rake
This gave me the response that rake is already up-to-date, but still, i list it here - just in case.
Then
gem install rake -v=0.8.7
Furthermore in my Gemfile i had this configuration
source 'http://rubygems.org'
gem 'rails', '3.2.6'
gem 'rake', '0.8.7'
(In that order)
After doing all this i was able to run
rake generate_secret_token
successfully.
When using several versions of a same gem, you can specify which version to use using _version_ argument, eg. rake _0.9.2.2_ --version
(see gem help install)
To use Gemfile's version, you can prefix your command with bundle exec, eg. bundle exec rake --version (read "Getting started" from http://gembundler.com/)
Basically the different incompatible versions of rake are creating problem. This solved it for me:
/var/lib/gems/1.8/bin/rake generate_secret_token

Bundle exec rake db:migrate does not work (and neither does rake db:migrate), Ubuntu

I am running a Rails 3 app on Ubuntu (EC2), I have rake locked at version 0.8.7 and when I do rake db:migrate I get the usual:
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.8.7. Using bundle exec may solve this.
However when I do bundle exec rake db:migrate, I get the same response..
??
There are a couple of things that you can try:
Upgrade Ruby to 1.9.3 which will provide Rake 0.9.2.2
Add this to your Gemfile gem 'rake' , '>= 0.9.2' and run bundle update again.
Worst case, delete your Gemfile.lock and regenerate it again using bundle install

Using bundle exec may solve this?

Here is my Gemfile
source :rubygems
gem 'rake', '0.9.2.2'
gem 'sinatra'
gem 'activerecord', '3.0.9'
gem 'pg', '~> 0.12.2'
gem 'logger'
gem 'nokogiri'
group :development, :test do
gem 'rack-test'
gem 'ruby-debug19'
gem 'sqlite3'
end
I run rake console which works in other projects and now I get this message:
You have already activated activesupport 3.1.3, but your Gemfile requires activesupport 3.0.9. Using bundle exec may solve this.
How do I use `bundle exec to solve this? What does it mean?
To stop using bundle exec rake you can run bundle clean --force. This command will update your Gemfile.lock.
You can run bundle exec rake console which means that the command (in this case rake console) will be locked to the specific gems listed in your Gemfile.
rubygems-bundler solves this. Run the following commands:
$ gem install rubygems-bundler
$ $ gem regenerate_binstubs
Then try your bundle again.
You can check to make sure that you include rake in your Gemfile. If it's not, add it, and specify the version "you already activated".
or you can just update it on your local like
bundle update rake
I hope that this helps

Resources