开发者

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

开发者 https://www.devze.com 2023-03-11 05:29 出处:网络
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

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.


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

cheers


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.

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消