Failed to install mysql2 gem on Ubuntu 14 - mysql

I'm running Ubuntu 14 and when I try to run rails server but I get this error:
Could not find gem 'mysql2 (>= 0) ruby' in the gems available on this machine.
Run bundle install to install missing gems.
So I run the bundle install and then I get the following error.
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.1.0/gems/mysql2-0.3.16 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.
So I run gem install mysql2 -v '0.3.16' and it installs successfully however when I run bundle install again it gives me the same error:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.1.0/gems/mysql2-0.3.16 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/mysql2-0.3.16/gem_make.out
An error occurred while installing mysql2 (0.3.16), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.16'` succeeds before bundling.

Start again from scratch and this time you should install RVM as it is really good at handling all this stuff for you.
http://rvm.io/rvm/install
Make sure you get all the dependencies first, this code will check to see what you have and don't have:
for name in {bash,awk,sed,grep,ls,cp,tar,curl,gunzip,bunzip2,git,svn} ; do which $name ; done
Its also worth looking at the prerequisites page: http://rvm.io/rvm/prerequisites
You can run the below code to install rvm with Ruby 2.1.1 and Rails:
\curl -sSL https://get.rvm.io | bash -s stable --rails
Then To start using RVM:
/bin/bash --login
Its definitely worth using RVM it will make your life much easier when managing your ruby versions, gems etc, just make sure you read through the webpage so that you know how to use it.

Related

how to run bundle install on ubuntu 16.04 LTS

I have a problems to run the bundle install on my PC. The return is:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
current directory: /tmp/bundler20170309-28068-jc2jotsqlite3-1.3.13/gems/sqlite3-1.3.13/ext/sqlite3
/usr/bin/ruby2.3 -r ./siteconf20170309-28068-19m0tjz.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /tmp/bundler20170309-28068-jc2jotsqlite3-1.3.13/gems/sqlite3-1.3.13 for inspection.
Results logged to /tmp/bundler20170309-28068-jc2jotsqlite3-1.3.13/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out
Using turbolinks-source 5.0.0
An error occurred while installing json (1.8.6), and Bundler cannot continue.
Make sure that gem install json -v '1.8.6' succeeds before bundling.
I try run gem install json -v '1.8.6' but it did not work.
Can someone help me?
Sorry my english.

Rails - mysql2 installation error

I have recently installed rvm to use rails5 along with rails3.x version in my current system. When i tried to create new rails5 application, i have got the below error
Could not find proper version of railties (3.2.13) in any of the sources
Run `bundle install` to install missing gems.
And when i try to do bundle install, i got stuck with this
gem install mysql2 -v '0.3.11'
Building native extensions. This could take a while...
/home/himanth/.rvm/rubies/ruby-2.3.1/lib/ruby/site_ruby/2.3.0/rubygems/ext/builder.rb:73: warning: Insecure world writable dir /home/himanth/.rvm/gems in PATH, mode 040777
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/home/himanth/.rvm/rubies/ruby-2.3.1/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
compiling mysql2_ext.c
In file included from ./client.h:11:0,
from ./mysql2_ext.h:39,
from mysql2_ext.c:1:
/home/himanth/.rvm/rubies/ruby-2.3.1/include/ruby-2.3.0/ruby/backward/rubysig.h:14:2: warning: #warning rubysig.h is obsolete [-Wcpp]
In file included from ./mysql2_ext.h:39:0,
from mysql2_ext.c:1:
./client.h: In function 'rb_thread_blocking_region':
./client.h:23:3: error: 'TRAP_BEG' undeclared (first use in this function)
./client.h:23:3: note: each undeclared identifier is reported only once for each function it appears in
./client.h:25:3: error: 'TRAP_END' undeclared (first use in this function)
mysql2_ext.c: At top level:
./client.h:16:1: warning: 'rb_thread_blocking_region' defined but not used [-Wunused-function]
make: *** [mysql2_ext.o] Error 1
make failed, exit code 2
Gem files will remain installed in /home/himanth/.rvm/gems/ruby-2.3.1#rails5/gems/mysql2-0.3.11 for inspection.
Results logged to /home/himanth/.rvm/gems/ruby-2.3.1#rails5/extensions/x86_64-linux/2.3.0/mysql2-0.3.11/gem_make.out
An error occurred while installing mysql2 (0.3.11), and Bundler cannot continue.
Make sure that `gem install mysql2 -v '0.3.11'` succeeds before bundling.
Got stuck with this for quite some time, any help would be much appreciated.
From Terminal try following:
For Ubuntu:
sudo apt-get install mysql-client libmysqlclient-dev
sudo gem install mysql2
For Mac:
brew install mysql
sudo gem install mysql2
try the below:
gem install rails
After that install mysql server
sudo apt-get install mysql-client libmysqlclient-dev
then bundle install

