【AmazonLinux2】MySQL2의 젬을 설치할 때 에러

【AmazonLinux2】MySQL2의 젬을 설치할 때 에러

2022-10-03 last update

7 minutes reading AmazonLinux2 mysql2 EC2

MySQL의 상태가 좋지 않아 제거하고 다시 설치


gem uninstall mysql2
gem install mysql2
  • 오류 발생
  • Fetching mysql2 0.5.3
    Installing mysql2 0.5.3 with native extensions
    Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
    
        current directory: /home/takumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3/ext/mysql2
    /home/takumi/.rbenv/versions/2.5.1/bin/ruby -r ./siteconf20200619-26162-iq2nwv.rb extconf.rb --with-ldflags=-L/usr/local/opt/openssl/lib
    checking for rb_absint_size()... yes
    checking for rb_absint_singlebit_p()... yes
    checking for rb_wait_for_single_fd()... yes
    checking for -lmysqlclient... no
    -----
    mysql client is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.
    -----
    *** 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.
    
    Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/home/takumi/.rbenv/versions/2.5.1/bin/$(RUBY_BASE_NAME)
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
    
    To see why this extension failed to compile, please check the mkmf.log which can be found here:
    
      /home/takumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.0/mysql2-0.5.3/mkmf.log
    
    extconf failed, exit code 1
    
    Gem files will remain installed in /home/takumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/gems/mysql2-0.5.3 for inspection.
    Results logged to /home/takumi/.rbenv/versions/2.5.1/lib/ruby/gems/2.5.0/extensions/x86_64-linux/2.5.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
    
    

    말했듯이 다음 명령을 실행해도 오류가 발생했습니다.
    gem install mysql2 -v '0.5.3' --source 'https://rubygems.org/'
    

    해결책


    mysql client is missing. You may need to 'sudo apt-get install libmariadb-dev', 'sudo apt-get install libmysqlclient-dev' or 'sudo yum install mysql-devel', and try again.
    

    에러문에 있는 이 안의 'sudo yum install mysql-devel'을 실행했다.
    $ sudo yum install mysql-devel
    読み込んだプラグイン:extras_suggestions, langpacks, priorities, update-motd
    amzn2-core                                                                                                                                                                         | 3.7 kB  00:00:00     
    amzn2extra-docker                                                                                                                                                                  | 3.0 kB  00:00:00     
    amzn2extra-nginx1                                                                                                                                                                  | 1.8 kB  00:00:00     
    mysql-connectors-community                                                                                                                                                         | 2.5 kB  00:00:00     
    mysql-tools-community                                                                                                                                                              | 2.5 kB  00:00:00     
    mysql57-community                                                                                                                                                                  | 2.5 kB  00:00:00     
    nodesource                                                                                                                                                                         | 2.5 kB  00:00:00     
    33 packages excluded due to repository priority protections
    依存性の解決をしています
    --> トランザクションの確認を実行しています。
    ---> パッケージ mysql-community-devel.x86_64 0:5.7.30-1.el7 を インストール
    --> 依存性解決を終了しました。
    
    依存性を解決しました
    
    ==========================================================================================================================================================================================================
     Package                                                アーキテクチャー                        バージョン                                       リポジトリー                                        容量
    ==========================================================================================================================================================================================================
    インストール中:
     mysql-community-devel                                  x86_64                                  5.7.30-1.el7                                     mysql57-community                                  3.7 M
    
    トランザクションの要約
    ==========================================================================================================================================================================================================
    インストール  1 パッケージ
    
    総ダウンロード容量: 3.7 M
    インストール容量: 20 M
    Is this ok [y/d/N]: y
    Downloading packages:
    mysql-community-devel-5.7.30-1.el7.x86_64.rpm                                                                                                                                      | 3.7 MB  00:00:00     
    Running transaction check
    Running transaction test
    Transaction test succeeded
    Running transaction
      インストール中          : mysql-community-devel-5.7.30-1.el7.x86_64                                                                                                                                 1/1 
      検証中                  : mysql-community-devel-5.7.30-1.el7.x86_64                                                                                                                                 1/1 
    
    インストール:
      mysql-community-devel.x86_64 0:5.7.30-1.el7                                                                                                                                                             
    
    完了しました!
    
    

    bundle install을 실행. 안전하게 했습니다!
    $ bundle install
    ~~
    Bundle complete! 37 Gemfile dependencies, 136 gems now installed.
    Use `bundle info [gemname]` to see where a bundled gem is installed.