Error installing rails error failed to build gem native extension

I'm running Crunchbang 11 (Debian-based). I'm trying to install Ruby on Rails, like this: gem install rails --version 4.0.0 I get the error "Failed to build gem native extension". My ruby is v...

I’m running Crunchbang 11 (Debian-based).

I’m trying to install Ruby on Rails, like this:

gem install rails --version 4.0.0

I get the error «Failed to build gem native extension».

My ruby is version 2.0.0p247, my RubyGems is 2.0.0.

What’s the issue here?


This is the full error output:

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

    /home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/bin/ruby extconf.rb
creating Makefile

make
compiling atomic_reference.c
linking shared-object atomic_reference.so

make install
/usr/bin/install -c -m 0755 atomic_reference.so /home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10/lib/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux
/usr/bin/install: cannot create regular file `/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10/lib/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/lib/ruby/site_ruby/2.0.0/x86_64-linux': No such file or directory
make: *** [install-so] Error 1


Gem files will remain installed in /home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10 for inspection.
Results logged to /home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/gems/atomic-1.1.10/ext/gem_make.out

My env:

ORBIT_SOCKETDIR=/tmp/orbit-erlkoenig
SSH_AGENT_PID=2695
rvm_bin_path=/home/erlkoenig/.rvm/bin
GEM_HOME=/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247
SHELL=/bin/bash
TERM=xterm-256color
XDG_SESSION_COOKIE=9e0343c07c890bd2d60ee6a750f36c6c-1373892339.852749-193038580
IRBRC=/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/.irbrc
WINDOWID=39845892
GNOME_KEYRING_CONTROL=/home/erlkoenig/.cache/keyring-g6PRS5
MY_RUBY_HOME=/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247
USER=erlkoenig
LS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arj=01;31:*.taz=01;31:*.lzh=01;31:*.lzma=01;31:*.tlz=01;31:*.txz=01;31:*.zip=01;31:*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lz=01;31:*.xz=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.jpg=01;35:*.jpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:*.cgm=01;35:*.emf=01;35:*.axv=01;35:*.anx=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:*.ra=00;36:*.wav=00;36:*.axa=00;36:*.oga=00;36:*.spx=00;36:*.xspf=00;36:
rvm_path=/home/erlkoenig/.rvm
SSH_AUTH_SOCK=/tmp/ssh-XVmUxMD7LHwi/agent.2651
rvm_prefix=/home/erlkoenig
PATH=/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247/bin:/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247@global/bin:/home/erlkoenig/.rvm/rubies/ruby-2.0.0-p247/bin:/home/erlkoenig/.rvm/bin:/home/erlkoenig/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/erlkoenig/.rvm/bin:/home/erlkoenig/.scripts:/home/erlkoenig/.scripts/netlogo-5.0.3:/opt/node/bin
MAIL=/var/mail/erlkoenig
PWD=/home/erlkoenig
EDITOR=vim
GNOME_KEYRING_PID=2575
LANG=en_US.UTF-8
rvm_env_string=ruby-2.0.0-p247
rvm_version=1.21.9 (stable)
SHLVL=1
HOME=/home/erlkoenig
rvm_ruby_string=ruby-2.0.0-p247
LOGNAME=erlkoenig
GEM_PATH=/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247:/home/erlkoenig/.rvm/gems/ruby-2.0.0-p247@global
DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-9eOdnYZelY,guid=a5db4ca68e107a48a04c8b8e51e3eef4
DISPLAY=:0.0
RUBY_VERSION=ruby-2.0.0-p247
XAUTHORITY=/home/erlkoenig/.Xauthority
COLORTERM=gnome-terminal
_=/usr/bin/env

asked Jul 15, 2013 at 13:47

LonelyWebCrawler's user avatar

LonelyWebCrawlerLonelyWebCrawler

2,8544 gold badges36 silver badges57 bronze badges

5

Rails 4.0 needs RubyGem version 2.0.3, Just update your system by using following command

gem update --system 2.0.3

answered Jul 15, 2013 at 14:54

shrikant1712's user avatar

shrikant1712shrikant1712

4,22623 silver badges42 bronze badges

6

Run the following command:

sudo apt-get install ruby-dev zlib1g-dev liblzma-dev

Then,

sudo gem install rails

Lakhwinder Singh's user avatar

answered Jan 2, 2019 at 6:34

Syed_Shahiq's user avatar

Syed_ShahiqSyed_Shahiq

5476 silver badges12 bronze badges

2

Just a follow up … on different solution…

it may be that you are on a mac and rails cannot find the right compiler for c headers.

just install xcode from apps store / homebrew or go to terminal …

$ xcode-select —install

complete the installation and agree on the licensing etc, then …

$ sudo gem install rails

answered Nov 1, 2016 at 20:04

mirageglobe's user avatar

mirageglobemirageglobe

2,0881 gold badge22 silver badges27 bronze badges

Got the same issue when installing rails with the command
«gem install rails -v 5.1.2» on windows7, solved after installing «MSYS2 and MINGW development toolchain» (command ridk install then option 3)..It took a while to finish the installation and then i installed rails without any problem

answered Jul 17, 2017 at 15:18

Adel Ben Hamadi's user avatar

1

For me this helped:

sudo apt-get install ruby-dev

answered Oct 22, 2020 at 19:22

Irma's user avatar

IrmaIrma

314 bronze badges

1

I could solve this way

rvm use ruby --install --default

and then try again.

gem install rails --no-document

answered Mar 15, 2021 at 23:31

Misael Londoño's user avatar

This worked for me:

sudo ln -s /bin/mkdir /usr/bin/mkdir

I kept encountering this error when I ran gem install rails -v 5.2.0:

make: /usr/bin/mkdir: Command not found
make: *** [Makefile:199: .sitearchdir.-.racc.time] Error 127

make install failed, exit code 2

So I ran this command and it fixed it for me:

sudo ln -s /bin/mkdir /usr/bin/mkdir

Originally found: https://stackoverflow.com/a/64653052

answered Sep 14, 2021 at 17:01

Michgolden Ukeje's user avatar

Try

sudo gem install rails --version 2.0

to install libraries.

answered Sep 29, 2015 at 23:04

Andre Mesquita's user avatar

For anyone got the error:»Failed to build gem native extension”, while running sudo gem install rails, and it said somethings about «nokogiri».

It is possible because you are using the same ruby version as system is using (for mac user). The solution would be install RVM, use RVM to install another ruby version.

So now you have 2 Ruby versions on your machine, RVM will automatically switch to the newly installed version. now, you can run gem install rails without error and without sudo as well.

answered Mar 9, 2018 at 9:46

Trieu Nguyen's user avatar

i’m running elementary os 5 and what i do is.

sudo gem update --system

and then try again.

sudo gem install rails

answered Nov 12, 2018 at 9:12

Edmundo's user avatar

On Fedora 30, I ran into this problem «Failed to build gem native extension». The log error was «gcc: fatal error: cannot read spec file ‘/usr/lib/rpm/redhat/redhat-hardened-cc1’: No such file or directory». The solution was found here.

If you installed all the above, but the extensions would still not compile, you are probably running a Fedora image that misses redhat-rpm-config package. In that case gcc compiler would complain about one of the following:

gcc: error: conftest.c: No such file or directory
gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory
To solve this, simply run sudo dnf install redhat-rpm-config.

answered Jun 15, 2019 at 22:39

Nhan's user avatar

NhanNhan

1,3551 gold badge14 silver badges16 bronze badges

I had the same error when installing rails, but I solved it by running the command: gem install rails without adding sudo.

cosmoonot's user avatar

cosmoonot

2,1633 gold badges31 silver badges38 bronze badges

answered May 3, 2017 at 16:52

Alvaro Alvarez's user avatar

1

I got a similar error installing rails 7.0.4 because of websocket-driver 0.7.5

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

    current directory: /usr/local/bundle/gems/websocket-driver-0.7.5/ext/websocket-driver
/usr/local/bin/ruby -I /usr/local/lib/ruby/3.1.0 -r ./siteconf20221124-7-9o2qxo.rb extconf.rb
creating Makefile

current directory: /usr/local/bundle/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR= clean
current directory: /usr/local/bundle/gems/websocket-driver-0.7.5/ext/websocket-driver
make DESTDIR=
make failedNo such file or directory - make

Gem files will remain installed in /usr/local/bundle/gems/websocket-driver-0.7.5 for inspection.
Results logged to /usr/local/bundle/extensions/aarch64-linux/3.1.0/websocket-driver-0.7.5/gem_make.out

The following command solved my problem

apt install -y build-essential

answered Nov 24, 2022 at 13:43

hfsaito's user avatar

hfsaitohfsaito

391 silver badge3 bronze badges

To check if your version of ruby is set up correctly, you can use the following.

$ which ruby
  /path/to/ruby
$ ruby --version
  ruby 2.1.5p273 (2014-11-13 revision 48405) [x86_64-darwin13.0]

In your case, it looks like ruby is setup fine.
Rvm is just a tool to help you manage your rubies. You’ll know if you don’t like it.

There are clues to why the installation of the gem failed.
Particularly,

checking for Ruby version >= 1.8.5... yes
checking for gcc... yes
checking for Magick-config... no                   <------   There's your problem
checking for pkg-config... yes
checking for ImageMagick version >= 6.4.9... yes

You are missing a library that is required for the gem to build successfully.
This solution suggests it’s available in the repos. So, you should be able to install it with:

sudo apt-get install libmagickwand-dev

Once that is done, you should be able to install the gem.

gem install  pdfbeads

Note: I haven’t tested this solution, and the more prudent reader might notice I’m not even using ubuntu here anymore. Leave a comment if this doesn’t get you sorted.

Installing Ruby on Rails should be a straight forward exercise. At high level, it should be just a matter of installing Ruby and then followed by installing Rails

>apt-get install ruby-full
>gem install rails

In my case, I have hit a few issues and below is the my notes which may be useful to anyone who may experience the same problems.

Firstly, installing Ruby using Debian package manager (apt-get)

>apt-get install ruby-full

The process completed without any error / issue.

Install Rails – nokogiri – You have to install development tools first

After Ruby is install, use Ruby package manager (gem) to install Rails

>gem install rails

Failed with the following error output

...
Fetching: mini_portile2-2.0.0.gem (100%)
Successfully installed mini_portile2-2.0.0
Fetching: nokogiri-1.6.7.gem (100%)
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/usr/bin/ruby2.1 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.

/usr/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
from /usr/lib/ruby/2.1.0/mkmf.rb:571:in `block in try_compile'
from /usr/lib/ruby/2.1.0/mkmf.rb:522:in `with_werror'
from /usr/lib/ruby/2.1.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 /usr/lib/ruby/2.1.0/mkmf.rb:621: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 /var/lib/gems/2.1.0/gems/nokogiri-1.6.7 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/gem_make.out

Checked /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/gem_make.out and it contains the same information above.

The part of the error messages

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.

suggests error occurred when trying to compile some C code.

This part of the error messages

/usr/lib/ruby/2.1.0/mkmf.rb:456:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.

seems to suggests perhaps “development tools” are missing?

Checked /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/mkmf.log and found

"gcc -o conftest -I/usr/include/i386-linux-gnu/ruby-2.1.0 -I/usr/include/ruby-2.1.0/ruby/backward -I/usr/include/ruby-2.1.0 -I. -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC  conftest.c  -L. -L/usr/lib/i386-linux-gnu -L. -Wl,-z,relro -L/build/ruby2.1-uTcziZ/ruby2.1-2.1.5/debian/lib -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.1  -lpthread -lgmp -ldl -lcrypt -lm   -lc "

checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

This suggests that error found when running gcc to compile something. Because of “You have to install development tools first”.

I tried to run gcc (GNU C compiler) directly

>which gcc
>gcc
-su: gcc: command not found

Up to this point, I have not tried to compile any C code on this Debian machine and was not too surprise to see gcc is missing. Check the package database

>dpkg --list | grep compiler
ii  gcc-4.8                        4.8.4-1                   i386         GNU C compiler
ii  libllvm3.5:i386                1:3.5-10                  i386         Modular compiler and toolchain technologies, runtime library
ii  linux-compiler-gcc-4.8-x86     3.16.7-ckt11-1+deb8u6     i386         Compiler for Linux on x86 (meta-package)

It is installed based on the package database but anyway, proceed to install gcc to get the latest version.

>apt-get install gcc

Check gcc after installation

>which gcc
/usr/bin/gcc

The above compile error is resolved but new error appeared.

Install Rails – nokogiri – zlib is missing; necessary for building libxml2

Second attempt to use Ruby package manager (gem) to install Rails and got the following errors

>gem install rails

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

/usr/bin/ruby2.1 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.0.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
*** 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.
...
extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/nokogiri-1.6.7 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/gem_make.out

Note the following line in the output

checking if the C compiler accepts ... yes

indicates that the previous error have been resolved – C compiler is present and working.

Checked /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/gem_make.out and it contains the same information above.

The following part of the error messages

Using mini_portile version 2.0.0
checking for gzdopen() in -lz... no
zlib is missing; necessary for building libxml2
 *** 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.
...
extconf failed, exit code 1

suggests that something is missing when trying to build libxml2.

Checked /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/mkmf.log and found

...
"gcc -o conftest -I/usr/include/i386-linux-gnu/ruby-2.1.0 -I/usr/include/ruby-2.1.0/ruby/backward -I/usr/include/ruby-2.1.0 -I. -D_FORTIFY_SOURCE=2 -D_FILE_OFFSET_BITS=64  -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC  -g -DXP_UNIX -Wall -Wcast-qual -Wwrite-strings -Wconversion -Wmissing-noreturn -Winline conftest.c  -L. -L/usr/lib/i386-linux-gnu -L. -Wl,-z,relro -L/build/ruby2.1-uTcziZ/ruby2.1-2.1.5/debian/lib -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.1 -lz  -lpthread -lgmp -ldl -lcrypt -lm   -lc "
conftest.c:3:18: fatal error: zlib.h: No such file or directory
#include <zlib.h>
^
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <zlib.h>
4:
5: /*top*/
6: extern int t(void);
7: int main(int argc, char **argv)
8: {
9:   if (argc > 1000000) {
10:     printf("%p", &t);
11:   }
12:
13:   return 0;
14: }
15: int t(void) { void ((*volatile p)()); p = (void ((*)()))gzdopen; return 0; }
/* end */

From this part of the messags

conftest.c:3:18: fatal error: zlib.h: No such file or directory

it is clear that zlib.h header file is missing. The missing header file issue is resolved by installing zlib1g-dev package

apt-get install zlib1g-dev

Install Rails – nokogiri – mini_portile.rb:344:in `spawn’: No such file or directory – make (Errno::ENOENT)

