Bundler won't install mysql2 - ruby-on-rails

First of all I've gone through dozens of posting here on SO and google and haven't been able to find an answer.
I'm trying to install mysql2 with bundler and it won't do it.
Running on Ubuntu Server 11.04 Natty
Here's some background info:
ruby -v
ruby 1.8.7 (2012-02-08 patchlevel 358) [x86_64-linux]
gem -v
1.8.24
rails -v
Rails 3.2.5
$ mysql --version
mysql Ver 14.14 Distrib 5.1.62, for debian-linux-gnu (x86_64) using readline 6.2
I have gem "mysql2", "~> 0.3.11" in my Gemfile
When I do bundle install it goes through the process and it finishes successfully (No Errors) but it doesn't install mysql2. When I do bundle show, mysql2 is not listed.
I've tried a gazillion of things recommended here and on forums and still can't get mysql2 to install with bundler.
Any ideas?
Thanks.

For mysql2 you need to install the dev files on your server.
try first:
sudo apt-get install libmysqlclient-dev
Then check first your GemFile in your RoR App Dir - I have this line in my GemFile:
gem 'mysql2', '0.3.11'
run bundle:
bundle install
or try the command from Emily first then run bundle install:
gem install mysql2 -v=0.3.11
bundle install
I hope it helps

So after many tries, reading, and pulling my hair out I found out what was the problem, so I'm posting it for those that might run into the same situation.
The reason why bundler wouldn't install mysql2 is because the gem was inside this platforms structure, see below:
platforms :mri_19, :mingw_19 do
group :mysql do
gem "mysql2", "0.3.11"
end
end
So all I did was to move just gem "mysql2", "0.3.11" by itself to the top of the Gemfile and run bundle install and that did it! Now mysql2 is listed under bundle show and my rails application is running now.
Thanks every one that tried to help!

Related

Running bundle install with modifier on certain gem

I'm trying to work on a project that uses the mysql2 gem, version 0.3.17 specifically.
I can get this to install by running:
gem install mysql2 -- --with-mysql-dir=C:\mysql\connector -v '0.3.17'
However after doing this (in the projects directory), and then run bundle install, it fails with the message
An error occurred while installing mysql2 (0.3.17), and Bundler cannot continue. Make sure that `gem install mysql2 -v '0.3.17'` succeeds before bundling.
Is there any way to run something like
bundle install -- --with-mysql-dir=C:\mysql\connector -v '0.3.17'
? I'm guessing I would need to specifiy the mysql2 gem in the command but I've looked on http://bundler.io/v1.3/man/bundle-install.1.html and can't seem to find anything.
My other option would be to simply point it to the gem I've already installed if that's possible.
Thanks in advance.

Ruby on Rails cannot bundle install

Ruby version: 2.1.5p273
Rails version: 4.2.0
Gem Version: 2.2.2
OS: Windows 7 x64
Hello, I am very very new to rails programming. I am trying to start learning, but cannot because of these problems.
I created a rails app
I type: >rails new app
I then navigate to the created folder
I type: >rails server
It tells me
"Run 'bundle install' to install missing gems."
I do so and it than tells me:
"Make sure that 'gem install debugger-linecache -v '1.2.0' succeeds before bundling'"
after installing said gem I try bundle install again, but it than repeats the same error with a different gem.
""Make sure that 'gem install *random gem* -v '*random version*' succeeds before bundling'""
I hardly have any idea what I'm doing here. How can I get this server running?
i started to write an answer, and then saw you comment,
but for everyone out there who need an answer and didn't notice your comment:
Try this,
first run:
bundle update
and then try to bundle install
if its not working, install bundler:
gem install bundler
and now run bundle install
Solved by using the following two commands: gem update --system gem install bundler

Error in running rails server

