Ruby Tricks 9 - Solving SassC Installation Errors

On Windows, you might face an error installing SassC for use with Rails or with Jekyll, especially if you are using JRuby. Resolving this issue requires having a C/C++ compiler installed on your Windows system and on your path.

Background / Problem

My blog is built using Jekyll and has always used CRuby. I wanted to try to see how it works if I set it up for JRuby (especially as there is an issue filed for slow performance), so I did the usual jgem install jekyll to get the gem installed. Half-way through, it crashed out with this error.

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

    current directory: C:/jruby-
C:/jruby- -I C:/jruby- -r ./siteconf20210609-16440-h3c2ly.rb extconf.rb
creating Makefile

current directory: C:/jruby-
make "DESTDIR=" clean
MAKE Version 5.43  Copyright (c) 1987, 2019 Embarcadero Technologies, Inc.
Fatal: 'clean-so' does not exist - don't know how to make it

current directory: C:/jruby-
make "DESTDIR="
MAKE Version 5.43  Copyright (c) 1987, 2019 Embarcadero Technologies, Inc.
Fatal: 'ast.o' does not exist - don't know how to make it

make failed, exit code 1

Gem files will remain installed in C:/jruby- for inspection.
Results logged to C:/jruby-

I remembered that I had read that SassC which failed can be installed and loaded under JRuby since it uses FFI. So, I was surprised. However, I realised the culprit when reading the error message more carefully:

MAKE Version 5.43  Copyright (c) 1987, 2019 Embarcadero Technologies, Inc.

This was a make on the path that did not know how to deal with the Makefile from the Ruby native extension. A different compiler toolchain should be invoked!

Let’s fix it!

For successfully installing these kinds of gems (for JRuby or Ruby on Windows), you need two main things:

  • A C/C++ compiler and toolchain (including make) that can compile the native code
  • This toolchain needs to be on the path so that when you do make during the gem installation, it finds it

For Ruby developers on Windows, the easiest thing to do is the following:

  • Install a modern Ruby, e.g. Ruby 2.6/ 2.7/ 3.0 together with the DevKit (which installs the compilers, etc.)
  • You might want to use pik so that you can switch between different Ruby versions
  • When installing a native gem, ensure that the DevKit is on your path

When using CRuby on Windows, this will probably happen automatically. It will change the path to bump up the DevKit directories. When using JRuby, especially with pik, it won’t do so. You might find that the installation fails because it cannot find the compiler or finds something else on the path first.

The solution for that is to enable the DevKit. This can be done by doing the following on your command line (I’m assuming Ruby 2.6 since that is installed for me, you’ll need to adjust the path for your case):

c:\Ruby26-x64\ridk_use\ridk.cmd enable

When I do this I get:

$ c:\Ruby26-x64\ridk_use\ridk.cmd enable
$ set "RI_DEVKIT=C:\Ruby26-x64\msys64"
$ set "PKG_CONFIG_PATH=/mingw64/lib/pkgconfig:/mingw64/share/pkgconfig"
$ set "ACLOCAL_PATH=/mingw64/share/aclocal:/usr/share/aclocal"
$ set "MANPATH=/mingw64/share/man"
$ set "MINGW_PACKAGE_PREFIX=mingw-w64-x86_64"
$ set "LANG=en_GB.UTF-8"

With all this done, when I rerun the installation, I happily get:

Building native extensions. This could take a while...
Successfully installed sassc-2.4.0

If you see a similar error even when using CRuby, the fix is the same.

Note! Using SassC

I’m still following this up in this issue but it seems like you will need to keep DevKit on the path when you want to use the SassC gem from JRuby.

When I started jirb and did require sassc it fails with an error:

       16: from org/jruby/ `catch'
       15: from org/jruby/ `catch'
       14: from org/jruby/ `loop'
       13: from org/jruby/ `eval'
       12: from (irb):1:in `evaluate'
       11: from C:/jruby- `require'
       10: from org/jruby/ `require'
        9: from C:/jruby- `<main>'
        8: from org/jruby/ `require_relative'
        7: from org/jruby/ `require'
        6: from C:/jruby- `<main>'
        5: from C:/jruby- `<module:SassC>'
        4: from C:/jruby- `<module:Native>'
        3: from C:/jruby- `ffi_lib'
        2: from org/jruby/ `map'
        1: from C:/jruby- `block in ffi_lib'
Could not open library 'C:/jruby-' : The operation completed successfully.

After the installation steps above, you can check that the DLL file exists at C:/jruby- and so, that’s not the problem.

However, I found that it works if the DevKit is still on the path. So, when I have this as my path, I have no problems:


If I find out more, I will update this post. But till then, assume that you need to have DevKit on the path for running it also. This issue on Sassc-ruby resolves the problem and once it’s rolled out, it should work fine.

I wrote this up because I had run into this earlier and had forgotten what I had done. so I wanted to be able to remember how to do it the next time. Of course, if it helps someone, that’s great! If you have some comments, please add below so that I can reflect changes here. If you are setting up Ruby on Windows, take a look at Installing JRuby on Windows and Installing Ruby 3.0 on Windows both on this site itself.

This issue on GitHub for Rails and this other one for SassC Ruby pointed me to the correct solution.

comments powered by Disqus