2

Im currently using a fresh install of ubuntu 18.04.2 LTS through windows subsystem for linux. I installed ruby using

sudo apt-get install ruby2.5-dev

and I'm trying to install rails by using

gem install rails -v 5.2.3

which gives me a Gem::FilePermissionError error, fixable by using sudo, but multiple sources online say not to use sudo for installing gems, though they seem to all be using MacOS.

When I ignore them and try to install using sudo, I get this:

    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.5.0/gems/nokogiri-1.10.7/ext/nokogiri
/usr/bin/ruby2.5 -r ./siteconf20200123-2772-1f46u2w.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=/usr/bin/$(RUBY_BASE_NAME)2.5
        --help
        --clean
/usr/lib/ruby/2.5.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.5.0/mkmf.rb:574:in `block in try_compile'
        from /usr/lib/ruby/2.5.0/mkmf.rb:521:in `with_werror'
        from /usr/lib/ruby/2.5.0/mkmf.rb:574:in `try_compile'
        from extconf.rb:138:in `nokogiri_try_compile'
        from extconf.rb:162:in `block in add_cflags'
        from /usr/lib/ruby/2.5.0/mkmf.rb:632:in `with_cflags'
        from extconf.rb:161:in `add_cflags'
        from extconf.rb:416:in `<main>'

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

  /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.7/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.5.0/gems/nokogiri-1.10.7 for inspection.
Results logged to /var/lib/gems/2.5.0/extensions/x86_64-linux/2.5.0/nokogiri-1.10.7/gem_make.out

I can't seem to find a way to install 'development tools' without it being an exe file for use in windows, nor am I too sure what 'development tools' I actually need.

mkmf.log says this:

    "gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.5.0 -I/usr/include/ruby-2.5.0/ruby/backward -I/usr/include/ruby-2.5.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fdebug-prefix-map=/build/ruby2.5-B0MvC_/ruby2.5-2.5.1=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC  conftest.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.5  -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 */

And I have no idea what that means. Any help would be appreciated.

HeyItsGwen
  • 55
  • 1
  • 7

1 Answers1

4

You are missing a compiler, and probably a lot of other essential libraries and tools from your WSL setup. Hopefully this will cover most of what you need:

sudo apt-get install build-essential
sudo apt-get install libxml2-dev libsqlite3-dev zlib1g-dev liblzma-dev
Casper
  • 33,403
  • 4
  • 84
  • 79
  • Unbelievable. I followed all the instructions [here](https://stackify.com/install-ruby-on-windows-everything-you-need-to-get-going/) and installed Ruby on Windows 10 WSL. I immediately ran into issues installing any gems and read through countless SO posts about permissions, using brew, rvm and rbenv, DevKit, MSYS2, etc. Wasted 6 hours of my life. These 2 lines fixed everything. Thank you Casper! – Luke Aug 26 '20 at 09:01
  • Actually, I spoke too soon. Another 4 hours dealing with unspecific error messages and reading more countless threads and I gave up. Ditched Windows WSL and used Ruby Installer. Had everything working (actually working) within 15 minutes. – Luke Aug 26 '20 at 13:30
  • awesome! solved the issue with unf_ext on WSL2 Ubuntu for me – mishkin Jan 13 '22 at 21:54