Multiple Rails vers on same machine + rake - ruby-on-rails

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.

Related

Redmine install process rake db:migrate does not work

I am in process of installing Redmine app via RedmineInstall documentation I try step 5 :
bundle exec rake db:migrate
then error shows :
bundler: command not found: rake
Install missing gem executables with ´bundle install´
I use redmine 3.3.0 64 for windows
I use redmine gemfile and rake was installed (i see Using rake 11.2.2)
I tried reinstall it via bundle install or gem install/uninstall, but did not help (see Successfully installed rake-11.2.2 but rake do not work).
I tried this command from ruby/bin directory or redmine directory not success.
I do not understand, that rake is successfully installed, but when i try use it with bundle it says that command not found.
The problem may be in the directory where the Redmine or rake?
Try rake db:migrate in your redmine directory without bundle exec and see if that resolves your issue.
Bundler usually provides bin stubs for rake and other gem files, so that bundle exec is not necessary or will even fail because it will look in an other gem directory where, in this case, rake might not be installed.

Rake does not run for older Rails application

I try to run rake routes on an older Rails application, then I got this:
Gem::LoadError: You have already activated rake 11.1.2, but your Gemfile requires rake 10.4.2. Prepending `bundle exec` to your command may solve this.
So I tried bundle exec, it works.
But how can I change my Gemfile so that I don't have to bundle exec,
rake 10.4.2 is not explicitly in my Gemfile.
Thanks.
Your current gemset has rake version 11.1.2, but your Gemfile.lock requires to use older version (namely 10.4.2).
If updating your project gems versions won't break your project, you can delete Gemfile.lock file and then run bundle install to create a new one. Then, the "problem" should be fixed.

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

Issue with "rake" and won't connect to database

I have a rails app i've been working on for a while and it was always working and testing fine. Then for some reason today when I tried rake db:migrate I get the message below. I have started using git recently. Whether that has anything to do with it I don't know.
Gem::LoadError: You have already activated rake 10.5.0, but your Gemfile requires rake 10.4.2. Prepending bundle exec to your command may solve this.
If i type bundle exec rake db:migrate it seems to complete the migration the issue now is that in the new view when the user hits the submit button the create action isn't called. So the data isn't entered into the database.
Any ideas would be great. Thanks.
You have to run bundle update on the terminal. I was also facing the same issue but after bundle update everything got fixed.
In my case
I used existing rvm gemset for new project
After bundle install (for new project) I had rake (10.5.0) in new project's Gemfile.lock
Old project is more important so I uninstalled rake 10.5.0 rvm gemset use <gemsetname>; gem uninstall rake + select 10.5.0 (asked in console)
rake (10.4.2) in new project's Gemfile.lock

Problems with Rake and Ruby on Rails

I have been trying to run rake but it seems that ever since I updated ruby gems rake is failing.
This morning I ran:
gem update --system
And ever since, rake has been failing with the following error:
$ rake db:migrate
rake aborted!
undefined method `specifications' for "/usr/lib/ruby/gems/1.9.1":String
/home/cknadler/projects/ecommerce/Rakefile:7:in `<top (required)>'
(See full trace by running task with --trace)
I have been reading about this problem and it seems that there is a problem with rake 0.9.x that breaks rails but when I check my rake version, I am running 0.8.7:
$ rake --version
rake, version 0.8.7
I have tried uninstalling rake and reinstalling it, using bundler, etc and at this point I am pretty stuck. Thanks in advance.
Edit:
My Rakefile (located in my app root directory)
# Add your own tasks in files placed in lib/tasks ending in .rake,
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
require File.expand_path('../config/application', __FILE__)
require 'rake'
Ecommerce::Application.load_tasks
I would suggest using the bundled binary version of rake to avoid this issue.
bundle exec rake db:migrate
If you installed your bundle using binstubs (bundle install --binstubs) then you can also use the bin version of rake which is equivalent to the bundle exec rake command:
bin/rake db:migrate
P.S: I would also recommend using RVM instead of installing Ruby using sudo for all users. This allows you to keep more modular ruby and gem installation.
You should remove rake 0.9.x (you may have 0.9.2 installed) by doing
gem uninstall rake -v=0.9.2
And then run bundle update
bundle update
Hope that helps.

Resources