Failed to build gem native extension (mkmf (LoadEr

2020-02-14 03:52发布

问题:

Hey I'm trying to install rails on a new ubuntu machine. I have ruby and rvm installed but I'm getting a "failed to build gem native extension" error. What does this mean?

$ sudo gem install rails -v 3.2.9

(without the sudo says I don't have permissions)

Then it outputs a lot of 'fetching' commands and ultimately this error:

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

            /usr/bin/ruby1.9.1 extconf.rb
    /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
        from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
        from extconf.rb:1:in `<main>'


    Gem files will remain installed in /var/lib/gems/1.9.1/gems/json-1.8.0 for inspection.
    Results logged to /var/lib/gems/1.9.1/gems/json-1.8.0/ext/json/ext/generator/gem_make.out

When I type

$rails server

It says rails is not currently installed

回答1:

Possible duplicate of:

Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)

Depending on your ruby version, run:

sudo apt-get install ruby1.9.1-dev


回答2:

If you are using RVM, you shouldn't ever be using 'sudo'. Using sudo calls libs and such out of the rvm path. Try just a flat:

gem install rails -v3.2.9

and see if that helps.