cannot start rails server -> cannot load such file -- mysql2/mysql2 (LoadError) - ruby-on-rails

My rails application cannot start because mysql2 load error.
I have tried many solutions, But none can't fix the problem.
Even the rake command can't be executed.
rake aborted!
LoadError: cannot load such file -- mysql2/mysql2
My gemfile is:
ruby '2.5.1'
gem 'rails', '~> 4.2.4'
gem 'mysql2', '~> 0.5.2'
Bundle installed successfully. Mysql installed correctly. Yet the error occurs on MacOS.

Simply, uninstall and reinstall with the following command:
gem install mysql2
If this is not working, you can try adding the following to your mysql_config:
gem install mysql2 -v 0.4.4 -- --with-mysql-config=/usr/local/Cellar/mysql#5.6/5.6.42/bin/mysql_config --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

Related

cannot load such file -- nokogiri/nokogiri (LoadError) MacOS

I'm trying to setup a Rails project but unfortunately it fails when running rails new railsapp. I get the in 'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError) error.
To fix this, I did cd railsapp and changed the gemfile to gem 'nokogiri', '~> 1.6', '>= 1.6.8' and ran gem install nokogiri -v 1.6.8 and bundle i but that still gives an error related to Nokogiri.
require': cannot load such file -- nokogiri/nokogiri (LoadError)
Also did the following things:
gem uninstall nokogiri
bundle install nokogiri
bundle update nokogiri
I have setup Ruby and Rails using https://gorails.com/setup/osx/11.0-big-sur
Rails 6.1.4.1
ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin20]

rails console giving error to add test-unit gem to gemfile

I am getting an error while running rails console:
`require': Please add test-unit gem to your Gemfile: `gem 'test-unit', '~> 3.0'`(cannot load such file -- test/unit/testcase) (LoadError)
If I add this gem to my Gemfile then rails console works fine. But why does it keep asking me to add this gem to my Gemfile?
Rails version 3.2.2
It's rails dependency: https://github.com/drapergem/draper/issues/690
Please read more about that: https://bugs.ruby-lang.org/issues/9711

how to know mongoid gem version?

I am new to ruby on rails and am trying to run my first application which connected to MongoDb. How do i know if I have Mongoid gem installed or if I have to install it? and what is the command to know the gem version.
In my rails application Gemfile I have added:
gem 'mongoid', '~> 5.0.0'
but it gives the error:
usr/local/lib/ruby/gems/2.3.0/gems/bundler-1.13.6/lib/bundler/resolver.rb:366:in `block in verify_gemfile_dependencies_are_found!': Could not find gem 'mongoid (~> 5.0.0.1)' in any of the gem sources listed in your Gemfile or available on this machine. (Bundler::GemNotFound)
I think the gem is not present in your local machine. So it's giving you error. Try running command
bundle install
or you can manually install this gem using console by this command
gem install mongoid -v 5.0.0
Hope it helps. Cheers!

Gem::LoadError for mysql2 gem, but it's already in Gemfile

