Cannot install rails gem on ruby 2.3.1

2019-09-14 13:50发布

问题:

I am trying to install rails on ruby 2.3.1.

$ ruby -v
ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-linux]

Ruby installed.

$ rvm -v
rvm 1.26.11 (latest) by Wayne E. Seguin <wayneeseguin@gmail.com>, Michal Papis <mpapis@gmail.com> [https://rvm.io/]

RVM exists.

$ gem install rails
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.
current directory: /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.7.0.1/ext/nokogiri
/usr/local/rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20170227-6774-1l4uc6c.rb extconf.rb
Cannot allocate memory - /usr/local/rvm/rubies/ruby-2.3.1/bin/ruby -r ./siteconf20170227-6774-1l4uc6c.rb extconf.rb 2>&1

Gem files will remain installed in /usr/local/rvm/gems/ruby-2.3.1/gems/nokogiri-1.7.0.1 for inspection.
Results logged to /usr/local/rvm/gems/ruby-2.3.1/extensions/x86_64-linux/2.3.0/nokogiri-1.7.0.1/gem_make.out

When I call gem list, I don't see nokogari nor rails. $ gem list

 *** LOCAL GEMS ***
...
minitest (5.8.3)
net-telnet (0.1.1)
pg (0.19.0)
power_assert (0.2.6)
psych (2.0.17)
rack (2.0.1)
rack-test (0.6.3)
raindrops (0.17.0)
rake (10.4.2)
rdoc (4.2.1)
rubygems-bundler (1.4.4)
rvm (1.11.3.9)
test-unit (3.1.5)
...

I donot know what is wrong.

回答1:

The same work around with libxml2 is also needed for sqlite3 byebug i.e.

$ sudo gem install byebug -- --use-system-libraries libxml2

that means: when ever you meet the error-information: couldn't understand kern.osversion `16.4.0' cc1: error: unrecognized command line option "-Wdivision-by-zero"



回答2:

follow instruction here (ignore the japanes, just use the code! http://qiita.com/riocampos/items/43b55ba06e6c3ec01b82

$ brew update

$ brew install libxml2

$ brew link --force libxml2

$ gem install nokogiri -- --use-system-libraries

in case of problems use sudo:

sudo gem install nokogiri -- --use-system-libraries libxml2

guess System 10.2.3 uses incompatible libxml2, so forced linking to the «outdated» libxml2 installed with homebrew does the job.