Third attempt to use Ruby package manager (gem) to install Rails and got the following errors

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

/usr/bin/ruby2.1 extconf.rb
checking if the C compiler accepts ... yes
Building nokogiri using packaged libraries.
Using mini_portile version 2.0.0
checking for gzdopen() in -lz... yes
...
Running 'configure' for libxml2 2.9.2... OK
Running 'compile' for libxml2 2.9.2... *** 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.
...
--disable-cross-build
/var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:344:in `spawn': No such file or directory - make (Errno::ENOENT)
from /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:344:in `block in execute'
from /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:337:in `chdir'
from /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:337:in `execute'
from /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:111:in `compile'
from /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:150:in `cook'
from extconf.rb:289:in `block (2 levels) in process_recipe'
from extconf.rb:182:in `block in chdir_for_build'
from extconf.rb:181:in `chdir'
from extconf.rb:181:in `chdir_for_build'
from extconf.rb:288:in `block in process_recipe'
from extconf.rb:187:in `tap'
from extconf.rb:187:in `process_recipe'
from extconf.rb:478:in `<main>'

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.1.0/gems/nokogiri-1.6.7 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86-linux/2.1.0/nokogiri-1.6.7/gem_make.out

Checked the make file output file and no additional information available in mkmf.out

This part of the error messages

/var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb:344:in `spawn': No such file or directory - make (Errno::ENOENT)

suggests that errors at line 344 in /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb

Here is the list of line 337 to 345 in /var/lib/gems/2.1.0/gems/mini_portile2-2.0.0/lib/mini_portile2/mini_portile.rb

Dir.chdir (options.fetch(:cd){ work_path }) do
if options.fetch(:initial_message){ true }
message "Running '#{action}' for #{@name} #{@version}... "
end

if Process.respond_to?(:spawn) && ! RbConfig.respond_to?(:java)
args = [command].flatten + [{[:out, :err]=>[log_out, "a"]}]
pid = spawn(*args)
Process.wait(pid)

The “stacktrace” in the error messages match up the method call and line number of the above listing.

Note that ::spawn() is a ruby method – according to Ruby documentation, it spawn a new process and then call exec() and pass a command as parameter.  Errno::ENOENT means specified command in the paramter cannot be found.

I followed the upstream logic flow based on the stack trace  – some command parameter is missing so it seems to be some sort of internal error – highly unlikely the result of missing libraries or header files.

Checked nokogiri site if there known issue which may cause the problem, found the installation and troubleshooting guide for Debian / Ubuntu and followed the provided instructions

> apt-get install build-essential patch
> apt-get install ruby-dev zlib1g-dev

Next, instead of trying to install Rails again, I tried installing nokogiri instead

> gem install nokogiri

and it installed OK and then tried installing Rails again.

> gem install rails

Success !

I run «bundle install».

➜ dailsoncampos git:(Production) ✗ bundle install
Fetching gem metadata from https://rubygems.org/………..
Fetching version metadata from https://rubygems.org/…
Fetching dependency metadata from https://rubygems.org/..
Resolving dependencies…
Using rake 11.1.2
Using i18n 0.7.0
Using json 1.8.3
Using minitest 5.8.4
Using thread_safe 0.3.5
Using builder 3.2.2
Using erubis 2.7.0
Using mini_portile2 2.0.0
Using rack 1.6.4
Using mime-types 2.99
Using arel 6.0.3
Using debug_inspector 0.0.2
Using bundler 1.11.2
Using coffee-script-source 1.10.0
Using execjs 2.6.0
Using thor 0.19.1
Using columnize 0.9.0
Using concurrent-ruby 1.0.1
Using debugger-linecache 1.2.0
Using debugger-ruby_core_source 1.3.8
Using multi_json 1.11.2
Using sass 3.4.22
Using tilt 2.0.2
Using spring 1.6.4
Using sqlite3 1.3.11
Using rdoc 4.2.2
Using tzinfo 1.2.2
Using nokogiri 1.6.7.2
Using rack-test 0.6.3
Using mail 2.6.3
Using binding_of_caller 0.7.2
Using coffee-script 2.4.1
Using uglifier 2.7.2
Using sprockets 3.5.2
Installing debugger 1.6.8 with native extensions

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

/home/campos/.rvm/rubies/ruby-2.1.8/bin/ruby -r ./siteconf20160423-10896-9be59d.rb extconf.rb

*** 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/campos/.rvm/rubies/ruby-2.1.8/bin/ruby
/home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:1401:in initialize': No such file or directory @ rb_sysopen - ./218/ruby_debug.h (Errno::ENOENT) from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:1401:inopen’
from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:1401:in copy_file' from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:483:incopy_file’
from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:400:in block in cp' from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:1579:inblock in fu_each_src_dest’
from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:1593:in fu_each_src_dest0' from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:1577:infu_each_src_dest’
from /home/campos/.rvm/rubies/ruby-2.1.8/lib/ruby/2.1.0/fileutils.rb:399:in cp' from extconf.rb:83:inblock in


from extconf.rb:82:in each' from extconf.rb:82:in

extconf failed, exit code 1

Gem files will remain installed in /home/campos/.rvm/gems/ruby-2.1.8/gems/debugger-1.6.8 for inspection.
Results logged to /home/campos/.rvm/gems/ruby-2.1.8/extensions/x86_64-linux/2.1.0/debugger-1.6.8/gem_make.out
Using sdoc 0.4.1
Using activesupport 4.2.5.1
Using loofah 2.0.3
An error occurred while installing debugger (1.6.8), and Bundler cannot
continue.
Make sure that gem install debugger -v '1.6.8' succeeds before bundling.

1. Да вроде выше я всё написал! Мускуль ставил так:
apt install mariadb-server
или так:
apt install mysql-server
пробовал разные варианты. Потому как натыкался на пост, что сам mysql начиная с версии 5.7 что-то там не того и неплохо бы пользовать Марию. Но к успеху это не привело.
P.S.: Я понимаю, что это обёртка! Мне то она и нужна, чтоб примеры для Руби и SQL попробовать!
2. Забыл добавить! gem install mysql2 тоже пробовал, как один из вариантов решения проблемы. Для меня он так же ничего не поменял! (Разве что ошибка малость другая).
3. Руби ставил просто:
apt install ruby-full
изначально не хотелось избыточности! Никакие Рельсы, РВМ и прочее мне по сути не нужны! Правда в одном из вариантов делал что-то подобное:
gem install rails
Оно прям долго мозгами скрипело, но в результате отработало без ошибок. Но, как говорят англичане, виз но лак! gem install mysql так и не получилось!

UPD1: В очередной раз снёс всё. На чистую Убунту установил gpg и mysql. Потом rvm (по инструкции, без отсебятины). Из rvm установил Руби (опять же по инструкции https://rvm.io/rvm/install). Снова пробую gem install mysql. Ошибка теперь такая:

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

    current directory: /usr/share/rvm/gems/ruby-2.6.3/gems/mysql-2.9.1/ext/mysql_api
/usr/share/rvm/rubies/ruby-2.6.3/bin/ruby -I /usr/share/rvm/rubies/ruby-2.6.3/lib/ruby/2.6.0 -r ./siteconf20191211-4210-8d232p.rb extconf.rb
checking for mysql_query() in -lmysqlclient... no
checking for -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for -lnsl... yes
checking for mysql_query() in -lmysqlclient... no
checking for -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** 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=/usr/share/rvm/rubies/ruby-2.6.3/bin/$(RUBY_BASE_NAME)
        --with-mysql-config
        --without-mysql-config
        --with-mysql-dir
        --without-mysql-dir
        --with-mysql-include
        --without-mysql-include=${mysql-dir}/include
        --with-mysql-lib
        --without-mysql-lib=${mysql-dir}/lib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mlib
        --without-mlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-zlib
        --without-zlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-socketlib
        --without-socketlib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-nsllib
        --without-nsllib
        --with-mysqlclientlib
        --without-mysqlclientlib
        --with-mygcclib
        --without-mygcclib
        --with-mysqlclientlib
        --without-mysqlclientlib

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

  /usr/share/rvm/gems/ruby-2.6.3/extensions/x86_64-linux/2.6.0/mysql-2.9.1/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /usr/share/rvm/gems/ruby-2.6.3/gems/mysql-2.9.1 for inspection.
Results logged to /usr/share/rvm/gems/ruby-2.6.3/extensions/x86_64-linux/2.6.0/mysql-2.9.1/gem_make.out

Сам mkmf.log теперь под 100 Кб. Не знаю, есть ли смысл сюда всё это выкладывать?

UPD2: Прошло несколько суток «изучения». На этом эксперименты заканчиваю. Больше не имею морального права тратить время на Это. Жизнь то не резиновая! Если оно на элементарных вещах требует таких трудозатрат, то нафиг нафиг! Этим надо заниматься, когда у тебя сломаны обе ноги и ты лежишь в больнице и тебе надо скоротать время и вобщем то особо нечем заняться. Печалька!

UPD3: Для таких же бедолаг, как и я. mysql победить не удалось, но mysql2 вроде победим. Итак. Чистая Убунта 18.04. Делаем раз:

apt update
apt install mc
apt install gpg
apt install mysql-server
gpg --keyserver hkp://pool.sks-keyservers.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
apt-get install software-properties-common
apt-add-repository -y ppa:rael-gc/rvm
apt-get update
apt-get install rvm
reboot
rvm install ruby
apt install libmysqlclient-dev
gem install mysql2

I am trying to build my first ruby on rails app using the following guide (http://ruby.railstutorial.org/chapters/a-demo-app#code-demo_gemfile_sqlite_version_redux) and have run into a few obstacles. The first, receiving errors when upgrading to the latest rails version 3.2.8.

bash-3.2$ gem install rails
Building native extensions.  This could take a while...
ERROR:  Error installing rails:
ERROR: Failed to build gem native extension.

/Users/davidmolina/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating Makefile

make
compiling generator.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [generator.o] Error 1

Gem files will remain installed in /Users/davidmolina/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5 for inspection.
Results logged to /Users/davidmolina/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/ext/json/ext/generator/gem_make.out

Even when trying to install from rails app:

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

/Users/davidmolina/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating Makefile

make
compiling generator.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [generator.o] Error 1

Gem files will remain installed in /Users/davidmolina/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5 for inspection.
Results logged to /Users/davidmolina/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/ext/json/ext/generator/gem_make.out

When trying to Bundle Install:

$ bundle install
Could not locate Gemfile

Background details:
Mac OS X Version 10.8.2
Ruby 1.9.3
Rails 2.3.4

I’m wondering if there is a direct one-liner or gem that is missing?

edit: sudo ln -s /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
Then run bundle update rails
Rails 3.2.8 should run now. Thanks to @peterwongpp for the post (http://peterwongpp.com/posts/missing-gcc-4-2-on-mountain-lion).

#ruby-on-rails #linux #ubuntu

#ruby-на-рельсах #linux #убунту

Вопрос:

Я справляюсь с этим https://guides.rubyonrails.org/getting_started.html Я уже завершил большую часть первоначальной настройки и застрял на последней части установки rails.

Версия Ruby — это

ruby 2.7.0p0 (2019-12-25 редакция 647ee6f091) [x86_64-linux-gnu]

Когда я запускаю

 sudo gem install rails
 

Я получаю следующий результат

 redd@tanya:~$ sudo gem install rails
Building native extensions. This could take a while...
ERROR:  Error installing rails:
    ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.7.0/gems/nio4r-2.5.8/ext/nio4r
/usr/bin/ruby2.7 -I /usr/lib/ruby/2.7.0 -r ./siteconf20211210-14142-ms6vi8.rb extconf.rb
checking for unistd.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=/usr/bin/$(RUBY_BASE_NAME)2.7
    --with-unistd-dir
    --without-unistd-dir
    --with-unistd-include
    --without-unistd-include=${unistd-dir}/include
    --with-unistd-lib
    --without-unistd-lib=${unistd-dir}/lib
/usr/lib/ruby/2.7.0/mkmf.rb:471:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
    from /usr/lib/ruby/2.7.0/mkmf.rb:613:in `try_cpp'
    from /usr/lib/ruby/2.7.0/mkmf.rb:1124:in `block in have_header'
    from /usr/lib/ruby/2.7.0/mkmf.rb:971:in `block in checking_for'
    from /usr/lib/ruby/2.7.0/mkmf.rb:361:in `block (2 levels) in postpone'
    from /usr/lib/ruby/2.7.0/mkmf.rb:331:in `open'
    from /usr/lib/ruby/2.7.0/mkmf.rb:361:in `block in postpone'
    from /usr/lib/ruby/2.7.0/mkmf.rb:331:in `open'
    from /usr/lib/ruby/2.7.0/mkmf.rb:357:in `postpone'
    from /usr/lib/ruby/2.7.0/mkmf.rb:970:in `checking_for'
    from /usr/lib/ruby/2.7.0/mkmf.rb:1123:in `have_header'
    from extconf.rb:15:in `<main>'

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

  /var/lib/gems/2.7.0/extensions/x86_64-linux/2.7.0/nio4r-2.5.8/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.7.0/gems/nio4r-2.5.8 for inspection.
Results logged to /var/lib/gems/2.7.0/extensions/x86_64-linux/2.7.0/nio4r-2.5.8/gem_make.out
 

Я уже перепробовал все исправления, упомянутые здесь: https://www.youtube.com/watch?v=ikIOpRnO1x4

Я был бы признателен за любую помощь в решении этой проблемы. Кроме того, если вы знаете процесс поиска решения, пожалуйста, упомяните и об этом. Спасибо вам за уделенное время.

Комментарии:

1. Обычно вы не должны устанавливать драгоценные камни, такие как rails, как sudo. Есть ли у вас такая же проблема без sudo?

2. @SuneNilausen Когда я пытаюсь gem установить rails без sudo. Я получаю «ОШИБКА: при выполнении gem… (Gem::FilePermissionError) У вас нет прав на запись для каталога /var/lib/gems/2.7.0 «.

3. Установите build-essentials и повторите попытку. Кроме того, делитесь деталями ОС, спрашивая о проблемах, связанных с установкой. Для Debian, Mac, M1 mac и т. Д. Все по-другому.

4. @FaizaanKhan Большое вам спасибо. Ваше решение сработало. Моя ОС — Ubuntu версии 20.4 btw. В следующий раз обязательно укажите сведения об ОС.

Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Miha Vičič

Hello!
I’m struggling with the last step of setting up rails.
When I try to install the rail gem I get the following error:
Building native extensions. This could take a while…
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.

/Users/vicic/.rbenv/versions/2.2.0/bin/ruby -r ./siteconf20150119-78332-aigbdm.rb extconf.rb

checking if the C compiler accepts … yes
checking if the C compiler accepts -Wno-error=unused-command-line-argument-hard-error-in-future… no

Building nokogiri using packaged libraries.

The file «/usr/include/iconv.h» is missing in your build environment,
which means you haven’t installed Xcode Command Line Tools properly.

To install Command Line Tools, try running xcode-select --install on
terminal and follow the instructions. If it fails, open Xcode.app,
select from the menu «Xcode» — «Open Developer Tool» — «More Developer
Tools» to open the developer site, download the installer for your OS

version and run it.

*** 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=/Users/vicic/.rbenv/versions/2.2.0/bin/$(RUBY_BASE_NAME)
—help
—clean
—use-system-libraries
—enable-static
—disable-static
—with-zlib-dir
—without-zlib-dir
—with-zlib-include
—without-zlib-include=${zlib-dir}/include
—with-zlib-lib
—without-zlib-lib=${zlib-dir}/lib
—enable-cross-build
—disable-cross-build

extconf failed, exit code 1

Gem files will remain installed in /Users/vicic/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/gems/nokogiri-1.6.5 for inspection.
Results logged to /Users/vicic/.rbenv/versions/2.2.0/lib/ruby/gems/2.2.0/extensions/x86_64-darwin-14/2.2.0-static/nokogiri-1.6.5/gem_make.out

1 Answer

Shani Rivers January 19, 2015 9:51pm

Hi Miha, have you tried installing the Xcode command line tools as suggested in the error message and then retrying the install?

июля 4, 2012  |  Published in Ruby, Ruby Gems, Расширения

So, how to solve the «Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.» problem?

You can solve this problem by adding ‘—with-ruby-include‘ option to ‘gem install‘ command. Firstly, check your current Ruby interpreter version with this:

$ ruby -v
ruby 1.9.3p194 (2012-04-20 revision 35410) [i686-linux]

Or this:

$ rvm current
ruby-1.9.3-p194@r326

Secondly, you should install ruby gem that you want to be installed with this:

$ gem install <ruby gem name> — —with-ruby-include=$rvm_path/src/<ruby version>

For me Ruby version is ruby-1.9.3-p194. Real example:

$ gem install ruby-debug19 — —with-ruby-include=$rvm_path/src/ruby-1.9.3-p194/

Thats all! Happy developing with Ruby, friends!

Понравилась статья? Поделить с друзьями:
  • Error installing prerequisites binaries easyanticheat
  • Error installing package bitrix env
  • Error installing nokogiri error failed to build gem native extension
  • Error installing new device drivers ppjoy will not be operational
  • Error installing ikernel exe 0xa00