2
4

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 5 years have passed since last update.

【Rails 5.2.2】Bundle Install でMysql2インストールするときのエラー解決法

Last updated at Posted at 2019-02-01

##現状
今までcloud9で新しいプロジェクトを立ち上げる時はrails 5.0.6でやっていた。
※プログラミングスクールの教材通りに進めていたため。
ただ、新たなversionに触れておくのも大事だと思いrails 5.2.2でプロジェクトを立ち上げる。
今まで通りrails _5.0.6_ new 〇〇 --database=mysqlとやってもエラーが出てしまう。

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

In Gemfile:
  mysql2

言われた通りgem install mysql2 -v '0.5.2'をインストールしようとしてもエラーがでる。

##やりたいこと
Bundle InstalldでMysql2をインストールしたい

##解決法
###①mysql-develをインストールする。

 $ sudo yum install mysql-devel

Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main                                                                                                                               | 2.1 kB  00:00:00
amzn-updates                                                                                                                            | 2.5 kB  00:00:00
1060 packages excluded due to repository priority protections
Resolving Dependencies
--> Running transaction check
---> Package mysql-devel.noarch 0:5.5-1.6.amzn1 will be installed
--> Processing Dependency: mysql55-devel >= 5.5 for package: mysql-devel-5.5-1.6.amzn1.noarch
--> Running transaction check
---> Package mysql55-devel.x86_64 0:5.5.62-1.23.amzn1 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===============================================================================================================================================================
 Package                                Arch                            Version                                    Repository                             Size
===============================================================================================================================================================
Installing:
 mysql-devel                            noarch                          5.5-1.6.amzn1                              amzn-main                             2.7 k
Installing for dependencies:
 mysql55-devel                          x86_64                          5.5.62-1.23.amzn1                          amzn-updates                          201 k

Transaction Summary
===============================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 204 k
Installed size: 602 k
Is this ok [y/d/N]: y
Downloading packages:
(1/2): mysql-devel-5.5-1.6.amzn1.noarch.rpm                                                                                             | 2.7 kB  00:00:00
(2/2): mysql55-devel-5.5.62-1.23.amzn1.x86_64.rpm                                                                                       | 201 kB  00:00:00
---------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                          476 kB/s | 204 kB  00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : mysql55-devel-5.5.62-1.23.amzn1.x86_64                                                                                                      1/2
  Installing : mysql-devel-5.5-1.6.amzn1.noarch                                                                                                            2/2
  Verifying  : mysql55-devel-5.5.62-1.23.amzn1.x86_64                                                                                                      1/2
  Verifying  : mysql-devel-5.5-1.6.amzn1.noarch                                                                                                            2/2

Installed:
  mysql-devel.noarch 0:5.5-1.6.amzn1

Dependency Installed:
  mysql55-devel.x86_64 0:5.5.62-1.23.amzn1

Complete!

RailsでMySQLを使うために必要なgemを使うために必要なパッケージ。
これがダメだった模様。。

-develというのは、developmentの略。
主に開発に関連したものが入っているパッケージ
開発用のツールだったり、コンポーネントだったり。
動的な仕組み(機能がモジュール化されているもの)を使うソフトウェアの場合は、通常の使用でも必要になることもある

###②bundle install実行

$ bundle install --without production

Fetching mysql2 0.5.2
Installing mysql2 0.5.2 with native extensions

ということでできました。

##参考サイト
https://mintaku-blog.net/rails-mysql2/
https://woshidan.hatenablog.com/entry/2014/12/29/152923

2
4
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
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?