About
Currently, I`m building the Ruby on Rails project environment.
However, if I implement bundle install, the following error occurs.
I do not know where the cause is, I would like advice.
Environment
Ruby v2.5.3
Rails 5.2.2
MySQL 5.7
Run Command 1
$ bundle install
Output error
Errno::EACCES: Permission denied # rb_sysopen -
/Users/xxx/project_dir/vendor/bundle/ruby/2.5.0/gems/mysql2-0.5.2/CHANGELOG.md
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.
Run Command 2
$ sudo gem install mysql2 -v '0.5.2' --source 'https://rubygems.org/'
Output error
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/xxx/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/ext/mysql2/Users/xxx/.rbenv/versions/2.5.3/bin/ruby -I /Users/xxx/.rbenv/versions/2.5.3/lib/ruby/site_ruby/2.5.0 -r ./siteconf20190220-84910-2gf7i1.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/local/opt/mysql#5.7/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/opt/mysql#5.7/lib
-----
creating Makefile
current directory: /Users/xxx/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/xxx/.rbenv/versions/2.5.3/lib/ruby/gems/2.5.0/gems/mysql2-0.5.2/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
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
It seems that some system libraries are missing. As far as I understand you are using macos. So please try: xcode-select --install and bundle install
UPDATE
We had a private chat with #getty and we came up a solution. The problem was with some missing headers regarding to ruby program.
So we fixed the problem like following:
rbenv uninstall 2.5.3
CC=gcc rbenv install 2.5.3
rbenv local 2.5.3
bundle install
This solution would be applied to rvm or other version managers.
Related
Hi I am trying to install mysql2 gem in MacBook M1 Big Sur, I am getting the the following errors.
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
Full Error
Using mysql_config at /opt/homebrew/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /opt/homebrew/Cellar/mysql/8.0.26/lib
-----
creating Makefile
current directory: /Users/santosh/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/santosh/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.3/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.bundle
ld: library not found for -lzstd
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make: *** [mysql2.bundle] Error 1
make failed, exit code 2
Gem files will remain installed in /Users/santosh/.rvm/gems/ruby-2.6.3/gems/mysql2-0.5.3 for inspection.
Results logged to /Users/santosh/.rvm/gems/ruby-2.6.3/extensions/-darwin-20/2.6.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.
I tried to install with different version of Ruby, nothing went well.
I had this problem too and I think what finally solved it was running:
gem install mysql2 -v '0.5.3' -- --with-opt-dir=$(brew --prefix openssl) --with-ldflags=-L/opt/homebrew/Cellar/zstd/1.5.0/lib
However, for what it's worth, I'd previously installed without success but might have also been needed:
homebrew, and brew doctor said it was ready to brew.
Xcode tools xcode-select --install
mysql brew install mysql (and I could make a local connection)
openssl brew install openssl && brew link openssl --force
rbenv and rbenv rehash
cmake brew install cmake
Apple Macbook air M1. Monterey. You need to install MySQL and openssl using brew .
This works for me.
gem install mysql2 -- --with-opt-dir=/opt/homebrew/opt/openssl#3 --with-mysql-dir=/opt/homebrew/opt/mysql
I try to install mysql2 gem with "gem install mysql2 -v '0.4.10'" on MacOS but always found this error.
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/sakuto/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.10/ext/mysql2
- /Users/sakuto/.rbenv/versions/2.3.3/bin/ruby -r
./siteconf20190212-14889-1xapc5p.rb extconf.rb checking for
rb_absint_size()... yes checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes checking for
rb_thread_call_without_gvl() in ruby/thread.h... yes checking for
rb_thread_blocking_region()... no checking for
rb_wait_for_single_fd()... yes checking for rb_hash_dup()... yes
checking for rb_intern3()... yes checking for rb_big_cmp()... yes
----- Using mysql_config at /usr/local/bin/mysql_config
----- checking for mysql.h... yes checking for errmsg.h... yes checking for SSL_MODE_DISABLED in mysql.h... yes checking for
SSL_MODE_PREFERRED in mysql.h... yes checking for SSL_MODE_REQUIRED
in mysql.h... yes checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes checking for
MYSQL.net.vio in mysql.h... yes checking for MYSQL.net.pvio in
mysql.h... no checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in
mysql.h... yes
----- Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
----- Setting libpath to /usr/local/Cellar/mysql/8.0.15/lib
----- creating Makefile
To see why this extension failed to compile, please check the
mkmf.log which can be found here:
/Users/sakuto/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-18/2.3.0-static/mysql2-0.4.10/mkmf.log
current directory:
/Users/sakuto/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" clean
current directory:
/Users/sakuto/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.10/ext/mysql2
make "DESTDIR=" compiling infile.c compiling client.c compiling
mysql2_ext.c compiling statement.c compiling result.c 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
Gem files will remain installed in
/Users/sakuto/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/gems/mysql2-0.4.10
for inspection. Results logged to
/Users/sakuto/.rbenv/versions/2.3.3/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-18/2.3.0-static/mysql2-0.4.10/gem_make.out
Try adding gem inside Gemfile in your ruby on rails project and run bundle install in command line.
for example:
gem 'mysql2', '~> 0.4.10'
Related Github Issue: https://github.com/docker-library/mysql/issues/441
Trying to install Sequel gem (https://github.com/jeremyevans/sequel) fails with "Failed to build gem native extension".
Docker image:
FROM mysql:latest
RUN apt-get update
RUN apt-get install -y rubygems ruby-mysql2 wget build-essential libmysqlclient-dev ruby2*-dev sqlite3 libsqlite3-dev
RUN gem install mysql2
Output:
$ docker build -t "mysqltest" .
Sending build context to Docker daemon 8.704kB
Step 1/4 : FROM mysql
---> a8a59477268d
Step 2/4 : RUN apt-get update
---> Using cache
---> ab35c534ffcf
Step 3/4 : RUN apt-get install -y rubygems ruby-mysql2 wget build-essential libmysqlclient-dev ruby2*-dev sqlite3 libsqlite3-dev
---> Using cache
---> b703bf4ef78d
Step 4/4 : RUN gem install mysql2
---> Running in 79790b7f4506
Building native extensions. This could take a while...
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /var/lib/gems/2.3.0/gems/mysql2-0.5.1/ext/mysql2
/usr/bin/ruby2.3 -r ./siteconf20180610-8-1ixqzle.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for rb_wait_for_single_fd()... yes
-----
Using mysql_config at /usr/bin/mysql_config
-----
checking for mysql.h... yes
checking for errmsg.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for MYSQL.net.vio in mysql.h... yes
checking for MYSQL.net.pvio in mysql.h... no
checking for MYSQL_ENABLE_CLEARTEXT_PLUGIN in mysql.h... yes
checking for SERVER_QUERY_NO_GOOD_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_NO_INDEX_USED in mysql.h... yes
checking for SERVER_QUERY_WAS_SLOW in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_ON in mysql.h... yes
checking for MYSQL_OPTION_MULTI_STATEMENTS_OFF in mysql.h... yes
checking for my_bool in mysql.h... no
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/lib/x86_64-linux-gnu
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.5.1/mkmf.log
current directory: /var/lib/gems/2.3.0/gems/mysql2-0.5.1/ext/mysql2
make "DESTDIR=" clean
current directory: /var/lib/gems/2.3.0/gems/mysql2-0.5.1/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
linking shared-object mysql2/mysql2.so
/usr/bin/ld: cannot find -lssl
/usr/bin/ld: cannot find -lcrypto
collect2: error: ld returned 1 exit status
Makefile:255: recipe for target 'mysql2.so' failed
make: *** [mysql2.so] Error 1
make failed, exit code 2
Gem files will remain installed in /var/lib/gems/2.3.0/gems/mysql2-0.5.1 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/mysql2-0.5.1/gem_make.out
The command '/bin/sh -c gem install mysql2' returned a non-zero code: 1
mkmf.log content: https://gist.github.com/ifischer/529950ce6af29280d5c778e702321b35
Found the problem:
I need to install default-libmysqlclient-dev instead of libmysqlclient-dev:
FROM mysql:latest
RUN apt-get update
RUN apt-get install -y rubygems ruby-mysql2 wget build-essential default-libmysqlclient-dev ruby2*-dev sqlite3 libsqlite3-dev
RUN gem install mysql2 sequel sqlite3
I'm trying to install mysql2 gem for rails applications but it gives me following error while running sudo gem install mysql2
ERROR: Error installing mysql2:
ERROR: Failed to build gem native extension.
current directory: /Users/ateeq/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.5/ext/mysql2
/Users/ateeq/.rbenv/versions/2.3.1/bin/ruby -r ./siteconf20161103-83594-10ft58j.rb extconf.rb
checking for rb_absint_size()... yes
checking for rb_absint_singlebit_p()... yes
checking for ruby/thread.h... yes
checking for rb_thread_call_without_gvl() in ruby/thread.h... yes
checking for rb_thread_blocking_region()... no
checking for rb_wait_for_single_fd()... yes
checking for rb_hash_dup()... yes
checking for rb_intern3()... yes
checking for rb_big_cmp()... yes
-----
Using mysql_config at /usr/local/bin/mysql_config
-----
checking for mysql.h... yes
checking for SSL_MODE_DISABLED in mysql.h... yes
checking for SSL_MODE_PREFERRED in mysql.h... yes
checking for SSL_MODE_REQUIRED in mysql.h... yes
checking for SSL_MODE_VERIFY_CA in mysql.h... yes
checking for SSL_MODE_VERIFY_IDENTITY in mysql.h... yes
checking for errmsg.h... yes
checking for mysqld_error.h... yes
-----
Don't know how to set rpath on your system, if MySQL libraries are not in path mysql2 may not load
-----
-----
Setting libpath to /usr/local/Cellar/mysql/5.7.16/lib
-----
creating Makefile
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Users/ateeq/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.5/mkmf.log
current directory: /Users/ateeq/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR=" clean
current directory: /Users/ateeq/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.5/ext/mysql2
make "DESTDIR="
compiling client.c
compiling infile.c
compiling mysql2_ext.c
compiling result.c
compiling statement.c
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
Gem files will remain installed in /Users/ateeq/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/gems/mysql2-0.4.5 for inspection.
Results logged to /Users/ateeq/.rbenv/versions/2.3.1/lib/ruby/gems/2.3.0/extensions/x86_64-darwin-16/2.3.0-static/mysql2-0.4.5/gem_make.out
I installed rails via brew & rbenv. Versions are mentioned below:
Ruby Version: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
Rails Version: Rails 4.2.6
MySql Version: mysql-5.7.16
Pull up an instance of Terminal and run:
brew doctor
It's likely that one or more dependencies for building the mysql gem are out of date.
You'll have to run:
brew update
You probably also upgraded to the Sierra release of OS X recently. Make sure your XCode command line tools is up to date. Run:
xcode-select --install
Make sure you accept the license for the new version of XCode by running:
sudo xcodebuild -license
Here is my solution for above error:
I just uninstalled mysql by running brew remove mysql and then run following command to install mysql2 gem sudo gem install mysql2. It worked for me. After this, I reinstalled mysql by running brew install mysql.
P.s. I don't know about this behaviour. If anyone can explain, it'd be great.
I have recently installed Ruby in my Windows machine and trying to setup in localhost a project that is built in Sinatara framework. For this I need to run few commands like below.
gem install bundle
bundle install
The first command executed without any issue. When I tried to execute second command, it throws below error after a while.
Installing do_mysql 0.10.16 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20150808-5540-i2wwjw.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
generating do_mysql-x64-mingw32.def
compiling do_common.c
compiling do_mysql.c
do_mysql.c:5:19: fatal error: mysql.h: No such file or directory
compilation terminated.
make: *** [do_mysql.o] Error 1
make failed, exit code 2
Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/do_mys
ql-0.10.16 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0
/do_mysql-0.10.16/gem_make.out
An error occurred while installing do_mysql (0.10.16), and Bundler cannot
continue.
Make sure that `gem install do_mysql -v '0.10.16'` succeeds before bundling.
As the above error sugested me to run "gem install do_mysql -v '0.10.16'", I did and again got same error. I have attached the error below.
C:\Users\binoy\live>gem install do_mysql -v '0.10.16'
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing do_mysql:
ERROR: Failed to build gem native extension.
C:/Ruby22-x64/bin/ruby.exe -r ./siteconf20150808-9876-odu2ng.rb extconf.rb
checking for my_global.h... no
checking for mysql.h... no
checking for main() in -llibmysql... no
checking for mysql_query() in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
checking for localtime_r()... yes
checking for gmtime_r()... yes
checking for mysql.h... no
checking for MYSQL_TYPE_STRING in mysql.h... no
checking for MYSQL_TYPE_BIT in mysql.h... no
checking for MYSQL_TYPE_NEWDECIMAL in mysql.h... no
checking for mysql_query() in mysql.h... no
checking for mysql_ssl_set() in mysql.h... no
checking for mysql_sqlstate() in mysql.h... no
checking for mysql_get_ssl_cipher() in mysql.h... no
checking for mysql_set_character_set() in mysql.h... no
checking for mysql_get_server_version() in mysql.h... no
checking for MYSQL_FIELD.charsetnr in mysql.h... no
checking for rb_thread_fd_select()... yes
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
generating do_mysql-x64-mingw32.def
compiling do_common.c
compiling do_mysql.c
do_mysql.c:5:19: fatal error: mysql.h: No such file or directory
compilation terminated.
make: *** [do_mysql.o] Error 1
make failed, exit code 2
Gem files will remain installed in C:/Ruby22-x64/lib/ruby/gems/2.2.0/gems/do_mys
ql-0.10.16 for inspection.
Results logged to C:/Ruby22-x64/lib/ruby/gems/2.2.0/extensions/x64-mingw32/2.2.0
/do_mysql-0.10.16/gem_make.out
I got stuck here. I will really appreciate your help.
Thanks, Binoy