当尝试在我的当前目录(这是一个新的 rails 项目)中运行 rails server
时,它说我需要安装 mysql2
gem。起初,我不知道这是什么意思……然后,我四处寻找,最后决定安装 gem。但是,我遇到了这个 super 讨厌的错误(因为我只花了 2 个小时试图调查并解决另一个错误)。我快要放弃了,但我真的很想试试rails。请帮忙!
目前,如果我运行 sudo gem install mysql2
,或者甚至像一些人告诉我在网上做的那样,gem install mysql --\--with-mysql-config=/Applications/MAMP/Library/bin/mysql_config
(我有 MAMP),它给了我以下错误:
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
/Users/vicky/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
-----
Using mysql_config at /Applications/MAMP/Library/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /Applications/MAMP/Library/lib
-----
creating Makefile
make "DESTDIR="
compiling client.c
compiling mysql2_ext.c
compiling result.c
linking shared-object mysql2/mysql2.bundle
ld: warning: directory not found for option '-L/Users/mpapis/.sm/pkg/active/lib'
ld: library not found for -lmysqlclient
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
Gem files will remain installed in /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14 for inspection.
Results logged to /Users/username/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/gems/2.0.0/gems/mysql2-0.3.14/ext/mysql2/gem_make.out
最佳答案
您是否考虑过使用自制软件安装 MySQL (http://brew.sh/)? MAMP 代表 Mac-Apache-MySQL-PHP(最后一部分是最重要的)。我建议直接在你的盒子上安装 MySQL(自制软件负责所有繁重的工作),然后我怀疑你在安装那个 gem 时会遇到任何困难。
安装自制软件 --
ruby -e "$(curl -fsSL https://raw.github.com/Homebrew/homebrew/go/install)"
运行 brew doctor
按照任何说明进行操作,然后安装 MySQL 运行 brew install mysql
并按照它为设置用户等提供的任何说明进行操作。 .
=============更新==============
所以,您要做的是以这种方式使用 brew 安装 MySQL,然后以正常方式安装 gem - sudo gem install mysql2
假设这可行,那么您将能够通过 -
sudo nano /etc/paths
然后将这一行添加到文档的顶部-
/Applications/MAMP/Library/bin
重新启动您的终端,然后运行 mysql
以仔细检查您是否正在使用 MySQL 的 MAMP 安装,然后您就可以开始了。
关于mysql - 带有 MAMP 2.2 的 Mac 上的 "gem install mysql2",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20935236/