ItGo.me Focus on IT Recommend

Home > ruby on rails - How do I install the mysql2 gem on ubuntu, when I'm using rails3 via rvm?

ruby on rails - How do I install the mysql2 gem on ubuntu, when I'm using rails3 via rvm?

I'm trying to figure my way around the vastly complex maze that is rails configuration. So far, I'm managed to set up rvm on ubuntu (for some reason, ruby is outdated in the ubuntu repo's). I've managed to set up a rails project. I want my test project to use mysql rather then mysqlite.

When I tried 'rake db:migrate', I got an error: "!!! Missing the mysql2 gem. Add it to your Gemfile: gem 'mysql2'"

When I try 'gem install mysql', I get an error, telling me that I need to provide parameters to the installation command. However, the list of parameters is huge, and I have no idea which ones to select.

How can I get rails3 via rvm running on ubuntu with mysql ?

Thanks.

ruby-on-rails ruby ubuntu rvm
asked Jun 9 '11 at 4:05 bob 83 2 6

 | 

5 Answers
5

I had the same problem, all you need to do is to install the libmysqlclient-dev first.

cheers


answered Jul 7 '11 at 0:11 thermosilla 321 1 3

 | 

First, you need mysql installed. You can install it using Ubuntu's package manager. No special steps needed. You also need to initially create your database and user using the mysql tool. This link shows how to do that:

http://www.tutorialspoint.com/ruby-on-rails/rails-database-setup.htm

Second, you need to have the mysql2 gem listed in your Gemfile. This tells Rails to go ahead and use that gem. You need a line like this:

gem 'mysql2', '< 0.3'

I'm specifying the version to be less than 0.3 because I'm using Rails 3.0.7 and version 0.3 and higher are for Rails 3.1. Also, be sure to use the mysql2 gem and not mysql - it seems to handle character encoding better.

Third, run "bundle install" so Rails downloads and installs the mysql2 gem.

Lastly, you need to change your database.yml file to put in the connection information for your database like so:

development:
  adapter:  mysql2
  database: your_database_name
  username: your_username
  password: your_password
  encoding: utf8

The encoding part is just what I'm using, you may need something different. This entry tells Rails how to find your database in the development environment.

Recommend:ruby on rails - rvm gem install error

I try to install a gem I get an error gem install railsERROR: While executing gem ... (Errno::EACCES) Permission denied - /Users/da/.rvm/gems/ruby-1.9.2-p180/gems/bundler-1.0.11/.gitignore It works when I do sudo, but I never had to do thi

Once that's all in place, things should work.


answered Jun 9 '11 at 16:44 jdc 595 2 6      I have mysql installed, and I have the mysql2 gem listed in my gemfile. I've actually completely given up on this one, and removed my rvm installation. It's too hard for me. Ruby on ubuntu just seems to be to difficult. –  bob Jun 11 '11 at 13:07

 | 
sudo apt-get install libmysql-ruby libmysqlclient-dev

If the above command does not work because libmysql-ruby cannot be found, the following should be sufficient:

sudo apt-get install libmysqlclient-dev

On Red Hat/CentOS and other distributions using yum:

sudo yum install mysql-devel

On Mac OS X with Homebrew:

brew install mysql

then run

bundle install

to install to gems as listed in gemfile


edited Jun 24 '15 at 9:40 user2849835 121 8 answered Sep 16 '14 at 15:56 Shalto 20 4

 | 

Maybe this link can help you. http://www.dreamincode.net/forums/blog/1662/entry-3490-day-6-installing-rails-gem-rvm-etc/


answered Jun 9 '11 at 4:59 Bjoernsen 1,335 19 32      I'm afraid that that link doesn't help. It doesn't supply any information on what you need to do when installing the mysql or mysql gems with rvm. It just gives the normal way, which doesn't produce the same issues. –  bob Jun 9 '11 at 7:46      For the installation of the mysql gem, maybe you can use something like this -> "gem install mysql -- --with-mysql-config=/usr/local/mysql/bin/mysql_config" –  Bjoernsen Jun 9 '11 at 8:14

 | 

I believe you need to add gem name to your Gemfile, located in your projects root:

It should read something like this:

source 'http://rubygems.org'

gem 'rails', version
gem 'mysql', version

Where version is the the gem version you'd like to install, and will have a bunch of other information by default.

Then, navigate to your project directory and run the bundle command and you should be set.


answered Jun 9 '11 at 5:06 Kombo 1,166 23 54      Doing this produces the same error that I got before, only surrounded by more text. It's the same issue: the mysql or mysql2 gem needs to be given options to be installed, but the error code doesn't tell me which options it needs or why. Again - the issue seems to be specific to installing rails using rvm –  bob Jun 9 '11 at 7:49

 | 

Recommend:How to install rvm/ruby/rails via chef

VM/Ruby 1.9.3 via Chef I am trying to set up a Ruby on Rails environment in Windows using VirtualBox/Vagrant. The installation of VirtualBox and Vagrant are pretty self-explanatory, but delving into the configuration of Vagrant and things l

oriUlr:http://stackoverflow.com/questions/6287963/how-do-i-install-the-mysql2-gem-on-ubuntu-when-im-using-rails3-via-rvm

------splitte line----------------------------