1

gem install compass - Failed to build gem native extension, as shown below within Terminal:

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

[THE BASICS]

[Macintosh:~] johnlove% which ruby
/usr/bin/ruby
[Macintosh:~] johnlove% which sass
/usr/local/bin/sass
[Macintosh:~] johnlove% which scss
/usr/local/bin/scss
[Macintosh:~] johnlove% which compass
compass: Command not found.

[MORE BASICS]

[Macintosh:~] johnlove% sass -v
Sass 3.5.5 (Bleeding Edge)
[Macintosh:~] johnlove% scss -v
Sass 3.5.5 (Bleeding Edge)
[Macintosh:~] johnlove% ruby -v
ruby 2.3.7p456 (2018-03-28 revision 63024) [universal.x86_64-darwin18]
[Macintosh:~] johnlove% compass -v
compass: Command not found.

[UPDATE 2]

did this in Terminal:

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

GOT THIS BACK

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.21/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby -I /Library/Ruby/Site/2.3.0 -r ./siteconf20190130-2612-nh9d7t.rb extconf.rb
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/universal-darwin18/rbconfig.rb:215: warning: Insecure world writable dir /usr/local/bin in PATH, mode 040757
checking for ffi.h... no
checking for ffi.h in /usr/local/include,/usr/include/ffi... no
checking for shlwapi.h... no
checking for rb_thread_blocking_region()... no
checking for rb_thread_call_with_gvl()... yes
checking for rb_thread_call_without_gvl()... yes
creating extconf.h
creating Makefile

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.21/ext/ffi_c
make "DESTDIR=" clean

current directory: /Library/Ruby/Gems/2.3.0/gems/ffi-1.9.21/ext/ffi_c
make "DESTDIR="
Running autoreconf for libffi
/Library/Ruby/Gems/2.3.0/gems/ffi-1.9.21/ext/ffi_c/libffi/autogen.sh: line 2: exec: autoreconf: not found
make: *** ["/Library/Ruby/Gems/2.3.0/gems/ffi-1.9.21/ext/ffi_c/libffi-universal-darwin18"/.libs/libffi_convenience.a] Error 127

make failed, exit code 2

end [UPDATE 2]

=====

[UPDATE 1]

I read that my PATHS may not be set up correctly, so I ran:

gem env

and got back:

RubyGems Environment:
  - RUBYGEMS VERSION: 3.0.2
  - RUBY VERSION: 2.3.7 (2018-03-28 patchlevel 456) [universal.x86_64-darwin18]
  - INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.3.0
  - USER INSTALLATION DIRECTORY: /Users/johnlove/.gem/ruby/2.3.0
  - RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/bin/ruby
  - GIT EXECUTABLE: /usr/bin/git
  - EXECUTABLE DIRECTORY: /usr/bin
  - SPEC CACHE DIRECTORY: /Users/johnlove/.gem/specs
  - SYSTEM CONFIGURATION DIRECTORY: /Library/Ruby/Site
  - RUBYGEMS PLATFORMS:
    - ruby
    - universal-darwin-18
  - GEM PATHS:
     - /Library/Ruby/Gems/2.3.0
     - /Users/johnlove/.gem/ruby/2.3.0
     - /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/gems/2.3.0
  - GEM CONFIGURATION:
     - :update_sources => true
     - :verbose => true
     - :backtrace => false
     - :bulk_threshold => 1000
  - REMOTE SOURCES:
     - https://rubygems.org/
  - SHELL PATH:
     - /Library/Frameworks/Python.framework/Versions/Current/bin
     - /usr/local/bin
     - /usr/bin
     - /bin
     - /usr/sbin
     - /sbin

What am I supposed to be looking for if my PATHS are messed up?

Another mystery?

sudo gem install compass

Got back?

ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /usr/bin directory.

I tried to create a LOCAL usr/local/bin directory with full Read and Write permissions.

FAILED!

end [UPDATE 1]

=====

after getting the native extension error, I followed with

compass -v compass: Command not found.

I downloaded and installed the compass.app which now appears in the menubar. I have even created a Compass Project for one of my non-sass projects.

So, how does the Compass.app get successfully installed without the gem compass?

Tried his ...

sudo gem update --system

Got this back ...

Latest version already installed. Done.

Then, I tried this:

sudo apt-get install ruby-dev

Got this:

apt-get: command not found

I did do this:

xcode-select --install

got back:

command line tools are already installed

I guess I cannot blame it on Xcode.

Thanks in advance for saving my mind ...

2 Answers2

1

The two main reasons for the errors in the original post are:

  1. Trying to install compass using the system Ruby (the version of Ruby that comes preinstalled on a Mac).

  2. Using sudo to install compass.

Learn why you shouldn't use the system Ruby to install gems on a Mac.

Learn why you should never use sudo to install gems.

Instead, you need to install a separate version of Ruby.

At a high level, setting up a proper Ruby development environment on a Mac involves six steps:

  1. Install Homebrew (which also installs the prerequisite Apple command line tools)
  2. Install a Ruby version manager (such as chruby, rbenv, asdf, RVM) - most of these can be installed with Homebrew
  3. Configure the Ruby manager by adding the appropriate lines to your shell file (~/.bash_profile or ~/.zshrc) - each manager will have instructions for doing this, and this is a typical step that people miss
  4. Restart the terminal (or open a new tab) for the shell changes to take effect - another step that is often overlooked
  5. Install a specific version of Ruby using the Ruby manager
  6. Switch to that version of Ruby using the Ruby manager

My personal preference is chruby with ruby-install. For more details and a script that can automate this whole process, check out my answer here: https://stackoverflow.com/a/54873916/928191

monfresh
  • 7,974
  • 1
  • 25
  • 22
0

I'm not sure, but did you install build-essential before try to install this gem? It's a commom issue for linux users

Try to install it before install this gem, for example:

sudo apt-get install build-essential

and then, install gem

sudo gem install compass

I made a simple test using docker and it only works when I install it, example:

Didn't work

docker run -it bash ubuntu:16.04 bash
apt-get update
apt-get install ruby2.3 ruby2.3-dev -y
gem install compass

It works

docker run -it bash ubuntu:16.04 bash
apt-get update
apt-get install build-essential ruby2.3 ruby2.3-devel
gem install compass

Why build-essentials?

The build-essentials package is a reference for all the packages needed to compile a Debian package. It generally includes the GCC/g++ compilers and libraries and some other utilities. Check the documentation: Here!

Paulo Victor
  • 3,814
  • 2
  • 26
  • 29