简体   繁体   中英

Error when installing Ruby gem Mechanize on AWS Linux

UPDATE : I ran sudo yum install ruby-devel , then sudo gem install mechanize , which gave me this error:

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

    /usr/bin/ruby2.0 extconf.rb
checking for main() in -lstdc++... *** 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}/lib64
    --with-make-prog
    --without-make-prog
    --srcdir=.
    --curdir
    --ruby=/usr/bin/ruby2.0
    --with-static-libstdc++
    --without-static-libstdc++
    --with-stdc++lib
    --without-stdc++lib
/usr/share/ruby/2.0/mkmf.rb:434:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/share/ruby/2.0/mkmf.rb:519:in `try_link0'
    from /usr/share/ruby/2.0/mkmf.rb:534:in `try_link'
    from /usr/share/ruby/2.0/mkmf.rb:720:in `try_func'
    from /usr/share/ruby/2.0/mkmf.rb:950:in `block in have_library'
    from /usr/share/ruby/2.0/mkmf.rb:895:in `block in checking_for'
    from /usr/share/ruby/2.0/mkmf.rb:340:in `block (2 levels) in postpone'
    from /usr/share/ruby/2.0/mkmf.rb:310:in `open'
    from /usr/share/ruby/2.0/mkmf.rb:340:in `block in postpone'
    from /usr/share/ruby/2.0/mkmf.rb:310:in `open'
    from /usr/share/ruby/2.0/mkmf.rb:336:in `postpone'
    from /usr/share/ruby/2.0/mkmf.rb:894:in `checking_for'
    from /usr/share/ruby/2.0/mkmf.rb:945:in `have_library'
    from extconf.rb:6:in `<main>'


Gem files will remain installed in /usr/local/share/ruby/gems/2.0/gems/unf_ext-0.0.7.2 for inspection.
Results logged to /usr/local/share/ruby/gems/2.0/gems/unf_ext-0.0.7.2/ext/unf_ext/gem_make.out

Original below:

When I run sudo gem install mechanize on my Amazon AWS Linux vritual machine, I get this error:

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

    /usr/bin/ruby2.0 extconf.rb
mkmf.rb can't find header files for ruby at /usr/share/ruby/include/ruby.h


Gem files will remain installed in /usr/local/share/ruby/gems/2.0/gems/unf_ext-0.0.7.2 for inspection.
Results logged to /usr/local/share/ruby/gems/2.0/gems/unf_ext-0.0.7.2/ext/unf_ext/gem_make.out

When I run yum install ruby-dev , I get this message:

Loaded plugins: priorities, update-motd, upgrade-helper
amzn-main/latest                                                                | 2.1 kB     00:00     
amzn-updates/latest                                                             | 2.3 kB     00:00     
No package ruby-dev available.
Error: Nothing to do

I want to install the Ruby gem Mechanize on this machine. What must I do to make this happen?

I had to install a bunch of packages first.

sudo yum install zlib-devel gcc gcc-c++ ruby-devel rubygems

And then:

sudo gem install mechanize

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM