snap.ruby icon indicating copy to clipboard operation
snap.ruby copied to clipboard

Can't install gem json v 1.8.6

Open choallin opened this issue 6 years ago • 8 comments

I have to work on an old rails 4.2 codebase. I have installed Ruby 2.3 as a snap package - I am trying to avoid rvm. Now, when I run bundle install it complains that it can't install the json gem. Here is the error message:

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

current directory: /home/user/.gem/gems/json-1.8.6/ext/json/ext/generator //bin/ruby -r ./siteconf20190430-29073-znwkkd.rb extconf.rb sh: 1: //bin/ruby: not found

extconf failed, exit code 127

When I try to install just the gem with 'gem install json -v '1.8.6' --source 'https://rubygems.org/'' I get this error:

ERROR: Error installing json: ERROR: Failed to build gem native extension.

current directory: /home/user/.gem/gems/json-1.8.6/ext/json/ext/generator /snap/bin/ruby -r ./siteconf20190430-30141-z86zxd.rb extconf.rb mkmf.rb can't find header files for ruby at /snap/ruby/109/lib/ruby/include/ruby.h

extconf failed, exit code 1

So, as far as I can tell the native extension is looking in the wrong directory for the ruby headers - I guess...

choallin avatar Apr 30 '19 13:04 choallin

I am having the same problem, gem install looks in /snap/ruby/109/lib/ruby/include:

$ gem install mysql2:0.3.21
Building native extensions.  This could take a while...
ERROR:  Error installing mysql2:
	ERROR: Failed to build gem native extension.

    current directory: /home/dayyan.lord/.gem/gems/mysql2-0.3.21/ext/mysql2
/snap/bin/ruby -r ./siteconf20190503-21474-2vfbku.rb extconf.rb
mkmf.rb can't find header files for ruby at /snap/ruby/109/lib/ruby/include/ruby.h

extconf failed, exit code 1

Gem files will remain installed in /home/dayyan.lord/.gem/gems/mysql2-0.3.21 for inspection.
Results logged to /home/dayyan.lord/.gem/extensions/x86_64-linux/2.3.0-static/mysql2-0.3.21/gem_make.out

The current location is:

$ ls /snap/ruby/109/include/ruby-2.3.0
ruby  ruby.h  x86_64-linux

dayyan avatar May 03 '19 20:05 dayyan

@dayyan Have you found a solution to this?

choallin avatar May 14 '19 09:05 choallin

@choallin Sorry, I have not. I ended up compiling Ruby copying the same commands the Dockerfile uses.

dayyan avatar May 14 '19 16:05 dayyan

Hi all, Thanks to reporting this. I confirmed this is an issue of my package script for snap. I try to investigate json and mysql2 cases.

hsbt avatar Jun 02 '19 12:06 hsbt

It seems like this could be the same problem I ran into trying to install eventmachine: https://github.com/eventmachine/eventmachine/issues/881

Based on the comments there, it sounds like bundle is unable to find the Ruby headers.

bmaupin avatar Jul 11 '19 19:07 bmaupin

After https://github.com/ruby/snap.ruby/pull/26, installing gem with ext failed with glibc version mismatch on Debian 10 (buster).

I think this does not happen on ubuntu-20.04, but I don't know how to resolve this issue on other platform without glibc 2.29.

vagrant@buster:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster
vagrant@buster:~$ gem i json
Building native extensions. This could take a while...
ERROR:  Error installing json:
	ERROR: Failed to build gem native extension.

    current directory: /home/vagrant/.gem/gems/json-2.6.0/ext/json/ext/parser
/snap/bin/ruby -I /snap/ruby/232/lib/ruby/3.0.0 -r ./siteconf20211020-3495-9mcx7g.rb extconf.rb
checking for rb_enc_raise() in ruby.h... *** 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=/snap/ruby/232/bin/$(RUBY_BASE_NAME)
/snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:564:in `try_link0'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:582:in `try_link'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:794:in `try_func'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:1083:in `block in have_func'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:971:in `block in checking_for'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:361:in `block (2 levels) in postpone'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:331:in `open'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:361:in `block in postpone'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:331:in `open'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:357:in `postpone'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:970:in `checking_for'
	from /snap/ruby/232/lib/ruby/3.0.0/mkmf.rb:1082:in `have_func'
	from extconf.rb:4:in `<main>'

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

  /home/vagrant/.gem/extensions/x86_64-linux/3.0.0/json-2.6.0/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /home/vagrant/.gem/gems/json-2.6.0 for inspection.