Gem::LoadError
Specified 'mysql2' for database adapter, but the gem is not loaded.
Add `gem 'mysql2'` to your Gemfile
This error occurred while loading the following files:
active_record/base
This is the error I get on running rails server.
The mysql2 gem has been added to the Gemfile as well.
I've done bundle install, and tried restarting the server but still get the error.
If you have this error when upgrading to rails 4.2.4 (also with rails 4.1.5) try using this version of mysql2:
gem 'mysql2', '~> 0.3.18'
Apparently mysql2 isn't still compatible with newer version of rails because rails 4.2.4 is pretty new as the time of answering this question by me 8 September 2015 so use the above line in your Gem file and run:
bundle install
You should be good to go
It worked for me when I specified a mysql2 gem version before the newest one (0.4.0).
For some reason there is a problem with Rails 4.2.4 and that gem 0.4.0. So, to solve the problem I just specified the previous gem released: 0.3.20 and it worked fine for me!
gem 'mysql2', '~> 0.3.20'
bundle install
You can check all the gems versions here: https://rubygems.org/gems/mysql2/versions
Change to
gem 'mysql2', '~> 0.3.18'
in your Gemfile.
This thread on the official mysql2 Github says to do this. You need to declare that version number if you're rails version 4.x.x.
https://github.com/brianmario/mysql2/issues/675
Then run bundle update mysql2.
I got the same error after an upgrade to Rails 4.1 and I managed to resolve it by updating mysql2. Run this in your rails app folder:
$ bundle update mysql2
This issue may occur if you're using newer version of rails > 4
Do these two simple steps, it will work.
Open your Gemfile and find the below line
gem 'mysql2'
replace that line with a specific mysql version like below
gem 'mysql2', '~> 0.3.18'
Now stop the server and run bundle
bundle install
Now restart your server. It should work.
rails s
Being Beginner to the ruby i could not figure out the line
gem 'mysql2', '~> 0.3.18'
it simply means go to your rails project folder and then there is
line for mysql2 it will be like 0.4* so you can change it to
gem 'mysql2', '~> 0.3.18'
and as we have new definition, we have to rebuild the dependency so to do that simple command as explained on the top bundle install
It doesn't load mysql2 gem because new version of mysql2(0.4.1) gem unable to load the mysql2_adaptor. This is working for me.
gem 'mysql2', '~> 0.3.13'
and run
bundle install
I had the same error and this is because Rails 4.1 requires minimum mysql2 version 0.3.13, and maximum compatible with Windows is version 0.3.11.
So I edited file c:\RailsInstaller\Ruby1.9.3\lib\ruby\gems\1.9.1\gems\activerecord-4.1.1\lib\active_record\connection_adapters\mysql2_adapter.rb and changed line gem 'mysql2', '~> 0.3.13' to gem 'mysql2', '~> 0.3.11', and it works so far.
Here is how I fixed this:
bundle config
bundle config --delete without
bundle install --deployment --without development test postgres
Credits:
How do you undo bundle install --without
It doesn't load mysql2 gem because new version of mysql2 (>= 0.4.0) gem unable to load the mysql2_adaptor. Can you try this?
gem 'mysql2', '~> 0.3.13'
Hopefully, it should work.
I solved the problem, installing the mysql2 gem local (gem install mysql2, bundle install) and adding the following line to the Gemfile:
gem 'mysql2'
Setting the mysql2 adapter in database.yml
adapter: mysql2
was also important!
I'm brand spanking new to Ruby on Rails and websites but hears what worked for me.
I had to change my gemfile, gem 'mysql2' to gem 'mysql2', '~> 0.3.13'
then in rails i typed bundle install
then i tried rails s and got errors
so then i tried bundle update mysql2
then in rails typed rails s, and it worked
I solved the problem, installing the libmysqlclient-dev.
sudo aptitude install libmysqlclient-dev
and later run bundle.
I have previously installed mysql2 0.4.5 but that was giving me this error so i have installed another version of mysql2 by:
gem install mysql2 --version 0.3.20
Hope this solves your problem.

Could not find rake-0.9.2.2 in any of the sources

This is an odd one. I'm getting this error when I run rake to do tests but not when I migrate. I'm running RVM, the shell dump below should give any information you need.
Any help would be greatly appreciated. I've seen a few other people with this issue, but no solutions that worked for me yet (or them).
Thanks.
$ rake
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Errors running test:units, test:functionals, test:integration!
$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-darwin11.4.0]
$ rails -v
Rails 3.1.6
$ more .rvmrc
rvm ruby-1.9.3-p194#...
$ rake db:rollback
== AddAllLocationsToAlert: reverting =========================================
-- remove_column(...
-> 0.0320s
== AddAllLocationsToAlert: reverted (0.0321s) ================================
------- EDIT::::
I have since upgraded to the latest Rails - 3.2.6. The error still occurs, even if I use 'bundle exec'. (This is not new to 3.2.6 - I was still getting the issue under 3.1) The undefined method is new though.
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
$ bundle exec rake
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Could not find rake-0.9.2.2 in any of the sources
Run `bundle install` to install missing gems.
Errors running test:units! #<NoMethodError: undefined method `[]' for nil:NilClass>
Errors running test:functionals! #<RuntimeError: Command failed with status (7): [/Users/ben/.rvm/rubies/ruby-1.9.3-p194/bin...]>
Errors running test:integration! #<RuntimeError: Command failed with status (7): [/Users/ben/.rvm/rubies/ruby-1.9.3-p194/bin...]>
My Gemfile, as requested:
source 'http://rubygems.org'
gem 'rails', '3.2.6'
group :assets do
gem 'sass-rails', " ~> 3.2.5"
gem 'coffee-rails', "~> 3.2.1"
gem 'uglifier', '>= 1.2.6'
end
gem 'jquery-rails'
gem 'rake'
gem "mysql2"
gem "squeel"
gem 'tinymce-rails'
gem 'dynamic_form'
gem 'will_paginate'
gem 'devise'
gem 'whitelist'
gem 'rmagick'
gem 'json'
gem 'paperclip'
gem 'acts_as_list', :git => 'https://github.com/swanandp/acts_as_list'
gem 'htmlentities'
gem 'formtastic'
# Bundle gems for the local environment. Make sure to
# put test-only gems in this group so their generators
# and rake tasks are available in development mode:
# group :development, :test do
# gem 'webrat'
# end
gem 'rake', ">=0.9.2" # in your Gemfile
then
$ bundle install
then
$ bundle exec rake
if above not worked :
$ rvm all do gem install rake -v 0.9.2.2#install rake to all ruby versions
then run rake again
If you're using bundler (and with rails, you probably do), always run rake like this:
bundle exec rake
This will pick up gems specified in your Gemfile.

Resources