Hello I have a strange problem, I'm trying to get rake task working in whenever, but have this problem Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound). It's strange, because it searches this rake version in ruby 2.1.2 version /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/spec_set.rb:92. However I'm using ruby 2.2.0 in rvm and the gem list is also using that version.
It's a simple cron job:
every 1.minute do
rake 'process_email:handle', output: 'log/mail.log', environment: 'development'
end
Rakefile:
namespace :process_email do
desc 'Handle email'
task handle: :environment do
MOBIZARD_MAILER.processor.retrieve_mail
end
end
Mobizard mailer is my own gem, that retrieves mails through ruby mail gem, that uses same ruby 2.2.0 and same gem list.
Whole stack trace in mail.log looks like this:
/home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/spec_set.rb:85:in `map!'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/spec_set.rb:85:in `materialize'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/definition.rb:133:in `specs'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/definition.rb:178:in `specs_for'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/definition.rb:167:in `requested_specs'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/environment.rb:18:in `requested_specs'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/runtime.rb:13:in `setup'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler.rb:120:in `setup'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bundler-1.6.2/lib/bundler/setup.rb:17:in `<top (required)>'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /home/vyivrain/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
Thx for answering.
It is because the output is set with the -l flag, which is incorrectly interpreted by rvm.
You can read more about this issue here:
https://github.com/javan/whenever/issues/325
TL;DR
Add this to schedule.rb
ENV.each { |k, v| env(k, v) }
Ref: https://github.com/javan/whenever/issues/656
My guess is the GEM_PATH is not the same when running in a crontab and when running in your normal/dev environment. You could check it which this command
gem which rake
In my cases:
When running in crontab GEM_PATH would be something like /usr/local/lib/ruby/site_ruby/2.3.0/bundle
When running in "normal", the GEM_PATH is /usr/local/bundle
This script ENV.each { |k, v| env(k, v) } will auto add those envs to make sure ruby using the right GEM_PATH
Quote from this answer https://stackoverflow.com/a/20499839/1819549
The -l option (according to the man page) makes "bash act as if it had been invoked as a login shell". Login shells read certain initialization files from your home directory, such as .bash_profile. Since you set the value of TEST in your .bash_profile, the value you set on the command line gets overridden when bash launches.
So #Yury's answer works maybe because the command executes something in .bash_profile and I guess it update the GEM_PATH for rvm.
Related
I want to check the version of my production database from a shell method running on my local MacOS development machine. From the command line, I can successfully run
heroku run rake db:version --remote production
but if I open a rails console session and type in
hv = `heroku run rake db:version --remote production`
I see the following error message:
/Users/Chris/.rvm/gems/ruby-2.5.1#golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler/definition.rb:489:in `validate_ruby!': Your Ruby version is 1.9.3, but your Gemfile specified 2.5.1 (Bundler::RubyVersionMismatch)
from /Users/Chris/.rvm/gems/ruby-2.5.1#golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler/definition.rb:464:in `validate_runtime!'
from /Users/Chris/.rvm/gems/ruby-2.5.1#golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler.rb:101:in `setup'
from /Users/Chris/.rvm/gems/ruby-2.5.1#golf_mentor_5.0.7/gems/bundler-1.16.1/lib/bundler/setup.rb:20:in `<top (required)>'
from /usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/local/heroku/ruby/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require
I am using ruby 2.5.1. The heroku --version command yields heroku-cli/6.16.13-dbb9c23 (darwin-x64) node-v9.11.1. How do I fix this?
It turns out this is related to this github https://github.com/bundler/bundler/issues/2489. It looks like bundler is confused by a shebang in the heroku cli file. The solution is to use a clean environment for bundler
Bundler.with_clean_env {`heroku run rake db:version --remote production`}
I'm getting this one error I don't understand (I'm fairly new to rails) when using the gem 'whenever' in development mode.
What I did was update config/schedule.rb and run
whenever --update-crontab --set environment='development'
crontab -l lists:
* * * * * /bin/bash -l -c 'cd /home/vic/Desktop/WorkflowProject && bundle exec bin/rails runner -e development '\''Task.new2'\'' >> log/whenever.log 2>&1'
at config/schedule.rb
set :output, 'log/whenever.log'
every 1.minute do
runner "Task.new2"
end
at log/whenever.log
bundler: failed to load command: bin/rails (bin/rails)
Bundler::GemNotFound: Your bundle is locked to rake (11.3.0), but that version could not be found in any of the sources listed in your Gemfile. If you haven't changed sources, that means the author of rake (11.3.0) has removed it. You'll need to update your bundle to a different version of rake (11.3.0) that hasn't been removed in order to install.
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:179:in `rescue in specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:173:in `specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:233:in `specs_for'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/definition.rb:222:in `requested_specs'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/runtime.rb:118:in `block in definition_method'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/runtime.rb:19:in `setup'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler.rb:99:in `setup'
/home/vic/.rvm/gems/ruby-2.3.1/gems/bundler-1.13.2/lib/bundler/setup.rb:20:in `<top (required)>'
/home/vic/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
/home/vic/.rvm/rubies/ruby-2.3.1/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
I would grealy appreciate the help, thank you very much!
Try the below commands.
gem install rubygems-bundler
gem regenerate_binstubs
Ref: this
Are you sure to have bundler installed? Try running bundle install inside your application directory.
If no, see Jayaprakash's answer above.
If yes, try bundle exec whenever --update-crontab --set environment='development'.
Update:
Ahh, missed that you are seeing error when your task executes.
Try this in your config/schedule.rb
env :PATH, ENV['PATH']
set :output, "#{ Whenever.path }/log/whenever.log"
every 1.minute do
runner "Task.new2"
end
I'm trying to start the rails app when Ubuntu starts up.
For this, I added these lines in /etc/rc.local.
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
bundle exec passenger start --port 8000 --user ubuntu --daemonize
However, the rc.local exits with error
+ cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
+ bundle exec passenger start --port 8000 --user ubuntu --daemonize
/usr/lib/ruby/vendor_ruby/bundler/spec_set.rb:92:in `block in materialize': Could not find rake-10.4.2 in any of the sources (Bundler::GemNotFound)
from /usr/lib/ruby/vendor_ruby/bundler/spec_set.rb:85:in `map!'
from /usr/lib/ruby/vendor_ruby/bundler/spec_set.rb:85:in `materialize'
from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:114:in `specs'
from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:159:in `specs_for'
from /usr/lib/ruby/vendor_ruby/bundler/definition.rb:148:in `requested_specs'
from /usr/lib/ruby/vendor_ruby/bundler/environment.rb:18:in `requested_specs'
from /usr/lib/ruby/vendor_ruby/bundler/runtime.rb:13:in `setup'
from /usr/lib/ruby/vendor_ruby/bundler.rb:120:in `setup'
from /usr/lib/ruby/vendor_ruby/bundler/setup.rb:17:in `<top (required)>'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
The error is caused from using the ruby installed from rbenv; the ruby is in /home/ubuntu/.rbenv/bin/ directory. I guess when ubuntu starts up, the system ruby is executed, but it does not know anything about installed packges with rbenv's ruby and gem.
How can I solve this issue? Is there any way to make the ruby from rbenv as system's ruby?
For getting the error, I used the hints from this post: Run script with rc.local: script works, but not at boot.
EDIT
mwp's answer works fine, but I think I'd better make things clearer.
development bundle
Run bundle --deployment --binstubs to create ./vendor and copy files in bundle directory.
The setup.sh
#!/bin/bash
export APP_ROOT="/home/ubuntu/webapp/rails/passenger-ruby-rails-demo"
export APP_USER="ubuntu"
export APP_PORT="8000"
export RBENV_ROOT="/home/ubuntu/.rbenv"
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
# Assuming you installed bundle with --binstubs...
$APP_ROOT/bin/passenger start --port $APP_PORT --user $APP_USER --daemonize
The rc.local file
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
sh ./setup.sh
exit 0
Run these commands one time:
cd /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
rbenv local <the version you want>
This will create a .ruby-version file in your application directory that tells rbenv which version to use.
I would also recommend that when you deploy the application to its "production" location, you install bundler with the --deployment --binstubs flags. This will install the Gems inside a vendor subdirectory (to insulate them from an errant Gem update) and create handy shortcuts inside a bin subdirectory to run e.g. passenger, rackup, etc. without needing to do bundle exec.
However, you have another problem, and that is that rbenv (the shell function) [probably] isn't available while rc.local is running. I would recommend creating a new shell script and stashing it somewhere, possibly within your application's directory structure, with (something like) the following contents:
#!/bin/bash
export APP_ROOT="/home/ubuntu/webapp/rails/passenger-ruby-rails-demo"
export APP_USER="ubuntu"
export APP_PORT="8000"
export RBENV_ROOT="/path/to/rbenv"
export PATH="$RBENV_ROOT/bin:$PATH"
eval "$(rbenv init -)"
# Assuming you installed bundle with --binstubs...
"$APP_ROOT"/bin/passenger start --port $APP_PORT --user $APP_USER --daemonize
Then mark this script executable and you can call it from rc.local to start the service. As far as what you set RBENV_ROOT to, you can either use an existing user's .rbenv directory (e.g. ~ubuntu/.rbenv, assuming you installed a copy there), or you can set up a system-wide rbenv at /opt/rbenv or elsewhere. There are some good notes here.
I can think of a million different ways to improve the above script, and indeed this is only one of a million different ways to tackle this problem. Starting and stopping services is quite a hot topic in the DevOps and SysAdmin communities right now. I've had great success running Ruby applications in production using rbenv and Bundler, and if you decide to go this route, I hope you will too!
Upstart (http://upstart.ubuntu.com) can be a better way to replace rc.local.
# simple script
# http://uwsgi-docs.readthedocs.org/en/latest/Upstart.html
description "passenger "
start on runlevel [2345]
stop on runlevel [06]
respawn
# http://stackoverflow.com/questions/14823972/upstart-node-js-working-directory
script
chdir /home/ubuntu/webapp/rails/passenger-ruby-rails-demo
exec sh runme.sh
end script
I'm having a really frustrating issue: Rake is being dumb.
Here's how the problem comes about:
$ rails new test_app
$ rails generate scaffold new_scaffold field1:string field2:text
Both of those work just fine, but then when I do this,
$ rake db:migrate
I get the following error.
(in /home/mikhail/test_app)
rake aborted!
uninitialized constant Rake::DSL
/usr/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/home/mikhail/test_app/Rakefile:7:in `<top (required)>'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/bin/rake:31:in `<main>'
I've looked about the Internet for similar/same errors, and people have had them. Just no one ever seems to solve the problem!
How do I fix this problem?
A tweet from DHH earlier. Rake .9.0 breaks Rails and several other things, you need to:
gem "rake", "0.8.7"
in your Gemfile.
I made some research just after my previous answer (sorry, I must do before it).
All problems are solved with Rake gem 0.9.2.. I followed these steps:
I installed gem install rake -v=0.9.2 (I had the 0.9.1 gem)
removed the 0.9.1 with gem uninstall rake -v=0.9.1
updated with bundle update
then the db:migrate showed a warning, WARNING: Global access to Rake DSL methods is deprecated. Please....
It was solved by adding the following to the Rake file.
module ::YourApplicationName
class Application
include Rake::DSL
end
end
I ommited the module ::RakeFileUtils extend Rake::FileUtilsExtend option sugested by #databyte.
It means that the Rake gem 0.9.2 works fine!
Going through Chapter 2 of Railstutorial (demo_app) and ran into this problem. I tried all of the other answers listed here, but couldn't get it to work until I did this:
Put this in your Rakefile above require 'rake':
require 'rake/dsl_definition'
via How to fix the uninitialized constant Rake::DSL problem on Heroku?
I also recommitted and pushed all files to Github and Heroku.
All I needed to do was use:
gem install rake
I had version 0.9.2 already, just needed installing.
Reinstall the rake gem and it should work fine:
gem uninstall rake -v=0.9.2
gem install rake -v=0.9.2
If not, specify version '0.8.7' in your Gemfile.
If not using Bundler:
sudo gem install rake -v 0.8.7
sudo gem uninstall rake
Then choose to uninstall 0.9.0.
If like me you're stuck on rake 0.8.7, and you're using Rails 3.2.x then railties adds a requirement for Rake::DSL
To solve this, to the top of your Rakefile you should add:
module Rake
module DSL
end
end
I solved the same problem with the following steps:
In Gemfile:
gem 'rake', '0.9.2'
Then ran this on the console:
sudo bundle update rake
Then added the following lines to Rakefile:
require 'rake/dsl_definition'
include Rake::DSL
Rails 3.1.rc1 has been updated. For your own Rakefiles, you can add this before the call to load_tasks.
module ::YourApplicationName
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
https://gist.github.com/4cd2bbe68f98f2f0249f
UPDATE: Also noticed it's already answered here as well: Undefined method 'task' using Rake 0.9.0
I had the same issue and had to use the rake 0.8.7 gem instead of 0.9.0.
I am a Windows XP user and I had the same problem.
I entered gem "rake", "0.8.7" into the gemfile, and then typed the following from the command window.
bundle update rake
This fixed my problem.
Go to your project path
Type bundle install --path=vendor/bundle
Type bundle exec rake db:migrate
To start server type bundle exec rails s. Use bundle exec and you will be sure that you use right gems (required version) for your project.
Also I would recommend you to add vendor/bundle to .gitignore if you use git and make alias for bundle exec. If you use zsh you can follow this approach
Same as Branstar above - thanks Branstar!
OS: Windows Vista
Level: Completely new to Ruby on Rails
I already had Ruby 1.9.2 installed
I followed the instructions in Running Rails 3 on Windows.
All worked up until the "rake db:migrate" part which gave me the same output as original post.
I ran:
gem install rake
I ran again:
rake db:migrate
Then I was able to start the Ruby on Rails server and had everything in place.
Thanks again Branstar :-)
I feel for you (mikhailvs), it's really frustrating. I have been going crazy for almost one full day. I even uninstalled Ruby and all its dependent files and shutdown my PC, but I still got the same problem.
What I got from the error message is the problem with Rake 0.9.2. It seems like it wasn’t fully installed. So I had to reinstall gem install rake -v=0.9.2
I wasn’t sure if I have rake –v0.9.1 installed. So to make sure I’m safe I tried to remove that old version with gem uninstall rake -v=0.9.1. But is showed me the error message
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rake`
OK, so I checked all Rake directories on my PC, and found I only had Rake 0.9.2.
Then to check if everything went alright, I migrated with rake db:migrate. And it worked :)
I think I didn’t have Rake 0.9.1 because I clean-installed Ruby (rubyinstaller-1.9.2-p180 - on my Windows 7 system) and all gems as well. In the meantime Rake 0.9.2 wasn’t fully installed.
Uninstalling with "gem uninstall rake" worked for me, I had 2 versions installed, so I jest did a clean reinstall.
"rake db:create", to make sure the database exists
and then "rake db:migrate" to seal the deal.
I had the same issue using Rake 0.9.2.2. I solved this problem by using bundle exec.
For Rails 2.3 editing lib/tasks/rspec.rake like in this commit worked for me:
https://github.com/dchelimsky/rspec-rails/pull/11/files
Install rake 0.8.7 and uninstall 0.9.2.2
$ gem install rake -v 0.8.7
$ gem uninstall rake -v 0.9.2.2
Now use
$ bundle exec rake db:migrate
i think this will help you
;)
Run
bundle exec rake db:migrate
it works for me.
I'm having a really frustrating issue: Rake is being dumb.
Here's how the problem comes about:
$ rails new test_app
$ rails generate scaffold new_scaffold field1:string field2:text
Both of those work just fine, but then when I do this,
$ rake db:migrate
I get the following error.
(in /home/mikhail/test_app)
rake aborted!
uninitialized constant Rake::DSL
/usr/lib/ruby/1.9.1/rake.rb:2482:in `const_missing'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:8:in `<class:TaskLib>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:6:in `<module:Rake>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/tasklib.rb:3:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `require'
/usr/lib/ruby/gems/1.9.1/gems/rake-0.9.0/lib/rake/rdoctask.rb:20:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks/documentation.rake:1:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `load'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:15:in `block in <top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `each'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/tasks.rb:6:in `<top (required)>'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `require'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:214:in `initialize_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:139:in `load_tasks'
/usr/lib/ruby/gems/1.9.1/gems/railties-3.0.7/lib/rails/application.rb:77:in `method_missing'
/home/mikhail/test_app/Rakefile:7:in `<top (required)>'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `load'
/usr/lib/ruby/1.9.1/rake.rb:2373:in `raw_load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2007:in `block in load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:2058:in `standard_exception_handling'
/usr/lib/ruby/1.9.1/rake.rb:2006:in `load_rakefile'
/usr/lib/ruby/1.9.1/rake.rb:1991:in `run'
/usr/bin/rake:31:in `<main>'
I've looked about the Internet for similar/same errors, and people have had them. Just no one ever seems to solve the problem!
How do I fix this problem?
A tweet from DHH earlier. Rake .9.0 breaks Rails and several other things, you need to:
gem "rake", "0.8.7"
in your Gemfile.
I made some research just after my previous answer (sorry, I must do before it).
All problems are solved with Rake gem 0.9.2.. I followed these steps:
I installed gem install rake -v=0.9.2 (I had the 0.9.1 gem)
removed the 0.9.1 with gem uninstall rake -v=0.9.1
updated with bundle update
then the db:migrate showed a warning, WARNING: Global access to Rake DSL methods is deprecated. Please....
It was solved by adding the following to the Rake file.
module ::YourApplicationName
class Application
include Rake::DSL
end
end
I ommited the module ::RakeFileUtils extend Rake::FileUtilsExtend option sugested by #databyte.
It means that the Rake gem 0.9.2 works fine!
Going through Chapter 2 of Railstutorial (demo_app) and ran into this problem. I tried all of the other answers listed here, but couldn't get it to work until I did this:
Put this in your Rakefile above require 'rake':
require 'rake/dsl_definition'
via How to fix the uninitialized constant Rake::DSL problem on Heroku?
I also recommitted and pushed all files to Github and Heroku.
All I needed to do was use:
gem install rake
I had version 0.9.2 already, just needed installing.
Reinstall the rake gem and it should work fine:
gem uninstall rake -v=0.9.2
gem install rake -v=0.9.2
If not, specify version '0.8.7' in your Gemfile.
If not using Bundler:
sudo gem install rake -v 0.8.7
sudo gem uninstall rake
Then choose to uninstall 0.9.0.
If like me you're stuck on rake 0.8.7, and you're using Rails 3.2.x then railties adds a requirement for Rake::DSL
To solve this, to the top of your Rakefile you should add:
module Rake
module DSL
end
end
I solved the same problem with the following steps:
In Gemfile:
gem 'rake', '0.9.2'
Then ran this on the console:
sudo bundle update rake
Then added the following lines to Rakefile:
require 'rake/dsl_definition'
include Rake::DSL
Rails 3.1.rc1 has been updated. For your own Rakefiles, you can add this before the call to load_tasks.
module ::YourApplicationName
class Application
include Rake::DSL
end
end
module ::RakeFileUtils
extend Rake::FileUtilsExt
end
https://gist.github.com/4cd2bbe68f98f2f0249f
UPDATE: Also noticed it's already answered here as well: Undefined method 'task' using Rake 0.9.0
I had the same issue and had to use the rake 0.8.7 gem instead of 0.9.0.
I am a Windows XP user and I had the same problem.
I entered gem "rake", "0.8.7" into the gemfile, and then typed the following from the command window.
bundle update rake
This fixed my problem.
Go to your project path
Type bundle install --path=vendor/bundle
Type bundle exec rake db:migrate
To start server type bundle exec rails s. Use bundle exec and you will be sure that you use right gems (required version) for your project.
Also I would recommend you to add vendor/bundle to .gitignore if you use git and make alias for bundle exec. If you use zsh you can follow this approach
Same as Branstar above - thanks Branstar!
OS: Windows Vista
Level: Completely new to Ruby on Rails
I already had Ruby 1.9.2 installed
I followed the instructions in Running Rails 3 on Windows.
All worked up until the "rake db:migrate" part which gave me the same output as original post.
I ran:
gem install rake
I ran again:
rake db:migrate
Then I was able to start the Ruby on Rails server and had everything in place.
Thanks again Branstar :-)
I feel for you (mikhailvs), it's really frustrating. I have been going crazy for almost one full day. I even uninstalled Ruby and all its dependent files and shutdown my PC, but I still got the same problem.
What I got from the error message is the problem with Rake 0.9.2. It seems like it wasn’t fully installed. So I had to reinstall gem install rake -v=0.9.2
I wasn’t sure if I have rake –v0.9.1 installed. So to make sure I’m safe I tried to remove that old version with gem uninstall rake -v=0.9.1. But is showed me the error message
ERROR: While executing gem ... (Gem::InstallError)
cannot uninstall, check `gem list -d rake`
OK, so I checked all Rake directories on my PC, and found I only had Rake 0.9.2.
Then to check if everything went alright, I migrated with rake db:migrate. And it worked :)
I think I didn’t have Rake 0.9.1 because I clean-installed Ruby (rubyinstaller-1.9.2-p180 - on my Windows 7 system) and all gems as well. In the meantime Rake 0.9.2 wasn’t fully installed.
Uninstalling with "gem uninstall rake" worked for me, I had 2 versions installed, so I jest did a clean reinstall.
"rake db:create", to make sure the database exists
and then "rake db:migrate" to seal the deal.
I had the same issue using Rake 0.9.2.2. I solved this problem by using bundle exec.
For Rails 2.3 editing lib/tasks/rspec.rake like in this commit worked for me:
https://github.com/dchelimsky/rspec-rails/pull/11/files
Install rake 0.8.7 and uninstall 0.9.2.2
$ gem install rake -v 0.8.7
$ gem uninstall rake -v 0.9.2.2
Now use
$ bundle exec rake db:migrate
i think this will help you
;)
Run
bundle exec rake db:migrate
it works for me.