I got this error
Could not find mysql2-0.3.13 in any of the sources
Run `bundle install` to install missing gems.
I tried to gem install mysql2 but without luck, it didn't fix it. I'm using wampp server and copied the libmysql.ddl to the bin folder of ruby. I also tried adding the path to the gem install just like this.
gem install mysql2 --platform=ruby -- ‘-with-mysql-lib=”C:\wamp\bin\mysql\mysql5.5.24\lib” -with-mysql-include=”C:\wamp\bin\mysql\mysql5.5.24\include”‘
Any ideas on how to fix this? THanks!
First, make sure you have mysql installed on your machine.
If you have an Ubuntu distribution, try:
sudo apt-get install libmysql-ruby libmysqlclient-dev
then try to install the gem again.
I installed mysql2 from sources like this
# i experienced some troubles with mysql2 0.3.13 installing
gem fetch mysql2 -v 0.3.12
gem install mysql2-0.3.12.gem -- ' --with-mysql-include="c:\Program Files (x86)\MariaDB 5.5\include\mysql" --with-mysql-lib="c:\Program Files (x86)\MariaDB 5.5\lib" '
But after each Gemfile updating and bundle install, bundler is installing precompiled version of mysql2 gem and it's very annoying. After manual removing precompiled gem rails app started successfully
P.S. You also need installed Ruby DevKit.

Ubuntu 12.04 - RubyOnRails - gem install mysql2 seems to install but fails when i do: gem mysql2 - Unknown command mysql2

I'm a Ror newbe and I'm attempting to create my first webapp with rails.
I'm encountering a problem when I installed gem mysql2:
This is my actual configuration:
ruby -v: ruby 1.9.3p194 (2012-04-20 revision 35410) [x86_64-linux]
rails -v: Rails 3.2.3
gem -v: 1.8.24
michele#michele:~/rails/my_app$ gem install mysql2
Building native extensions. This could take a while...
Successfully installed mysql2-0.3.11
1 gem installed
Installing ri documentation for mysql2-0.3.11...
Installing RDoc documentation for mysql2-0.3.11...
After this I edited the database.yml and I run:
rake db:create
it returns:
rake aborted!
Please install the mysql2 adapter: `gem install activerecord-mysql2-adapter` (mysql2 is not part of the bundle. Add it to Gemfile.)
So, when finally I try to install it I get the error:
michele#michele:~/rails/my_app$ gem install activerecord-mysql2-adapter
ERROR: Could not find a valid gem 'activerecord-mysql2-adapter' (>= 0) in any repository
ERROR: Possible alternatives: activerecord-jdbch2-adapter, activerecord-jdbcmysql-adapter, activerecord-postgis-adapter, activerecord-jdbc-adapter, activerecord-odbc-adapter
Obviously I installed properly the others adapters but they don't fit with my needing of mysql2.
Nothing else, I'm just stacked here. :)
Better late than never:
1) install mysql support for RoR
on ubuntu sudo apt-get install libmysql-ruby libmysqlclient-dev
2) create rails app
rails new mysql_app -d mysql
3) edit config/database.yml
to set your username&password&other details.
Mainly i'm writing this not to forget myself... )
Try creating a brand new project like so
rails new -d=mysql
this should initialize the Gemfile and the config/database.yml with the right values
can you past your Gemfile in your question?
EDIT
Replace gem 'sqlite3' with gem 'mysql2' and bundle install. then you'll need to update the config/database.yml, take a look at what is generated with in the new project I suggest in the first line
edit
remove the socket line, you should be fine with something like:
development:
adapter: mysql
database: whatever_is_there
username: your_username
password: your_pwd
host: localhost
encoding: utf8

could not find gem 'mysql2..' when running rails script/generate scaffold command

I got this error:
Could not find gem 'mysql2 (>= 0, runtime)' in any of the gem sources.
Try running `bundle install`.
when trying:
rails script/generate scaffold post title:string
I am on a mac osx, rails 1.8.7, 3.0
On ubuntu you may need to install library for mysql first.
sudo apt-get install libmysqlclient-dev
And then you can install
gem install mysql2
or even better way is to use rvm
rvm gem install mysql2
You use rails script/generate … with rails 3.0? Maybe you upgraded rails 2.x project? With rails 3 you should use rails generate … or shorter rails g ….
About missing gem: run bundle install as asked for :)
If you use the Mac, this will help you (I also had been on this error for 2 hours).
brew install mysql
brew install openssl
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
bundle install
The main point is that you have to first install the openssl for setup the mysql2 gem on Mac.

Resources