gem install mysql2 -v '0.3.18' fails

I'm using OS X 10.9.5. Recently updated ruby to 2.2.1 and it messed up everything in my system. I'm having a hard time with this. I'm trying to do a bundle install on my project and it fails saying
Make sure that gem install mysql2 -v '0.3.18' succeeds before bundling
I was going through the same issue yesterday. All I did was to uninstall mysql and reinstall it, then re install mysql2 and it worked. I', trying the same thing now but it wouldn't let me install mysql2.
I tried,
gem install mysql2 'gem install mysql2 -v '0.3.18'
Also Tried,
gem install mysql2 -v '0.3.18' -- --with-mysql-dir=/usr/local/bin/mysql
It gives me the following error,
LInk to the error.
I'm thinking if this could be a gcc issue. when I run which gcc it gives me gcc: aliased to /usr/local/bin/cpp-4.8. could this be the reason?
can anyone guide me in fixing this? thanks in advance
I got the same errors when I deploy my app to VPS(Ubuntu 14.04)
What I did to make it out is
sudo apt-get install libmysqlclient-dev
Not sure for OS X , but hope this can help you.

Unable to install "mysql2" gem on Linux (CentOS)

I am unable to install the "mysql2" gem on my CentOS linux machine.
I recently install mysql following the following tutorial: http://www.rackspace.com/knowledge_center/article/installing-mysql-server-on-centos
When I try to download "mysql2" gem I get the following log:
[root#vc2cmmka035538n ruby]# gem install mysql2
ERROR: Could not find a valid gem 'mysql2' (>= 0) in any repository
ERROR: Possible alternatives: mysql
Environment info:
Rails 3.2.3
ruby 1.8.7 (2011-06-30 patchlevel 352) [x86_64-linux]
gem -v 1.8.24
From their github page, quoted
This gem links against MySQL's libmysqlclient C shared library. You may need to install a package such as libmysqlclient-dev, mysql-devel, or other appropriate package for your system.
So, you might wanna install those packages first. Then you can even manually compile the gem if you still face the problem.
https://github.com/brianmario/mysql2
If mysql repo is disabled on your system, here is the link about installing them
http://dev.mysql.com/doc/mysql-repo-excerpt/5.6/en/linux-installation-yum-repo.html

MySQL Gem for Ruby On Rails

I have searched everywhere and no ones solutions solve my problem. I have built rails apps using SQLite but not MySQL. For this particular project, I need MySQL. When I attempt to boot the server I get an error, so I attempt to install the gems for MySQL and get another error. Does anyone have any insight? Thank you!
rails server
Could not find gem 'mysql2 (>= 0)' in any of the gem sources listed in your Gemfile.
sudo gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/mysql2-0.2.7/ext/mysql2/gem_make.out
I had this problem. You need to install the mysql gem with native extensions.
The line you're probably looking for is this:
$ ARCHFLAGS="-arch x86_64" gem install mysql2 --version '~> 0.2.7' -- --with-mysql-config=/usr/local/mysql/bin/mysql_config
Full write up on getting it going here: http://softwaregravy.com/mysql-on-os-x-rails-3-0-7/