301

When I attempt to install the latest version of compass (https://rubygems.org/gems/compass/versions/1.0.0.alpha.17), I get the following error.

ERROR:  Error installing compass:
ERROR: Failed to build gem native extension.

 ERROR:  Error installing compass:
  ERROR: Failed to build gem native extension.

    /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby extconf.rb
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... yes
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... no
checking for rb_thread_blocking_region()... yes
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
checking for ffi_prep_cif_var()... no
creating extconf.h
creating Makefile

make "DESTDIR=" clean

make "DESTDIR="
compiling AbstractMemory.c
compiling ArrayType.c
compiling Buffer.c
compiling Call.c
Call.c:303:5: warning: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Wimplicit-function-declaration]
    rbffi_thread_blocking_region(call_blocking_function, data, (void *) -1, NULL);
    ^
./Thread.h:78:39: note: expanded from macro 'rbffi_thread_blocking_region'
# define rbffi_thread_blocking_region rb_thread_call_without_gvl
                                      ^
1 warning generated.
compiling ClosurePool.c
compiling DataConverter.c
DataConverter.c:43:1: warning: control may reach end of non-void function [-Wreturn-type]
}
^
1 warning generated.
compiling DynamicLibrary.c
compiling ffi.c
compiling Function.c
Function.c:479:33: warning: incompatible pointer types passing 'VALUE (void *)' to parameter of type 'void *(*)(void *)' [-Wincompatible-pointer-types]
        rb_thread_call_with_gvl(callback_with_gvl, &cb);
                                ^~~~~~~~~~~~~~~~~
Function.c:102:46: note: passing argument to parameter 'func' here
extern void *rb_thread_call_with_gvl(void *(*func)(void *), void *data1);
                                             ^
Function.c:563:9: warning: implicit declaration of function 'rb_thread_call_without_gvl' is invalid in C99 [-Wimplicit-function-declaration]
        rb_thread_call_without_gvl(async_cb_wait, &w, async_cb_stop, &w);
        ^
Function.c:738:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
3 warnings generated.
compiling FunctionInfo.c
compiling LastError.c
compiling LongDouble.c
compiling MappedType.c
compiling MemoryPointer.c
compiling MethodHandle.c
compiling Platform.c
compiling Pointer.c
compiling Struct.c
compiling StructByReference.c
compiling StructByValue.c
compiling StructLayout.c
compiling Thread.c
compiling Type.c
compiling Types.c
compiling Variadic.c
linking shared-object ffi_c.bundle
clang: error: unknown argument: '-multiply_definedsuppress' [-Wunused-command-line-argument-hard-error-in-future]
clang: note: this will be a hard error (cannot be downgraded to a warning) in the future
make: *** [ffi_c.bundle] Error 1

make failed, exit code 2

Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/ffi-1.9.3 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-13/2.0.0/ffi-1.9.3/gem_make.out

What's going on here? How do I install the latest compass without error?

2

26 Answers 26

603

Try this, then try to install compass again

apt-get install ruby-dev
11
  • 40
    This fixes the error on Ubuntu, but it seems OP is using OSX.
    – mhnagaoka
    Oct 8, 2014 at 5:33
  • 30
    Worked on CentOS with "yum install ruby-devel" which is the equivalent. Thanks !
    – B2F
    Mar 6, 2015 at 13:19
  • 8
    Funny to find a solution to my Ubuntu problem in an answer to an OSx question. Nevertheless, you’ve got my upvote as your answer just solved my problem. Tnx!
    – e-sushi
    Mar 15, 2015 at 6:06
  • 2
    I think installing ruby-dev helped, but I also had to install gcc & make. The errors are not very clear about that.
    – Balmipour
    Oct 19, 2016 at 15:00
  • 3
    Any idea how to get this to work on Windows? I installed the Ruby dev tools using choco install ruby2.devkit but it's still not working
    – jtate
    Oct 24, 2017 at 16:32
141

In order to install compass On Mac OS X 10.10 (Yosemite)had to perform the following:

1. Set Up Ruby Environment

  • Ensure ruby is installed and up to date: ruby -v
  • Update gem's sudo gem update --system

2. Set Up MAC Environment

Install the Xcode Command Line Tools this is the key to install Compass.

xcode-select --install

Installing the Xcode Command Line Tools are the key to getting Compass working on OS X

3. Install Compass

sudo gem install compass
5
  • 3
    For me this was exactly the right answer, it needs the Xcode command line tools
    – svnm
    Dec 18, 2014 at 23:43
  • 2
    Thanks, worked for me, you are right, the Xcode Command Line Tools are the key.
    – marsaldev
    May 11, 2015 at 12:02
  • 5
    This worked for me with one addition - you have to actually start XCODE so that you can accept the license agreement and let it finish setup. Might be worth tagging onto your answer.
    – Bruford
    Jun 17, 2015 at 14:06
  • Accepting the update(terms of agreement) through the GUI worked also. Sep 25, 2015 at 14:08
  • On a recently updated MacBook Pro to Sierra 10.12.6, I also had to run "sudo xcodebuild -license" to accept terms and conditions, before running sudo gem install compass....
    – Joserra
    Sep 27, 2017 at 15:35
