1

I'm upgrading an existing setup to use Rails 5 beta 3. As part of that, I've upgraded Ruby to version 2.2.4 (using RVM), i.e.

rvm install 2.2.4
rvm use 2.2.4

With that done, I'm trying to install the Rails gem. However, running

sudo gem install rails

gives me the error

ERROR: Error installing mime-types-data: mime-types-data requires Ruby version >= 2.0.

Having read this question, I've looked at my Ruby versions:

ruby --version   =>   ruby 2.2.4p230 (2015-12-16 revision 53155) [x86_64-linux]
sudo ruby --version   =>   ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

I don't seem to be able to access RVM from sudo, so I tried using gem install rails instead, which also fails while building native extensions:

Building native extensions.  This could take a while...
ERROR:  Error installing rails:
        ERROR: Failed to build gem native extension.

    /home/ubuntu/.rvm/rubies/ruby-2.2.4/bin/ruby -r ./siteconf20160405-31973-l7bzq7.rb extconf.rb
checking if the C compiler accepts ... *** 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/.rvm/rubies/ruby-2.2.4/bin/$(RUBY_BASE_NAME)
        --help
        --clean
/home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
        from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `block in try_compile'
        from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:522:in `with_werror'
        from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:571:in `try_compile'
        from extconf.rb:80:in `nokogiri_try_compile'
        from extconf.rb:87:in `block in add_cflags'
        from /home/ubuntu/.rvm/rubies/ruby-2.2.4/lib/ruby/2.2.0/mkmf.rb:619:in `with_cflags'
        from extconf.rb:86:in `add_cflags'
        from extconf.rb:336:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /home/ubuntu/.rvm/gems/ruby-2.2.4/gems/nokogiri-1.6.7.2 for inspection.
Results logged to /home/ubuntu/.rvm/gems/ruby-2.2.4/extensions/x86_64-linux/2.2.0/nokogiri-1.6.7.2/gem_make.out

I see two solutions to this:

  1. Upgrade the Ruby that's used in sudo commands to 2.0 or above (preferably 2.2.4). I can't figure out how to do this, because sudo rvm results in command not found for rvm.
  2. Fix the error that comes up when using gem install rails. Again, I don't know how to do this.

Which of these is the easiest (or is there an easier fix), and how do I do it?

2 Answers 2

2

It looks like you have installed RVM in single user mode. This is the reason why sudo rvm returns command not found error. You can find more about RVM modes here: https://rvm.io/rvm/install#2-load-rvm-into-your-shell-sessions-as-a-function.

But, based on log your provided, the error is in installing Nokogiri. Please install development header files first with command sudo apt-get install ruby-dev zlib1g-dev liblzma-dev. For details follow: http://www.nokogiri.org/tutorials/installing_nokogiri.html

2
  • 1
    Well Nokogiri installs correctly now, cheers! We'll see what the Rails install does in a minute.
    – ArtOfCode
    Commented Apr 5, 2016 at 17:18
  • Cool! Let me know how it goes. Commented Apr 5, 2016 at 17:57
0

The sudo command that you invoke will be executed as the root user, hence it won't load your profile settings (which is where the rvm ruby version is loaded, if it works like rbenv which is what I use, never used rvm)

On the other hand, whenever a Building native extensions fail when installing a gem it means that you need the development packages (C/C++ header files) for a library that is the one that actually does the whole thing (ruby gems are usually wrappers around it), so for instance, if you want to build ruby you will need the ruby development package from your linux distribution (or from brew if you use OSX), the development package from postgres to build pg gem, etc.

Not the answer you're looking for? Browse other questions tagged or ask your own question.