LoginSignup
12
5

More than 1 year has passed since last update.

Amazon Linux 2023にMySQL をインストールする

Posted at

Amazon-linux2023を使用しています。

エラー内容

$ bundle install --path vendor/bundle

    (省略)

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

An error occurred while installing mysql2 (0.5.3), and Bundler cannot
continue.

In Gemfile:
  mysql2

解決したいこと

EC2にてMYSQLをインストールして、bundle installを成功させたい。

試したこと

エラー文から見るに、EC2に MYSQL がインストールできていない可能性が高いと思い、下記で調べてみる。

$ sudo yum list installed | grep mysql  # mysqlと関連パッケージがインストールされているか?
mysql80-community-release.noarch       el7-7          @mysql80-community

$ mysql --version  # MySQLのバージョンを確認
-bash: mysql: command not found

mysql: command not foundと出ているので、MYSQLをインストールできていないことがわかる。

MYSQLインストールを試みるがここでもエラーになる。

$ sudo yum install mysql mysql-devel
[sudo] password for tester:

(省略(他にエラー文はなし))

(try to add '--skip-broken' to skip uninstallable packages)

--skip-brokenをオプションをつけて再度コマンドを実行してみてもインストールできておらず、$ bundle install --path vendor/bundleしてもまったく同じエラー内容が出ました。

(そもそも「–skip-broken」オプションを付与してインストールしても、パッケージ依存関係に不整合が出る可能性があり、将来的に困る可能性大です。。)

ちなみに git や gccなどは何の問題もなくインストールできています。

解決

↑このサイトに書いてある手順通り試してみたら、mysqlmysql-develがインストールできました!

$ sudo dnf -y localinstall  https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm

$ sudo dnf -y install mysql mysql-community-client

$ sudo yum install mysql mysql-devel
[sudo] password for tester:
Last metadata expiration check: 0:05:20 ago on Sun Mar 26 03:46:53 2023.
Package mysql-community-client-8.0.32-1.el9.x86_64 is already installed.
Package mysql-community-devel-8.0.32-1.el9.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!

その後

ここからは記事としては少々蛇足なのですが、bundle installしてみるとrmagicの部分でエラーになりました。

$ bundle install --path vendor/bundle
(省略)
Fetching mysql2 0.5.3    
Installing mysql2 0.5.3 with native extensions  ←MYSQLは通った!
Using pagy 5.10.1   
Using pry 0.14.1
Using pry-nav 1.0.0
Using pry-rails 0.3.9
Fetching psych 3.3.2
Installing psych 3.3.2 with native extensions
Fetching puma 4.3.12
Installing puma 4.3.12 with native extensions
Using rack-proxy 0.7.2
Using rexml 3.2.5
Fetching rmagick 4.2.5
Installing rmagick 4.2.5 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.


ERROR: Can't install RMagick 4.2.5.
Can't find the ImageMagick library or one of the dependent libraries.
Check the mkmf.log file for more detailed information.

*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers.  Check the mkmf.log file for more details.  You may
need configuration options.

An error occurred while installing rmagick (4.2.5), and Bundler cannot
continue.

↑こちらに対処法が書いてありました。

解決コマンド

$ sudo yum -y install ImageMagick
$ sudo yum -y install ImageMagick-devel
$ bundle install --path vendor/bundle

(省略)

Bundle complete! 35 Gemfile dependencies, 119 gems now installed.
Bundled gems are installed into `./vendor/bundle`

無事bunndle installもできました。

12
5
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
12
5