3

I am using Linux Mint and I just started to learn Ruby on Rails. I'm following Lynda.com tutorials and I am getting stuck with setting up mysql. I tried everything that people asked before and I cannot find a solution. Let me explain. I have all things installed correctly.

matth@MatijaComp ~ $ ruby -v
ruby 2.2.2p95 (2015-04-13 revision 50295) [x86_64-linux]
matth@MatijaComp ~ $ rails -v
Rails 4.2.3
matth@MatijaComp ~ $ mysql --version
mysql  Ver 14.14 Distrib 5.5.44, for debian-linux-gnu (x86_64) using readline 6.3

when I start a project with "-d mysql", start my mysql server, run "rake db:create", configure database.yml file to fill the password, then simply do "rails server". Hope I explained all my steps, maybe I forgot something, but I think I tried everything. Setting the password is not the problem. ( without mysql rails server works fine)

[2015-07-25 02:58:46] INFO  WEBrick 1.3.1
[2015-07-25 02:58:46] INFO  ruby 2.2.2 (2015-04-13) [x86_64-linux]
[2015-07-25 02:58:46] INFO  WEBrick::HTTPServer#start: pid=11689 port=3000


Started GET "/" for 127.0.0.1 at 2015-07-25 02:58:48 +0200

Gem::LoadError (Specified 'mysql2' for database adapter, but the gem is not loaded. Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).):
  activerecord (4.2.3) lib/active_record/connection_adapters/connection_specification.rb:177:in `rescue in spec'
  activerecord (4.2.3) lib/active_record/connection_adapters/connection_specification.rb:174:in `spec'
  activerecord (4.2.3) lib/active_record/connection_handling.rb:50:in `establish_connection'
  activerecord (4.2.3) lib/active_record/railtie.rb:120:in `block (2 levels) in <class:Railtie>'
  activesupport (4.2.3) lib/active_support/lazy_load_hooks.rb:38:in `instance_eval'
  activesupport (4.2.3) lib/active_support/lazy_load_hooks.rb:38:in `execute_hook'
  activesupport (4.2.3) lib/active_support/lazy_load_hooks.rb:45:in `block in run_load_hooks'
  activesupport (4.2.3) lib/active_support/lazy_load_hooks.rb:44:in `each'
  activesupport (4.2.3) lib/active_support/lazy_load_hooks.rb:44:in `run_load_hooks'
  activerecord (4.2.3) lib/active_record/base.rb:315:in `<module:ActiveRecord>'
  activerecord (4.2.3) lib/active_record/base.rb:26:in `<top (required)>'
  activerecord (4.2.3) lib/active_record/migration.rb:383:in `connection'
  activerecord (4.2.3) lib/active_record/migration.rb:370:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.3) lib/active_support/callbacks.rb:84:in `run_callbacks'
  actionpack (4.2.3) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  web-console (2.2.1) lib/web_console/middleware.rb:39:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  railties (4.2.3) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.3) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.3) lib/rails/rack/logger.rb:20:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  rack (1.6.4) lib/rack/methodoverride.rb:22:in `call'
  rack (1.6.4) lib/rack/runtime.rb:18:in `call'
  activesupport (4.2.3) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  actionpack (4.2.3) lib/action_dispatch/middleware/static.rb:116:in `call'
  rack (1.6.4) lib/rack/sendfile.rb:113:in `call'
  railties (4.2.3) lib/rails/engine.rb:518:in `call'
  railties (4.2.3) lib/rails/application.rb:165:in `call'
  rack (1.6.4) lib/rack/lock.rb:17:in `call'
  rack (1.6.4) lib/rack/content_length.rb:15:in `call'
  rack (1.6.4) lib/rack/handler/webrick.rb:88:in `service'
  /usr/share/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:138:in `service'
  /usr/share/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/httpserver.rb:94:in `run'
  /usr/share/rvm/rubies/ruby-2.2.2/lib/ruby/2.2.0/webrick/server.rb:294:in `block in start_thread'

It always shows this error, whatever I try to do. Even if I remove gems for mysql, comment the database in database.yml, it still doesn't want to work. Thank you!

mightymatth
  • 93
  • 1
  • 9

1 Answers1

2

First, try running bundle exec rails s and see if it gives a different result. If it complains that you haven't run bundler, first run bundle install. A Gem::LoadError generally means there's an issue with your Gemfile, and sometimes -- e.g., if you installed Ruby via your system package manager or an installer -- the rails binary will be linked to your system gems and not your project's gems. Prefixing commands with bundle exec ensures they run in the context of your current Gemfile.

Robert Nubel
  • 5,300
  • 1
  • 11
  • 26
  • now I explored new problem with rails.. when i type `rails -v` outside project it says that correct version is installed, but when I enter in the project directory it says that `Warning: You're using Rubygems 1.8.23 with Spring. Upgrade to at least Rubygems 2.1.0 and run "gem pristine --all" for better startup performance.` and when i try to update rubygems it says its updated. – mightymatth Jul 25 '15 at 10:07
  • Thanks, I have fixed my problem by removing all things connected with RVM ( [rvm-removing-guide](http://stackoverflow.com/questions/3558656/how-can-i-remove-rvm-ruby-version-manager-from-my-system) )because it causes some problems with gems. It might happened because I used few installing guides in the same time. Then I used one guide and installed ruby and rails with `rbenv` ( [ror-installing-guide](https://gorails.com/setup/ubuntu/14.10) ). – mightymatth Jul 25 '15 at 10:32