好吧,问一个显然已经被问过多次的问题感觉 super 愚蠢。提前致歉。
正在学习本教程: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
不幸的是,我得到:“找不到命令”...
有点不知所措......
想通过 Homebrew 程序来做到这一点(因为它看起来“简单”)......但是有几个问题......
- 真的不熟悉...
- 不确定我是否拥有它...
所以,尝试了brew update来看看我会得到什么......这就是我得到的:
/usr/local/.git: Permission denied
Error: Failure while executing: git init
所以...尝试通过这里的代码删除它:https://gist.github.com/1173223
它似乎没有做任何事情,而且有点卡住,所以退出它......
不知道现在该做什么...首要任务显然是尝试安装 mysql2 gem(如果可能的话)... Homebrew 程序只是附带的东西...
这里还需要其他信息吗?我的问题需要澄清吗?抱歉,我不是故意问这个问题这么久的!只是试图覆盖尽可能多的基地。
提前致谢。
哦,我的 mac 版本是 10.6.8,如果这有什么区别的话......
刚刚又尝试了一件事:“brew install mysql”(通过另一个 stackoverflow 问题)
这就是我得到的:
Error: Cannot write to /usr/local/Cellar
最佳答案
一些事情:
apt-get
是一个适用于 Linux 的软件包安装工具,因此这些命令不适用于您的 Mac。
您的 /usr/local
存在权限问题导致 brew update
错误的目录和brew install
。要解决此问题,您可以使用以下命令授予自己所有权:
sudo chown -R $USER /usr/local
这有一些警告,所以请查看此线程:Installing in Homebrew errors
接下来,您没有 mysql
安装。 mysql2
gem 未安装 mysql
;它只是一个 Ruby 库,允许您连接到正在运行的 mysql
使用 Ruby 代码进行处理。我不相信你可以安装 gem,除非该进程已安装并运行,这解释了 gem install mysql2
中的大而丑陋的堆栈跟踪.
所以,在您更新 /usr/local
后权限,重试 brew install mysql
并按照说明运行该服务。如果您看到 mysqld
,则可以确认它正在工作。或mysqld_safe
守护进程使用类似 ps ax | grep mysqld
的命令运行。假设可行,您应该能够安装 mysql2
gem 。
关于ruby-on-rails - 无法安装 mysql2 gem ...( Homebrew 软件上的附带内容也是如此),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12719355/