Nico Brenner
Nico Brenner

Reputation: 737

rbenv fails to install ruby 1.8.7 on MacOS X Sierra

After creating a .ruby-version file with 1.8.7, running rbenv install on the same directory where the file is gives the following error:

ERROR: This package must be compiled with GCC, but ruby-build couldn't find a suitable gcc executable on your system. Please install GCC and try again.

DETAILS: Apple no longer includes the official GCC compiler with Xcode as of version 4.2. Instead, the gcc executable is a symlink to llvm-gcc, a modified version of GCC which outputs LLVM bytecode.

For most programs the llvm-gcc compiler works fine. However, versions of Ruby older than 1.9.3-p125 are incompatible with llvm-gcc. To build older versions of Ruby you must have the official GCC compiler installed on your system.

TO FIX THE PROBLEM: Install Homebrew's apple-gcc42 package with this command: brew tap homebrew/dupes ; brew install apple-gcc42

You will need to install the official GCC compiler to build older versions of Ruby even if you have installed Apple's Command Line Tools for Xcode package. The Command Line Tools for Xcode package only includes llvm-gcc.

BUILD FAILED (OS X 10.12.4 using ruby-build 20170405-2-g3b15693)

Then running brew install apple-gcc42 gives:

apple-gcc42: This formula either does not compile or function as expected on macOS versions newer than Mavericks due to an upstream incompatibility. Error: An unsatisfied requirement failed this build.

Stuck trying to install ruby 1.8.7 through rbenv on MacOS X Sierra. Any ideas on how to fix this?

Upvotes: 3

Views: 1269

Answers (2)

Xiting
Xiting

Reputation: 941

Previous answer looks good, but some updates for it:

You must add the following code not after line 762 (because from version to version lines must be different). You must insert it after:

require_gcc() {
  local gcc="$(locate_gcc || true)"

these lines(for me it was 784 line)

So full tutorial:

Found the solution here: http://xibbar.hatenablog.com

http://xibbar.hatenablog.com/entry/2017/04/28/112813

After running it through Google Translate, got to this:

  • Find ruby-build: which ruby-build
  • Edit it (in my case): vim /usr/local/bin/ruby-build
  • Find the lines like these:

    require_gcc() { local gcc="$(locate_gcc || true)"

  • Add the following code after it:

    local osx_version="$(osx_version)"
    if [ $osx_version = "1012" ]; then
     return 0
    fi
    
  • Run:

    CONFIGURE_OPTS="--with-readline-dir=/usr/local --with-openssl-dir=`brew --prefix openssl`" RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 1.8.7-p374
    

Hope it's useful to others.

Upvotes: 3

Nico Brenner
Nico Brenner

Reputation: 737

Found the solution here: http://xibbar.hatenablog.com

After running it through Google Translate, got to this:

  • Find ruby-build: which ruby-build
  • Edit it (in my case): vim /usr/local/bin/ruby-build
  • Add the following code after line 762:

    local osx_version="$(osx_version)"
    if [ $osx_version = "1012" ]; then
     return 0
    fi
    
  • Run:

    CONFIGURE_OPTS="--with-readline-dir=/usr/local --with-openssl-dir=`brew --prefix openssl`" RUBY_CONFIGURE_OPTS="--with-openssl-dir=`brew --prefix openssl`" rbenv install 1.8.7-p374
    

Hope it's useful to others.

Upvotes: 1

Related Questions