LoadError: cannot load such file --rails on 'rake db:setup' - ruby-on-rails

I'm having an issue trying to switch the database in my rails app from the out of box sqlite3 to using postgres.
I've run 'gem install pg' and switched the database.yml file to new settings. Also, I've run 'bundle install' in the directory.
Now, when I run 'rake db:setup', I'm receiving this error:
$ rake db:setup
rake aborted!
LoadError: cannot load such file -- rails
/Users/aaa/Documents/Projects/sample_app/config/application.rb:3:in `require'
/Users/aaa/Documents/Projects/sample_app/config/application.rb:3:in `<top (required)>'
/Users/aaa/Documents/Projects/sample_app/Rakefile:4:in `<top (required)>'
/Users/aaa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `eval'
/Users/aaa/.rvm/gems/ruby-2.2.1/bin/ruby_executable_hooks:15:in `<main>'
(See full trace by running task with --trace)
Any thoughts? Thank you in advance.

Oy, had the wrong version of rails in my gemfile.
If anyone else finds this, make sure running rails -v has your intended result! I was receiving an error when trying to see my rails version, and then changing my gemfile solved the issue.

Related

Replicating Rails App

I am trying to download a Rails app from github and that make it work on my PC. I have read other posts that say you have to run bundle install, rake db:create and then rake db:migrate, I do everything but when I try to run rake db:create I get this error:
rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 10.3.2. Prepending `bundle exec` to your command may solve this.
D:/art-website/config/boot.rb:4:in `<top (required)>'
D:/art-website/config/application.rb:1:in `<top (required)>'
D:/art-website/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
D:/art-website/config/boot.rb:4:in `<top (required)>'
D:/art-website/config/application.rb:1:in `<top (required)>'
D:/art-website/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
The cause
Your gem rake has a conflicts in the version you have installed i.e. the gem rake your Gemfile requires is of version 10.3.2 while the gem you have on your machine has got version 10.4.2 and 10.3.2.
Solution
uninstall the gem of version 10.4.2. gem uninstall rake would ask you for the version that has to be uninstalled, please select 10.4.2
you may run the commands with bundle exec eg:- bundle exec rake db:migrate or bundle exec rake db:create
you may want to use RVM and use Gemsets as per the projects and its dependency gems. (I would personally prefer this way so that the projects of different version of gems would be clear and no need to worry about the conflicts gem versions)

Unable to run Rake tasks, ci_reporter dependency missing

I am unable to any rake tasks within my Rails project. Any attempt to do so results in the following error, stating that it cannot locate an rspec file for ci_reporter:
rake aborted!
LoadError: cannot load such file -- ci/reporter/rake/rspec
/Users/blake/.rvm/gems/ruby-2.0.0-p643/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/Users/blake/.rvm/gems/ruby-2.0.0-p643/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `block in require'
/Users/blake/.rvm/gems/ruby-2.0.0-p643/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:236:in `load_dependency'
/Users/blake/.rvm/gems/ruby-2.0.0-p643/gems/activesupport-3.2.11/lib/active_support/dependencies.rb:251:in `require'
/Users/blake/workspaces/ruby/minestatus/Rakefile:6:in `<top (required)>'
/Users/blake/.rvm/gems/ruby-2.0.0-p643/bin/ruby_executable_hooks:15:in `eval'
I have made the following attempts to reset my environment to a working state:
Installing the newest ci_reporter gem from github
Deleting Gemfile.lock and re-running bundle install
Reinstalling Ruby 2.0.0 using rvm
Unfortunately none of the above things have helped me solve this issue. I am able to run rake tasks in other Rails projects, but not in this one. Rake tasks used to run just fine, and I'm not sure what changes I could've made to break things. Does anyone have an idea of what I can do to get rake tasks to run properly again?

migration error with rake db:migrate