48

The best way is sudo apt-get install ruby-compass to install compass.

1
  • 1
    Wow, sometimes it's so easy ^^ tried to install compass with gem, but there were some dependencies not resolved by gem. With apt-get it worked fine! Thanks
    – stollr
    Sep 16, 2015 at 19:42
39

You can try in Debian with

sudo apt-get install gcc ruby-dev rubygems compass

for Fedora, Centos

yum -y install gcc ruby-devel rubygems compass

It worked for me.

2
30

I struggled with you same issue for about 3 hours. As of Compass 1.0.alpha19, the requirement is for the rvm version 1.9.3.

There are several uncollected posts, however what worked for me was the following:

  1. sudo gem uninstall sass
  2. sudo gem uninstall compass
  3. rvm install ruby-1.9.3-p448
  4. sudo gem install sass --pre
  5. sudo gem install compass --pre

and that did it. Hope it works for you as well!

2
  • I recently had the same issue but with a newer version. What I did is to uninstall the ruby version I installed previously with aptitude and then I installed it again with following the instructions at: rvm.io/rvm/install. With the new ruby/rvm version compass built properly.
    – adosaiguas
    May 7, 2014 at 23:19
  • 2
    Thanks for this, very helpful. I changed step 3 to rvm install ruby-2.1.2 as 1.9.3 is no longer being updated
    – timelfelt
    Aug 13, 2014 at 16:47
25

For me to solve this issue, I had to make sure I had the most current version of Ruby and the gems gem update --system; then, I had to make sure that Xcode & the Command Line Tools were installed: xcode-select --install.

1
  • 2
    xcode-select --install was done but this doesn't solve it for me
    – Ade
    Jun 7, 2019 at 16:12
15

On Mac OS you need to install this feature!

xcode-select --install
1
  • macOS 11.2 BigSur trying to install sudo gem install compass with OP error. Installing xcode fixed it and I can finally install compass. Mucha gracias!
    – leymannx
    Mar 4, 2021 at 16:41
14

If you are using Ubuntu, you should try install build-essential

apt install build-essential

I had troubles with gems installation on fresh installation of ubuntu, and this solution worked for me.

2
  • I had the same problem. Some more people should upvote this.
    – Sorter
    Dec 25, 2018 at 15:49
  • This is the answer for me. Jan 26, 2022 at 2:45
11

Hi it was a challenge to get it work on Mac so anyway here is a solution

  1. Install macports
  2. Install rvm
  3. Restart Terminal
  4. Run rvm requirements then run rvm install 2.1
  5. And last step to run gem install compass --pre

I'm not sure but ruby version on Mavericks doesn't support native extensions etc... so if you point to other ruby version like I did "2.1" it works fine.

1
  • I would recommend not using macports.
    – nomis
    Apr 8, 2015 at 6:14
6

Not sure why none of these are marked as the correct answer, but I landed here through a google search, so I will pass along what I know...

@paul_g's method was pretty close for me, my steps on a Mac osx10.9 Retina:

  • Install macports
  • Install rvm (stable with ruby add --insecure flag for SSL related issues) $\curl -sSL --insecure https://get.rvm.io | bash -s stable --ruby
  • Restart Terminal / Resource your profile
  • Run rvm requirements --with-gcc=clang You won't have to update Ruby because you downloaded the last stable version
  • And last step to run gem install compass --pre
6
sudo gem update --system
sudo gem install compass 
0
5

For Mac OS:

My error was I forgot to select option in XCode - Preferences - Locations - Command Line Tools after new XCode installation (I had 2 versions and later I deleted one). Maybe it will help someone.

enter image description here

4

You could need to install Apple's Command Line Tools, which probably aren't installed on your system by default. I was getting the same error, but before following any of the instructions here I installed Command Line Tools (due to an unrelated issue) and lo and behold compass installed without issue when I tried again. YMMV.

1
  • This solved the above issue for me, so I would say this is an acceptable answer to the above question. Oct 2, 2014 at 13:17
4

In order to install Compass on Yosemite you need to set up the Ruby environment and to install the Xcode Command Line Tools. But, most important thing, after updating Xcode, be sure to launch the Xcode application and accept the Apple license terms. It will complete the installation of the components. After that, you can install Compass: sudo gem install compass

4

For macOS 10.14 Mojave, make sure you have already installed command line tools via xcode-select --install and the run the following command to install std headers.

sudo open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg

Now try your command again.

0
3

you must have gcc,json_pure

i collect some information from several post

sudo gem uninstall sass
sudo gem uninstall compass
sudo gem update --system
gem install json_pure   (if you have already have continued to next step)
sudo yum install gcc gcc-c++   (if you have already have continued to next step)
sudo gem install sass

