2

ok, feel super dumb about asking a question that's apparently been asked multiple times. apologies in advance.

am following this tutorial: http://squarism.com/2011/04/01/how-to-write-a-ruby-rails-3-rest-api/

it requires mysql2 ...

tried to install it via "gem install mysql2"

this is what i get:

Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
ERROR: Failed to build gem native extension.

    /Users/name_withheld/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Provided configuration options:
--with-opt-dir
--with-opt-include
--without-opt-include=${opt-dir}/include
--with-opt-lib
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/Users/name_withheld/.rvm/rubies/ruby-1.9.3-p194/bin/ruby
--with-mysql-config
--without-mysql-config
--with-mysql-dir
--without-mysql-dir
--with-mysql-include
--without-mysql-include=${mysql-dir}/include
--with-mysql-lib
--without-mysql-lib=${mysql-dir}/lib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mlib
--without-mlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-zlib
--without-zlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-socketlib
--without-socketlib
--with-mysqlclientlib
--without-mysqlclientlib
--with-nsllib
--without-nsllib
--with-mysqlclientlib
--without-mysqlclientlib
--with-mygcclib
--without-mygcclib
--with-mysqlclientlib
--without-mysqlclientlib


Gem files will remain installed in /Users/name_withheld/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11 for inspection.
Results logged to /Users/name_withheld/.rvm/gems/ruby-1.9.3-p194/gems/mysql2-0.3.11/ext/mysql2/gem_make.out

so, poked around and saw this solution being proposed multiple times:

sudo apt-get install libmysql-ruby libmysqlclient-dev

unfortunately, i get: "command not found" ...

kind of at loss ...

wanted to do it via homebrew (since it seemed "simple") ... but there are several problems with that ...

  • really unfamiliar with it ...
  • not sure if i have it or not ...

so, tried brew update to see what i'd get ... this is what i got:

/usr/local/.git: Permission denied
Error: Failure while executing: git init 

so ... tried to delete it via this code from here: https://gist.github.com/1173223

it doesn't seem to have done anything, and it kind of froze up, so quit it ...

not sure what to do now ... first priority is clearly trying to get mysql2 gem installed if possible ... homebrew is just side stuff ...

any other information needed here? any clarification need with my question? and sorry, didn't mean to make this question so long! just trying to cover as many bases as possible.

thanks in advance.

oh, my version of mac is 10.6.8 if that makes any difference ...

just tried one more thing: "brew install mysql" (via another stackoverflow question)

this is what i get:

Error: Cannot write to /usr/local/Cellar
  • A few questions: Are you on a Mac? and, What is the output of `which mysqld` from command line? – rossta Oct 04 '12 at 02:37
  • @rossta, i am on mac. version is 10.6.8. just tried "which mysqld" right now. command line doesn't say anything. just goes to the next prompt. –  Oct 04 '12 at 02:42

1 Answers1

3

A few things:

apt-get is a package installation tool for Linux, so those commands won't work with your Mac.

You have a permissions issue with your /usr/local directory which is causing the errors with brew update and brew install. To fix this, you can give yourself ownership with the following command:

sudo chown -R $USER /usr/local

There are some caveats with this, so check out this thread: Installing in Homebrew errors

Next, you don't have the mysql installed. The mysql2 gem does not install mysql; it is simply a Ruby library that allows you to connect to a running mysql process with Ruby code. I don't believe you can install the gem unless the process is installed and running, which explains that big ugly stack trace from gem install mysql2.

So, after you update your /usr/local permissions, retry brew install mysql and follow the instructions to get the service running. You can confirm that it's working if you see mysqld or mysqld_safe daemon process running with a command like ps ax | grep mysqld. Assuming that works, you should then be able to install the mysql2 gem.

Community
  • 1
  • 1
rossta
  • 11,394
  • 1
  • 43
  • 47
  • feel a bit silly asking this ... but if i do the sudo chown command, it won't affect my rvm, will it? –  Oct 04 '12 at 02:52
  • It will set the owner for all the files in your `/usr/local` directory to your user. You can preview the directories that will be affected by listing the contents: `ls -la /usr/local`. See rvm in there? – rossta Oct 04 '12 at 02:56
  • just ran your "ls -la /usr/local" ... there's no rvm mention in there. should it have shown up there? –  Oct 04 '12 at 02:59
  • If you don't see it there, you can run the sudo chown command on /usr/local without affecting rvm. – rossta Oct 04 '12 at 03:01
  • ok ... here goes! fingers crossed! @rossta, one more question ... what is Cellular? –  Oct 04 '12 at 03:02
  • oh my gosh! it worked! aside from telling me that xcode is outdated, and other sundries. @rossta, thank you so much! merci! gracias! ok, just one more question, what does this mean: `Warning: m4 macros were installed to "share/aclocal". Homebrew does not append "/usr/local/share/aclocal" to "/usr/share/aclocal/dirlist". If an autoconf script you use requires these m4 macros, you'll need to add this path manually. ` –  Oct 04 '12 at 03:12
  • oh, and how did i lose the ownership of all my files in `/user/local/`. i know, extra questions. you don't need to answer them. just asking out of curiosity. –  Oct 04 '12 at 03:14
  • You probably don't need to worry about the m4 macros warning. Directories under `/` are typically owned by the root user of the system so unless you're operating as the root user, you never had file and folder ownership of `/usr/local/`. – rossta Oct 04 '12 at 03:27
  • ok. thanks for the explanation. hope you don't mind one more! i would really like become good at ROR ... what are the _other_ essential skills besides ROR stuff? your advice would be very much appreciated, if you don't mind me asking. –  Oct 04 '12 at 03:33