Help us understand the problem. What is going on with this article?

Devise4.7をRails6+ruby 2.7.0で動かす

はじめに

さっき、「Devise4.7をRails6で動かす」を書いたばかりなのにRuby 2.7.0が使えることに気づき、やり直した。

1. ruby 2.7.0 install

2.7.0があるか確認するとちゃんとあった。

$ rbenv install -l | grep ^2
途中省略
2.7.0-dev
2.7.0-preview1
2.7.0-preview2
2.7.0-preview3
2.7.0-rc1
2.7.0-rc2
2.7.0
2.8.0-dev
$ rbenv install 2.7.0
Downloading openssl-1.1.1d.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2
Installing openssl-1.1.1d...
Installed openssl-1.1.1d to /Users/you/.rbenv/versions/2.7.0

Downloading ruby-2.7.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.bz2
Installing ruby-2.7.0...
ruby-build: using readline from homebrew
Installed ruby-2.7.0 to /Users/you/.rbenv/versions/2.7.0

Communized gems for 2.7.0
/usr/local/bin/rbenv-communal-gem-home: line 21: /usr/local/bin/../version_cache/2.7.0: Permission denied

なぜPermission denied? 調べるのは面倒なのでsudoで再実行。

$ sudo rbenv install 2.7.0
rbenv: /Users/you/.rbenv/versions/2.7.0 already exists
continue with installation? (y/N) y
Downloading openssl-1.1.1d.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/1e3a91bc1f9dfce01af26026f856e064eab4c8ee0a8f457b5ae30b40b8b711f2
Installing openssl-1.1.1d...
Installed openssl-1.1.1d to /Users/you/.rbenv/versions/2.7.0

Downloading ruby-2.7.0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.7/ruby-2.7.0.tar.bz2
Installing ruby-2.7.0...
ruby-build: using readline from homebrew
Installed ruby-2.7.0 to /Users/you/.rbenv/versions/2.7.0

Communized gems for 2.7.0
$ rbenv versions
  system
  2.3.3
  2.5.1
* 2.5.3 (set by /Users/your/apps/devise-rails6/.ruby-version)
  2.6.5
  2.7.0 <=ちゃんとインストールされている。
  2.7.0-rc1

Rubyのバージョンごとにgemをインストールしないといけないらしい。

$ gem install bundler
Successfully installed bundler-2.1.2
Parsing documentation for bundler-2.1.2
Installing ri documentation for bundler-2.1.2
Done installing documentation for bundler after 2 seconds
1 gem installed

2. Rails newでプロジェクト作成

rbenv rehashでRubyMineが読み取れるようにインストールしたRubyを反映させておきます。それからRubyMineでプロジェクトを作成します。

スクリーンショット 2020-01-01 午前3.00.10.png

ここでいろいろエラーが出て、解決するまで時間を使ったが、Railsの問題は本記事のDeviseとは関係ないので割愛する。

ところが、次のエラーが出た。

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.

素直にgem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'を実行したが、またエラー。

$ gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
    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

参考記事 の下の方に下記のヒントがあった。

$> brew install mysql@5.6
$> bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql\@5.6/5.6.42/bin/mysql_config
$> bundle install

私はMySQLのバージョンはいじりたくない(他のアプリに影響が出るのを避けたい)し、MySQLは5.7で古くないので、自分のMacのMySQL5.7に合わせて次を実行した。

$ bundle config build.mysql2 --with-mysql-config=/usr/local/Cellar/mysql@5.7/5.7.24/bin/mysql_config
$ sudo bundle install

これでbundle installは成功した。

参考記事

mysql2 gem fails to compile with MySQL 5.6.12 on OS X with Homebrew

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした