1
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 1 year has passed since last update.

UbuntuにRuby Gem(mysql2など)をインストールする時のエラーに対処

Last updated at Posted at 2022-10-22

以下のエラーはRubyをビルド後にgemでmysql2を入れようとすると表示されます。
(aptは使ってません)

検索するとopenssl等を入れたりして何とかなりましたとか、mysql-dev関係をなどをapt installしましょう
というものが多いのですが、私の場合は全く違う所に原因があったので備忘録のために載せておきます。
というか、何年振りかに環境整えると同じ事で悩んでる気がします。
皆さんこれにハマらないのでしょうか?

ubuntu@ip:~$ gem install mysql2
Fetching mysql2-0.5.4.gem
Building native extensions. This could take a while...
ERROR:  Error installing mysql2:
        ERROR: Failed to build gem native extension.

    current directory: /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/mysql2-0.5.4/ext/mysql2
/home/ubuntu/.rbenv/versions/3.1.2/bin/ruby -I /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/3.1.0 -r ./siteconf20221022-18560-7gl5ax.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
checking for rb_enc_interned_str() in ruby.h... yes
*** 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/ubuntu/.rbenv/versions/3.1.2/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-mysqlclient-dir
        --without-mysqlclient-dir
        --with-mysqlclient-include
        --without-mysqlclient-include=${mysqlclient-dir}/include
        --with-mysqlclient-lib
        --without-mysqlclient-lib=${mysqlclient-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
/home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/3.1.0/mkmf.rb:1086:in `block in find_library': undefined method `split' for nil:NilClass (NoMethodError)

    paths = paths.flat_map {|path| path.split(File::PATH_SEPARATOR)}
                                       ^^^^^^
        from /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/3.1.0/mkmf.rb:1086:in `each'
        from /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/3.1.0/mkmf.rb:1086:in `flat_map'
        from /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/3.1.0/mkmf.rb:1086:in `find_library'
        from extconf.rb:103:in `<main>'

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/aarch64-linux/3.1.0/mysql2-0.5.4/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/gems/mysql2-0.5.4 for inspection.
Results logged to /home/ubuntu/.rbenv/versions/3.1.2/lib/ruby/gems/3.1.0/extensions/aarch64-linux/3.1.0/mysql2-0.5.4/gem_make.out

解決方法

sudo apt install libmysqlclient-dev

追記mecabの場合

sudo apt install libmecab-dev

1
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
1
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?