无法安装mysql2 gem ...(也是自制的东西)

时间:2012-10-04 01:59:36

标签: ruby-on-rails ruby-on-rails-3 gem homebrew mysql2

好吧,对于提出一个显然被多次询问的问题感到非常愚蠢。提前道歉。

遵循本教程:http://squarism.com/2011/04/01/how-to-write-a-ruby-rails-3-rest-api/

它需要mysql2 ...

试图通过“gem install mysql2”

安装它

这就是我得到的:

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

所以,戳了一遍,看到这个解决方案被多次提出:

sudo apt-get install libmysql-ruby libmysqlclient-dev

不幸的是,我得到:“找不到命令”......

有点不知所措......

希望通过自制软件做这件事(因为它似乎“简单”)......但是有几个问题......

  • 真的不熟悉......
  • 不确定我是不是......

所以,试过brew更新看看我得到了什么...这就是我得到的:

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

所以...试图通过此处的代码删除它:https://gist.github.com/1173223

它似乎没有做任何事情,它有点冻结,所以退出它......

不确定现在要做什么...如果可能的话,首要任务显然是尝试安装mysql2 gem ...自制软件只是副本......

此处需要的任何其他信息?任何澄清需要我的问题?对不起,并不是故意让这个问题这么久!只是试图覆盖尽可能多的基地。

提前谢谢。

哦,我的Mac版本是10.6.8,如果这有任何区别......

刚尝试了一件事:“brew install mysql”(通过另一个stackoverflow问题)

这就是我得到的:

Error: Cannot write to /usr/local/Cellar

1 个答案:

答案 0 :(得分:3)

一些事情:

apt-get是Linux的软件包安装工具,因此这些命令不适用于您的Mac。

您的/usr/local目录存在权限问题,导致brew updatebrew install出错。要解决此问题,您可以使用以下命令为自己拥有所有权:

sudo chown -R $USER /usr/local

对此有一些警告,请查看此主题:Installing in Homebrew errors

接下来,您没有安装mysqlmysql2 gem 未安装mysql;它只是一个Ruby库,允许您使用Ruby代码连接到正在运行的mysql进程。我不相信你可以安装gem,除非这个进程已经安装并运行,这解释了来自gem install mysql2的大量难看的堆栈跟踪。

因此,在您更新/usr/local权限后,请重试brew install mysql并按照说明运行服务。如果您看到使用mysqld之类的命令运行mysqld_safeps ax | grep mysqld守护程序进程,则可以确认它是否正常工作。假设有效,那么您应该能够安装mysql2 gem。