I created a new model, but when I run the rake db: migrate command, it shoots me the following error:
rake aborted!
Gem::LoadError: You have already activated rake 10.4.0, but your Gemfile requires rake
10.3.2. Prepending `bundle exec` to your command may solve this.
/Users/yedidyaweiner/projects/music-app/config/boot.rb:4:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/config/application.rb:1:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/Users/yedidyaweiner/projects/music-app/config/boot.rb:4:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/config/application.rb:1:in `<top (required)>'
/Users/yedidyaweiner/projects/music-app/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
What am I doing wrong?
use
bundle exec rake db:migrate
You can also update your gems by running
bundle update
Execute the below commands
a) delete your Gemfile.lock file
b)bundle install
It should update Gemfile.lock with correct rake.
OR
a) gem uninstall rake -v 10.4.0
b) gem install rake -v 10.3.2
then try running 'rake db:migrate'. it should work.

rake routes command is not working

I have run this rake routes command in terminal but not working, But it's working few days back. Please check it
jaskaran#jaskaran-Vostro-1550:~/rails_project$ rake routes
rake aborted!
Gem::LoadError: You have already activated rake 10.3.2, but your Gemfile requires rake 10.2.2. Prepending `bundle exec` to your command may solve this.
/home/jaskaran/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.6.1/lib/bundler/runtime.rb:34:in `block in setup'
/home/jaskaran/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.6.1/lib/bundler/runtime.rb:19:in `setup'
/home/jaskaran/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.6.1/lib/bundler.rb:120:in `setup'
/home/jaskaran/.rvm/gems/ruby-2.1.0#global/gems/bundler-1.6.1/lib/bundler/setup.rb:7:in `<top (required)>'
/home/jaskaran/rails_project/config/boot.rb:4:in `<top (required)>'
/home/jaskaran/rails_project/config/application.rb:1:in `<top (required)>'
/home/jaskaran/rails_project/Rakefile:4:in `<top (required)>'
LoadError: cannot load such file -- bundler/setup
/home/jaskaran/rails_project/config/boot.rb:4:in `<top (required)>'
/home/jaskaran/rails_project/config/application.rb:1:in `<top (required)>'
/home/jaskaran/rails_project/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Try running bundle exec rake routes to ensure the proper version of Rake gets loaded.
You need to update your gems to the latest available versions: bundle update
Rake versions seems to be different. So, run it as bundle exec rake routes. It should be working.
The correct solution to your problem is to use bundle exec, as suggested by others, to load the version of Rake which your app expects. You may also wish to avoid needing to always run Rake commands with bundle exec. You can either
1) [Recommended] Update your app to use the same version of rake as you have running globally (10.3.2, which is the latest version)
or
2) [Not really recommended] Uninstall version 10.3.2 (actually, any version greater than the one you want) from your global gems and install version 10.2.2 (which your app is currently using)
rvm #global do gem uninstall rake
rvm #global do gem install rake --version 10.2.2
See RVM documentation for global gemsets

Dropping the database in Rails

~/Rails Projects/QA-app$ rake db:drop
rake aborted!
Gem::LoadError: You have already activated rake 10.3.2, but your Gemfile requires rake 10.1.1. Using bundle exec may solve this.
/home/salmanalam/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:33:in `block in setup'
/home/salmanalam/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/runtime.rb:19:in `setup'
/home/salmanalam/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler.rb:120:in `setup'
/home/salmanalam/.rvm/gems/ruby-2.0.0-p353#global/gems/bundler-1.3.5/lib/bundler/setup.rb:7:in `<top (required)>'
/home/salmanalam/Rails Projects/QA-app/config/boot.rb:4:in `<top (required)>'
/home/salmanalam/Rails Projects/QA-app/config/application.rb:1:in `<top (required)>'
/home/salmanalam/Rails Projects/QA-app/Rakefile:4:in `<top (required)>'
(See full trace by running task with --trace)
Run the command using bundle exec(bundle exec rake db:drop) to force the version of rake that is used by your application.
Just run `bundle update and update your app. The version of Rake that it is looking for is 10.1.1 but your version of Rake has already been updated to 10.3.2
You can't just go updating all gems willy nilly on a larger project without running into problems. If you don't want to have to prefix bundle exec, then just run bundle update rake.
This is what worked for me:
rm -rf Gemfile.lock
Then run bundle install if needed, and rake db:(whatever) goes without error.

Resources