簡體   English   中英

無法為 Rails 項目安裝 mysql2 gem

[英]Cannot install mysql2 gem for Rails project

我已經在 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 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

任何有想法、建議、提示、修復等的人......我將不勝感激。

謝謝!

這個問題的答案來看,運行以下對我有用

gem install mysql2 --source 'https://rubygems.org/' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include

我在 Mojave 上遇到了同樣的問題,之前的答案都沒有對我有用,但是這個 Github 問題評論中提到的這個命令沒有

第1步。

brew install openssl

第2步。

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

就我而言,我已經安裝了openssl所以它確實是解決問題的導出命令。

  1. 確保通過 Homebrew 在 Mac 上安裝了 openssl。
brew install openssl
  1. 安裝 mysql2 gem。
gem install mysql2 -v '0.5.2' -- --with-ldflags=-L/usr/local/opt/openssl/lib --with-cppflags=-I/usr/local/opt/openssl/include
  1. 如果錯誤沒有修復,上面的解決方案是最后一個
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /

如果上述方法不起作用,則另一種解決方案。

cd /usr/local/Cellar/openssl/1.0.2s/lib/

sudo cp libssl.1.0.0.dylib libcrypto.1.0.0.dylib /usr/local/lib

這在 macOS Catalina 上對我有用:

確保你已經安裝了 openssl。 如果不:

brew install openssl

然后執行 gem 安裝:

gem install mysql2 -- --with-opt-dir="$(brew --prefix openssl)"

嘗試這個:

which mysql

然后,使用 output-result 使用現有的 mysql 安裝目錄安裝 gem:

gem install mysql2 -- --with-mysql-dir=<mysql-installation-directory>

瘋狂 2 小時后它就為我工作了

  1. 卸載 Ruby 並安裝 Ruby v2.6.6
  2. 以管理員身份運行命令行gem install mysql2
  3. 安裝導軌gem install rails
  4. 創建新項目rails new my_proj -d mysql

在 Windown 中 100% 工作

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM