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.
Install Ruby
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 !
Great!!!
Thanks! Help me a lot 🙂
Thanks. Very good explanation
Hero of the day, you just saved me a lot of time 🙂 Thanks!
great! thanks!