0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Rails apiモード構築時にBundleがインストールできないエラー&解決方法(db:MySQL)

Posted at

Rails apiモードの構築時、Bundleがインストールできないエラーが発生しました。
解決に至った方法をメモも兼ねて記述しておきます。
当方初学者なので、気になるところや、こうした方が良かった等のご意見も頂ければ嬉しいです!

Railsのバージョンは

~ % rails -v
  Rails 5.2.6

~ % bundle -v
  Bundler version 1.17.2

###エラー内容
(コマンド中の「%」などは人によって異なると思います。)

~ % cd myapp

myapp % rails new api --database=mysql --skip-bundle --api
	  create  
      create  README.md
      create  Rakefile
      create  .ruby-version
      create  config.ru
      create  .gitignore
      create  Gemfile
         run  git init from “."
	  ・
	  ・
	  ・
myapp % cd api

Railsインストール完了後

api % bundle install
The dependency tzinfo-data (>= 0) will be unused by any of the platforms Bundler is installing for. Bundler is installing for ruby but the dependency is only for x86-mingw32, x86-mswin32, x64-mingw32, java. To add those platforms to the bundle, run `bundle lock --add-platform x86-mingw32 x86-mswin32 x64-mingw32 java`.
Fetching gem metadata from https://rubygems.org/............
Fetching gem metadata from https://rubygems.org/.
Resolving dependencies...
Using rake 13.0.6
Using concurrent-ruby 1.1.9
	・
	・
	・
Fetching mysql2 0.5.3
Installing mysql2 0.5.3 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
	・
	・
	・
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lssl
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/{ユーザー名}/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/gems/mysql2-0.5.3 for
inspection.
Results logged to
/Users/{ユーザー名}/.rbenv/versions/2.6.8/lib/ruby/gems/2.6.0/extensions/x86_64-darwin-20/2.6.0/mysql2-0.5.3/gem_make.out

An error occurred while installing mysql2 (0.5.3), and Bundler cannot
continue.
Make sure that `gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'`
succeeds before bundling.

In Gemfile:
  mysql2

Macを使用している場合、Apple は独自の TLS と暗号化ライブラリを使用して OpenSSL の使用を推奨しておらず、自身でGemをインストール・ビルドする際は、環境変数を設定し直さないといけないようです。

###解決方法

api % bundle config --local build.mysql2 “—with-ldflags=-L/usr/local/opt/openssl/lib"

入力後

api % bundle install

で、Bundleのインストールが完了しました。

・参考記事
 bundle install時にmysql2でエラーした時の対応

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?