RoR rake bundle dependencies - ruby-on-rails

Platform: windows 7, running on JRuby 1.6.8.
C:\project> rake db:migrate
rake aborted!
You have already activated rake 10.0.3, but your Gemfile requires rake 0.9.2.2.
Using bundle exec may solve this.
OK. I have added
gem "rake", "= 0.9.2.2"
to Gemfile and ran:
C:\project> bundle exec rake db:migrate
bundler: command not found: rake
Install missing gem executables with `bundle install`
<polite>WTF?</polite>
I have also done
bundle install --deployment
to no avail.
I have different versions of rake installed:
C:\project>gem list
LOCAL GEMS
...
rake (10.0.3, 0.9.2.2, 0.8.7)
How to resolve this? I need rake db:migrate working with my specific (inherited) RoR project with gems that tend to be slightly out of date, but they are all specified in Gemfile.

Don't run bundle --deployment until you clearly understand what it is used for. (it's confusing, we usually use bundle install --path vendor/bundle)
The first error means, that you should execute your command with bundle exec, like bundle exec rake db:migrate
after the version change in the Gemfile you should have just run bundle install without --deployment.
At this point I'd recommend to delete the .bundle folder in your project home, this reverses the --deployment call. Afterwards call bundle install and try it again. If it doesn't work please let us know.
Don't get frustrated, bundle is pretty cool as soon as you get the hang of it.

Related

Multiple Rails vers on same machine + rake

I've been running a Rails 3.2 with Ruby 1.9.3 for a while now. Recently I added Rails 5.1 and Ruby 2.4.
I used rvm to install Ruby2.4.
Today I had occasion to cd into one of my old projects and run rake db:migrate, and I got the following message:
Gem::LoadError: You have already activated rake 12.0.0, but your Gemfile requires rake 0.9.2.2. Prepending `bundle exec` to your command may solve this.
Prepending 'bundle exec' did solve the problem but for my knowledge I would like to understand what happened. I thought the whole point of a Gem file within the project was to lock in the required gems.
So somewhere on my machine clearly there is still rake 0.9.2.2 but why did my command 'rake db:migrate' not use that automatically?
Reason: Some of the gem might have locked rake gem to that version.You are getting this as version of rake inside gemlock file is different than the one you have already installed.
Solution1:
bundle update
Solution2:
edit the gemlock file. open Gemfile.lock and change
rake (0.9.2.2) to rake (12.0.0)
Solution3:
remove Gemfile.lock and run bundle install once again.This will create
Gemfile.lock once again.

Rails - Getting Rake error

When running rake commands, I get this error:
You have already activated rake 10.0.2, but your Gemfile requires rake 11.1.1.
Prepending `bundle exec` to your command may solve this.
How do I fix this so that I don't have to run bundle exec before every rake command?
I uninstalled rake and reinstalled, but it's still looking for an older version:
C:/Ruby22-x64/bin/rake:22:in `load': cannot load such file -- C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/rake-10.4.2/bin/rake (LoadError)
from C:/Ruby22-x64/bin/rake:22:in `<main>'
run
$ bundle update rake
that worked for me.
see the documentation.
http://bundler.io/v1.3/man/bundle-update.1.html
Pretty simple:
gem install rake -v 11.1.1
For me it was just that I needed to use sudo bundle exec rake <...>, maybe it can help someone else...
(I was trying to install concerto on a RaspberryPi, FYI)
UPDATE:
gem 'rake','10.0.2' in gemfile
gem uninstall rake
remove gemfile.lock
bundle update rake
Simply remove your gemfile.lock and do bundle install :)
simply write this
gem install rake
Check your Gemfile.lock for rake version, you should find something like
rake (10.0.2)
If you found the above then you have to remove your gemfile.lock then run bundle install again.
And it wouldnt hurt to double check that you are on the right project.
just write a command starting with bundle exec example bundle exec rake db:schema
The problem is your installed rake has a different version to the rake in your Gemfile.lock. Just go in there, Cmd + F to search for 'rake', change the version number to the one that terminal wants.
The problem is the rake version you are using is not same as that in your Gemfile, you must make sure of that there's no difference, you can also take no more bundle exec ... with rubygems-bundler
gem install rubygems-bundler
next run (once)
gem regenerate_binstubs

Rails migration error when running migration?

When I do rake db:migrate, I get the following error:
rake aborted!
Gem::LoadError: You have already activated rake 10.2.2, but your Gemfile requires rake 10.1.0. Using bundle exec may solve this.
How can solve this?
This error is due to the fact that some applications may specify different versions of gems than the ones you have installed.
Try using bundle exec rake db:migrate.
Using bundle exec guarantees that the program is run with the environment specified in the gemfile.
Perhaps:
bundle exec rake db:migrate
There might be other gems in the Gemfile which are dependent on rake 10.2.2, while you are trying to install rake 10.1.0 via your gemfile or explicitly mentioned it. A look into your Gemfile will help.
In case you have specific environment, you may want to run
bundle exec rake db:migrate
to make sure you are running it appropriately.
As per another answer given on this topic, you can also try deleting the Gemfile.lock file and re-running bundle install to regenerate the Gem dependencies.

bundle binstubs vs rake

I am relatively new to Rails, and using version 3.x.I have just found out about bundle binstubs gem command which creates executable wrappers in /bin dir.Is there any benefit running commands from bin/ if there is already rake task for that.For example, I would use rake spec:models , which I prefer over bin/rspec spec/models/.
Yes.
As an example, when you install gems locally within your rails app using Gemfile and bundle install, you normally need to do a bundle exec before running tasks, so as to resolve ruby gems dependecies from the app directory, not from installed otherwise (using gem install <gemname>).
With binstubs, you don't need to do that.
Example: bundle exec rake RAILS_ENV=production onetime:generate_report without binstubs and
rake RAILS_ENV=production onetime:generate_report with binstubs

newbie: error message when 'rake -T'

I am using Ruby Enterprise Edition for my project. When I check all my rake task by run the command rake -T , I got the following error message:
You have already activated rake 0.9.2.2, but your Gemfile requires rake 0.9.2. Using bundle exec may solve this.
The error message implies that I can use bundle exec to solve the problem, but I am not sure how? So, how to get rid of this error message?
------------------------------ more ---------------------------
I prefer to update my Gemfile instead of run bundle exec rake -T. But when I open my project Gemfile, I did not see rake 0.9.2 in my Gemfile, why the error message complains that I have it? Where could be the place I defined rake 0.9.2??
Run bundle exec rake -T, this ensures that the version of rake that is specified in your Gemfile is running, not another version.
Alternatively, update your Gemfile.
This is because your rake tool does not match the version written in the Gemfile.
You first need to run this command, to ensure rake 0.9.2 get installed:
bundle install
Then, you can run rake 0.9.2 with the following command:
bundle exec rake -T
The bundle thing is a nice tool to help you manage the dependency of your application. You can get more info from here.

Resources