Ruby on rails 无法安装mysql2 gem for Rails项目
我已经在Stackoverflow.com上查看并尝试了关于此主题的所有内容,但仍然无法解决这个问题 当我“gem install mysql2”时,我得到一个权限错误。当我“sudo gem install mysql2”时,我得到以下信息:Ruby on rails 无法安装mysql2 gem for Rails项目,ruby-on-rails,mysql2,Ruby On Rails,Mysql2,我已经在Stackoverflow.com上查看并尝试了关于此主题的所有内容,但仍然无法解决这个问题 当我“gem install mysql2”时,我得到一个权限错误。当我“sudo gem install mysql2”时,我得到以下信息: Teds-MacBook-Pro:~ tedmartin$ sudo gem install mysql2 Building native extensions. This could take a while... ERROR: Error
Teds-MacBook-Pro:~ tedmartin$ sudo gem install mysql2
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
/Users/tedmartin/.rbenv/versions/2.4.1/bin/ruby -r ./siteconf20170420-50202-1nekuvd.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in 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 /usr/local/Cellar/mysql-connector-c/6.1.9/lib
-----
creating Makefile
current directory: /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -l-lpthread
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/gems/mysql2-0.4.5 for inspection.
Results logged to /Users/tedmartin/.rbenv/versions/2.4.1/lib/ruby/gems/2.4.0/extensions/x86_64-darwin-15/2.4.0-static/mysql2-0.4.5/gem_make.out
任何有想法、建议、提示、修正等的人。。。我真的很感激
谢谢 试试这个:
which mysql
然后,使用输出结果使用现有mysql安装目录安装gem:
gem install mysql2 -- --with-mysql-dir=<mysql-installation-directory>
gem安装mysql2--with mysql dir=
从上的答案来看,运行以下命令对我很有效
gem安装mysql2——源代码'https://rubygems.org/'--with ldflags=-L/usr/local/opt/openssl/lib--with cppflags=-I/usr/local/opt/openssl/include
cd /usr/local/Cellar/openssl/1.0.2s/lib/
sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib
我在Mojave上遇到了同样的问题,之前的答案对我来说都不管用,但Github中提到的命令确实管用 第一步
brew install openssl
第二步
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
在我的例子中,我已经安装了
openssl
,所以实际上是export命令解决了这个问题。它让我在2小时后工作
gem安装mysql2
gem安装rails
rails新建my_proj-d mysql
在Windown中100%工作这对我在macOS Catalina上的工作很有效: 确保已安装openssl。如果没有:
brew install openssl
然后执行gem安装:
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"
不知道为什么有人否决了你。。你开始在mac上安装mysql了吗?与其他gems不同的是,它不仅仅是一个bundle安装的例子,您可以通过从终端运行mysql-uroot并查看它是否识别该命令来进行检查。如果没有,请访问mysql站点并按照OSXThanks Mike的安装说明进行操作。我已经用自制软件安装了mysql,并下载了社区版。。。我也不知道为什么有人投票反对我。。。哦,匿名互联网的乐趣:)这就是生活!当您尝试从终端运行mysql-u root时会发生什么?它能识别命令吗?检查@TedMartin。只有最后一个解决方案对我有效。还应复制libssl.a、libcrypto.a。解决方案2有助于运行gem安装,但随后的bundle安装仍然失败。这也是我的问题。有openssl,但需要导出。非常感谢。这是单线解决方案的最佳答案
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
brew install openssl
gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"