Results logged to /home/vagrant/.gem/extensions/x86_64-linux/3.0.0/json-2.6.0/gem_make.out
vagrant@buster:~$ cat /home/vagrant/.gem/extensions/x86_64-linux/3.0.0/json-2.6.0/mkmf.log
"gcc -o conftest -I/snap/ruby/232/include/ruby-3.0.0/x86_64-linux -I/snap/ruby/232/include/ruby-3.0.0/ruby/backward -I/snap/ruby/232/include/ruby-3.0.0 -I.    -O3 -ggdb3 -Wall -Wextra -Wdeprecated-declarations -Wduplicated-cond -Wimplicit-function-declaration -Wimplicit-int -Wmisleading-indentation -Wpointer-arith -Wwrite-strings -Wimplicit-fallthrough=0 -Wmissing-noreturn -Wno-cast-function-type -Wno-constant-logical-operand -Wno-long-long -Wno-missing-field-initializers -Wno-overlength-strings -Wno-packed-bitfield-compat -Wno-parentheses-equality -Wno-self-assign -Wno-tautological-compare -Wno-unused-parameter -Wno-unused-value -Wsuggest-attribute=format -Wsuggest-attribute=noreturn -Wunused-variable  -fPIC conftest.c  -L. -L/snap/ruby/232/lib -Wl,-rpath,/snap/ruby/232/lib -L. -L/root/parts/ruby/install/usr/lib -L/root/parts/ruby/install/usr/lib/x86_64-linux-gnu -fstack-protector-strong -rdynamic -Wl,-export-dynamic     -Wl,-rpath,/snap/ruby/232/lib -L/snap/ruby/232/lib -lruby  -lm   -lc"
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `log2@GLIBC_2.29'
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `log@GLIBC_2.29'
/usr/bin/ld: //snap/core20/current/lib/x86_64-linux-gnu/libpthread.so.0: undefined reference to `__twalk_r@GLIBC_PRIVATE'
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `pow@GLIBC_2.29'
/usr/bin/ld: /snap/ruby/232/lib/libruby.so: undefined reference to `exp@GLIBC_2.29'
collect2: error: ld returned 1 exit status
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return !!argv[argc];
6: }
/* end */

znz avatar Oct 20 '21 05:10 znz

Seeing this as well, with a different set of gems - https://github.com/ruby/snap.ruby/issues/28

hloeung avatar Oct 25 '21 04:10 hloeung

Any updates on this? I'm getting the same errors inside a core22 snap that includes this snap with stage-snaps: [ruby/3.3/stable] and tries to install json 2.7.4:

:: + /snap/bin/bundle version
:: Bundler version 2.5.22 (2024-11-21 commit unknown)
:: + cd /root/stage/app
:: + /snap/bin/bundle config set --local path /root/parts/bundle/install/app/vendor/bundle
:: + /snap/bin/bundle config set --local cache_path /root/parts/bundle/src
:: + /snap/bin/bundle config set --local silence_root_warning true
:: + /snap/bin/bundle config set --local jobs 1
:: + /snap/bin/bundle env
:: ## Environment
::
:: ```
:: Bundler       2.5.22
::   Platforms   ruby, x86_64-linux
:: Ruby          3.3.6p108 (2024-11-05 revision 75015d4c1f6965b5e85e96fb309f1f2129f933c0) [x86_64-linux]
::   Full Path   /snap/ruby/375/bin/ruby
::   Config Dir  /etc
:: RubyGems      3.5.22
::   Gem Home    /root/parts/bundle/install/app/vendor/bundle/ruby/3.3.0
::   Gem Path    /root/parts/bundle/install/app/vendor/bundle/ruby/3.3.0
::   User Home   /root
::   User Path   /root/.local/share/gem/ruby/3.3.0
::   Bin Dir     /root/parts/bundle/install/app/vendor/bundle/ruby/3.3.0/bin
:: Tools
::   Git         2.34.1
::   RVM         not installed
::   rbenv       not installed
::   chruby      not installed
:: Gem.ruby      /snap/ruby/375/bin/ruby
:: bundle #!     /snap/ruby/current/bin/ruby
::
:: ```
::
:: ## Bundler Build Metadata
::
:: ```
:: Built At          2024-11-21
:: Git SHA           unknown
:: Released Version  false
:: ```
::
:: ## Bundler settings
::
:: ```
:: cache_path
::   Set for your local app (/root/stage/app/.bundle/config): "/root/parts/bundle/src"
:: jobs
::   Set for your local app (/root/stage/app/.bundle/config): 1
:: path
::   Set for your local app (/root/stage/app/.bundle/config): "/root/parts/bundle/install/app/vendor/bundle"
:: silence_root_warning
::   Set for your local app (/root/stage/app/.bundle/config): true
:: ```
:: Installing json 2.7.4 with native extensions
:: Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
::
:: current directory:
:: /root/parts/bundle/install/app/vendor/bundle/ruby/3.3.0/gems/json-2.7.4/ext/json/ext/generator
:: /snap/ruby/375/bin/ruby extconf.rb
:: checking for whether -std=c99 is accepted as CFLAGS... *** 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=${opt-dir}/include
::   --without-opt-include
::   --with-opt-lib=${opt-dir}/lib
::   --without-opt-lib
::   --with-make-prog
::   --without-make-prog
::   --srcdir=.
::   --curdir
::   --ruby=/snap/ruby/375/bin/$(RUBY_BASE_NAME)
:: /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:480:in `try_do': The compiler failed to
:: generate an executable file. (RuntimeError)
:: You have to install development tools first.
::
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:606:in `block in try_compile'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:553:in `with_werror'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:606:in `try_compile'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:670:in `try_cflags'
:: from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:1019:in `block (2 levels) in
:: append_cflags'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:983:in `block in checking_for'
:: from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:344:in `block (2 levels) in
:: postpone'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:314:in `open'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:344:in `block in postpone'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:314:in `open'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:340:in `postpone'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:982:in `checking_for'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:1018:in `block in append_cflags'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:1017:in `each'
::   from /snap/ruby/375/lib/ruby/3.3.0/mkmf.rb:1017:in `append_cflags'
::   from extconf.rb:7:in `<main>'

Development tools (build-essential, autoconf, automake, cmake, pkg-config, ...) are installed via build-packages.

paddor avatar Nov 21 '24 09:11 paddor