sudo gem install compass

Hi if ** sudo gem update --system ** not working you got an error in the update then use

sudo gem update --system 2.7.8

2
  • I also had to run sudo yum install -y redhat-rpm-config for Fedora 24 before installing compass because of this error: gcc: error: /usr/lib/rpm/redhat/redhat-hardened-cc1: No such file or directory Apr 4, 2017 at 22:43
  • sudo gem update --system gave me errors: ERROR: While executing gem ... (Errno::EPERM) Operation not permitted @ rb_sysopen - System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/gem :(
    – Ade
    Jun 7, 2019 at 16:17
2

On yosemite, all you must do is install the command line tools. then it works.

Even if other gems installed fine. You must run xcode-select --install for gem install compass to work.

Good luck.

2

On Mac OS X 10.9, if you try xcode-select --install, you will get the following error :

Can't install the software because it is not currently available from the Software Update server.

The solution is to download Command Line Tools (OS X 10.9) directly from Apple website : https://developer.apple.com/downloads/index.action?name=for%20Xcode%20-

You will then be able to install the last version of Command Line Tools.

2

In ubuntu 14.04, while execute apt-get install rubygems, there is a error

E: Package 'rubygems' has no installation candidate

follow command solve the problems.

sudo apt-get install gcc ruby-devel rubygems-integration ruby-compass

2

Try brew install coreutils.

I've hit this problem while rebuilding an aging sass/compass project that was recently updated to ruby 2.2.5 by a colleague. The project uses rvm and bundler. These were my commands

$ rvm install ruby-2.2.5
$ rvm use ruby-2.2.5
$ gem install bundler
$ bundle install

This caused me to hit the famed ffi installation errors, that are reported around the StackOverflow environment:

An error occurred while installing ffi (1.9.14), and Bundler cannot continue.

Most of the suggestions to solve this problem are to install Xcode command line tools. However this was already installed in my environment:

$ xcode-select -p
/Library/Developer/CommandLineTools

Other suggestions said to install gcc... so I tried:

$ brew install gcc46

But this also failed due to a segmentation fault... ¯\_(ツ)_/¯.

So, I then tried installing compass by hand, just to see if it would give the same ffi error:

$ gem install compass

But to my surprise, I got a totally different error:

make: /usr/local/bin/gmkdir: No such file or directory

So I searched for that issue, and found this ancient blog post that said to install coreutils:

$ brew install coreutils

After installing coreutils with Homebrew, bundler was able to finish and installed compass and dependencies successfully.

The End.

2

when

gem install overcommit

is run also this error have been placed in terminal.

Failed to build gem native extension

please do the same

xcode-select --install

and it will fix that issue too

1
  • 1
    I get xcode-select: error: command line tools are already installed, use "Software Update" to install updates. This doesn't fix it.
    – Ade
    Jun 7, 2019 at 16:20
1

Try this, then try to install compass again

sudo apt install ruby-full
0

I had the same problem on Linux Mint but I was able to fix it by uninstalling ruby and install it again.

Uninstall ruby:

sudo apt-get remove ruby

It reported some ruby packages like:

Package 'ruby' is not installed, so not removed
The following packages were automatically installed and are no longer required:
libruby2.2 ruby-chunky-png ruby-sass rubygems-integration
Use 'apt-get autoremove' to remove them.

Uninstall remaining packages*

apt-get autoremove

Install ruby again

sudo apt-get install ruby2.2

Install Compass

sudo gem install compass

The last command was executed with success.

0

First had to upgrade from Ruby 2.6 to 3.0 (see https://rvm.io/):

$ curl -sSL https://get.rvm.io | bash -s stable --ruby
$ source /Usrs/myuser/.rvm/scripts/rvm

Then I had to install it in local because otherwise Mac OSX permissions won`t let me upgrade it (see ERROR: While executing gem ... (Errno::EPERM) Operation not permitted):

$ sudo gem install -n /usr/local/bin compass

I am not totally sure if installing rvm above first was necessary, but it was useful for upgrading ruby.

0

for me it happened after a xcode software update.

had to execute:

sudo xcodebuild -license

as after an update you need to "agree" again to xcode license

-1

Installing Ruby gems on a Mac is a common source of confusion and frustration. Unfortunately, most solutions are incomplete, outdated, and provide bad advice. The answer here with the most votes says to use sudo which you should never need to do, especially if you don't understand what it does.

Learn why you should never use sudo to install gems.

It is correct that the error "Failed to build gem native extension" is due to the Apple command line tools not being installed. However, installing them won't necessarily provide you with a proper Ruby environment.

At a high level, there are 5 steps to a working Ruby setup, which I've written about in detail in my definitive guide to installing Ruby gems on a Mac. It explains why you are getting this error, compares the various solutions, why some are better than others, and why you shouldn't use sudo.

I've also written about these steps in this answer: https://stackoverflow.com/a/54873916/928191

Not the answer you're looking for? Browse other questions tagged or ask your own question.