4

I'm bit confused by "easy" working with ruby on rails, cause I already spend three days by trying create an app.

I work on site5 hosting, and try to create new app. step by step:

$ rails new app -d mysql

$ gem install mysql

$ gem install mysql2

and after

$ rake db:create

it report about error

Could not find gem 'mysql2 (~> 0.2.6, runtime)' in any of the gem sources listed in your Gemfile.

I google it, but still can't fix problem. Can anybody help?

3
  • When you run 'gem list' do you find the mysql gem in the list?
    – Srisa
    Jun 23, 2011 at 7:10
  • [email protected] [~/public_html/ab.awithy.ru/app]# gem list mysql *** REMOTE GEMS *** mysql (2.8.1, 2.7.3) mysql-inspector (0.0.6) mysql-xml (0.1.1) mysql2 (0.3.6, 0.2.6) mysql2_bigint (0.2.6.1) mysql2_model (0.1.2) mysql2mysql (0.0.2) mysql2psql (0.1.0) mysql2xxxx (0.1.1) mysql_backup (0.2.1) Jun 23, 2011 at 7:20
  • does that mean, what I have mysql gem? Jun 23, 2011 at 7:21

4 Answers 4

5

Running rails new app -d mysql will automatically add the required gems to your Gemfile, so you shouldn't need to install them manually with the gem command. Try the following:

$ rails new app -d mysql
$ cd app
$ bundle install
$ rake db:create

I suspect the tutorial you're following is for an older version of Rails. With rails 3, you should be using bundler for all gem management.

1
  • yeah, thanks! problem was on my host, I should type $bundle install vendor/bundle Jun 23, 2011 at 14:47
1

This is how you do it.

gem list --local

Displays list of installed gems. Do you see mysql2 gem? If mysql2 is not installed run

gem install mysql2

You are now ready to launch a new rails app. Go to the desired directory and run

rails new my_app -d mysql

This will create a new rails app in directory my_app with mysql binding. Navigate to the app directory and run

rake about

If every thing is fine you should see the following

Database adapter         mysql2

Fire your favourite text editor and go to config/database.yml Notice there are three databases, one each for development, test, and production. User will be "root" but without password. Enter the root password at all three places. You can also change user.

next open mysql and create three databases

mysql -u root -p
create database my_app_production;
create database my_app_test;
create database my_app_development;
exit

next in the terminal type

rails generate scaffold TableName name:string due:date etc...
rake db:migrate

...and you are done. Hope this helps.

0

Have you tried running gem install mysql2?

If that is not working, try following this tutorial

It looks like your problems are generated by the missing mysql gem.

Here is another question regarding its installation. See if any of the solutions from there apply to you too

2
  • look above, I already tried $gem install mysql. also, I think this tutorial created for windows, but I need to make app on remote linux server Jun 23, 2011 at 7:16
  • I edited my answer to give you another source of inspiration :) Jun 23, 2011 at 7:23
0

I ran into a similar problem. (I'm using rvm). I think I ran some code like:

The number after libmysqlclient may be different. And the path may be different for you too, but the concept should be similar.

sudo install_name_tool -change libmysqlclient.18.dylib /usr/local/mysql/lib/libmysqlclient.18.dylib ~/.rvm/gems/ruby-1.9.2-p136\@rails3tutorial/gems/mysql2-0.2.7/lib/mysql2/mysql2.bundle

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.