Ruby on Rails : Rake db:create -> Could not find gem - ruby-on-rails

I begin with ruby on rails and I'm trying to create my first blog. So i ran:
rails new blog -database=mysql
There was an error:
Gem::InstallError: The 'json' native gem requires installed build tools.
But since i saw a json directory in my blog's directory i didn't care.
So i run the command to create the database:
rake db:create --trace
And i had another error:
Could not find gem 'rails (= 3.1.3) x86-mingw32' in any of the gem sources listed in your Gemfile.
Run `bundle install` to install missing gems.
Does anybody knows what is the problem?

Also may need to run
bundle exec rake db:create

you can try "gem list | grep json" to check if json is already install.
Then, you can add following line in Gemfile (in your site's directory):
gem 'json'
and then
bundle install json or bundle update json
Good luck,

Related

How to avoid Error in deploy with Ruby on Rails

Whenever I try to deploy my system the following error occurs:
root#:/var/www/code# bundle exec rake assets:precompile db:migrate RAILS_ENV=production
rake aborted!
LoadError: incompatible library version - /var/www/code/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/nokogiri.so
/var/www/code/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri.rb:32:in `require'
I tried to make an update on all gems:
gem update
And I followed the "Incompatible library version on Ubuntu 16.04" issue, but yet it doesn't work.
Why does this happen?
I circled the uninstallation and installation code at the root of the project:
root#:/var/www/code# gem uninstall nokogiri
And then:
root#:/var/www/code# gem install nokogiri
My gem list shows:
root#:/var/www/code# gem list
- nokogiri (1.7.1)
But when I try to compile it appears again:
/code/vendor/bundle/ruby/2.3.0/gems/nokogiri-1.6.8/lib/nokogiri/nokogiri.so
Should I accomplish this within the gems/ folder?

Your bundle is locked to rake (12.0.0), but that version could not be found in any of the sources listed in your Gemfile.

I get the following error message when starting the rails server:
Your bundle is locked to rake (12.0.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 (12.0.0) has removed it. You'll need to update your bundle to a different version of rake (12.0.0) that hasn't been removed in order to install.
I specified gem 'rake', '12.0.0' in the gemfile but that doesn't fix it. I tried bundle update rake, deleting the Gemfile.lock and generating it with bundle exec bundle install. I also prepended `bundle exec1 to al my commands which does nothing.
My Gemfile.lock already specifies rake version 12.0.0, and there are no other versions installed.
See my gemfile:
http://pastebin.com/L4tVFWz9
And rakefile:
http://pastebin.com/K7p2ajsE
I tried the solutions suggested in Already activated rake version different than what Gemfile requires prevents rake commands
Different methods to solve this issue,
Step1:
gem install rubygems-bundler
gem regenerate_binstubs
Step2:
Remove the vendor/bundle directory.
Run bundle install to rebuild it
Step3:
Try, gem update bundler
Here is a link where the issue got solved. Check this is very useful
Try:
gem install rubygems-bundler
gem regenerate_binstubs
Not really a fundamental solution, but if you really have to run some Rails commands urgently and needs a temporary fix, try bundle exec rails c rather than bin/rails c.
Enter command :-
bundle update rake

Problems with migration from older ruby/rbenv

I faced with the following problem:
I update my OS X to Yosemite, switched to ruby 2.2.2 and decided to come back to my Octopress-based blog. Below I try to describe all my actions one by one, will be glad if someone tell me where I did something wrong.
So I cloned my page from github , checkout to source branch. But when I try to execute any rake command I get error:
rbenv: version `1.9.3-p194' is not installed
rbenv: version `1.9.3-p194' is not installed
I did:
> rbenv local --unset
> rake reharsh --trace
rake aborted!
LoadError: cannot load such file -- bundler/setup
MYPATH/Rakefile:2:in `<top (required)>'
Thus I install bundler:
> gem install bundler
> bundle install
Fetching gem metadata from http://rubygems.org/...........
Fetching version metadata from http://rubygems.org/...
Fetching dependency metadata from http://rubygems.org/..
Installing rake 0.9.2.2
etc
Finally:
> rake generate --trace
rake aborted!
Gem::LoadError: You have already activated rake 10.4.2, but your Gemfile requires rake 0.9.2.2. Prepending `bundle exec` to your command may solve this.
UPD: Following advices of K M Rakibul Islam, I changed in the gemfile rake version from 0.9.2 to 10.4 and added line gem 'iconv' to the gem file. After that rake generate start working.
As the error message suggests, you should run the rake command using bundle exec in order to run it in the context of your Gemfile:
bundle exec rake generate --trace
This should fix your issue.
Update
change this: gem 'rake', '~> 0.9.2' to gem 'rake', '~> 10.4.2' in your Gemfile and run: bundle install.

Ruby on rails error when running rails s

Um quite new to rails and um getting an error when run the command
rails s
it says
Could not find rake-0.9.2.2 in any of the sources
Run bundle install to install missing gems.
when I run bundle install nothing happened
my gem list has rake 0.9.2.2
what can go wrong?
my ruby version is 1.9.3
Thank you in advance
Remove all the versions of Rake ==> gem uninstall rake
Remove your gemfile.lock => rm Gemfile.lock
Remove gem 'rake' on your gemfile
Run bundle install
Install Rake manually : gem install rake --version=10.0.4
When you use command gem list, you will get a list of gem installed on your machine.
For example : rake (10.0.4, 10.0.3, 0.9.2.2)
Just see the console which gem is compatible with your application. It is already mentioned in the error log message.
Use
gem uninstall rake
Keep the suitable one and remove the version who is creating trouble. And then run rails s or bundle exec rails s
Try using rvm and go back to ruby 1.8.7 instead of 1.9.2. This fixed it for me. Don't forget to install rails again (sudo gem install rails while already on 1.8.7) if you have only installed rails for 1.9.3.]

Rake cannot find gems in vendor/gems

I'm trying to publish a Rails 3.1 (upgraded from 3.0) application. After submitting the code I ran
bundle install --path vendor/gems RAILS_ENV=production
It worked. I've got a directory vendor/gems/ruby/1.9.1, in which bin, cache, doc, gems and specifications are located. However, when I run a rake task I've got an error:
$ rake db:migrate RAILS_ENV=production
Could not find authlogic-3.0.3 in any of the sources
Run `bundle install` to install missing gems.
It's not a problem with authlogic, it's both in gems and specifications directories, and it was annotate mentioned in the error before I removed it from the gemfile.
What can be wrong?
I'm using Ubuntu 10.10, Ruby 1.9.2p0, Rails 3.1 and Rake 0.9.2. The code was deployed by capistrano, vendor directory is placed in shared folder and linked in the releases.
If you want to use the project's gems then you should use bundle exec command e.g.,
bundle exec rake db:create
also require authlogic gem in gem file.
gem 'authlogic'
First delete the whole gems directory from vendor/ folder. You should use this:
bundle install --path=vendor/gems
no needs for specifying the environment.

Resources