rbenv fails to install ruby 1.8.7 on MacOS X Sierra - ruby

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?

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.

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.

Related

macOS Mojave 'ruby/config.h' file not found

When I try to build vim(8.1.0509) with ruby support(--enable-rubyinterp) on macOS Mojave(10.14.1) I get error:
In file included from /System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error:
'ruby/config.h' file not found
#include "ruby/config.h"
I have installed Xcode 10.1.
xcode-select -p
/Applications/Xcode.app/Contents/Developer
Note: this workaround works, but you can't just copy/paste paths blindly. Instead, look at the error installation gave you. It will say something like
To see why this extension failed to compile, please check the mkmf.log which can be found here:
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/mkmf.log
So open the log it mentions, and see what it can't find. It will tell you the correct versions of MacOSX__._.sdk and universal-darwin-__ you need to link
Catalina, Big Sur, etc. (As of 2020, 2021, and 2022)
UPDATE: This workaround still works as of 2022. For the commands below, please change version string (e.g., 11.1, ruby 2.6, universal-darwin20, etc.) accordingly to your macOS version environment.
Recent versions of macOS and Xcode (e.g. Catalina 10.15 and Xcode 12.2) have this broken. Reinstalling Xcode and xcode-select --install did not help for me at all (the solutions already posted seem to be outdated). I did not want to use rvm because it may cause some annoying problems.
I did a workaround by manually making a symbolic link:
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby
ln -sf ../../../../Headers/ruby/config.h
where ruby/config.h can be found at:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/Headers/ruby/config.h.
You should change SDK versions (e.g. 11.1 in the above example) accordingly to your current xcode installation.
It is also very likely that one runs into another error where .../universal-darwin19/ruby/config.h cannot be found (Commonmarker gem cannot be installed (needed for jekyll) macos). It can be quick-fixed as follows:
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0
ln -sf universal-darwin20 universal-darwin19
If after using this workaround, you get a crash on pod install like:
/Library/Ruby/Gems/2.6.0/gems/ffi-1.15.5/lib/ffi/library.rb:275: [BUG] Bus Error at 0x0000000100f38000
follow this solution
macOS Catalina
Issue reappeared in Catalina and I wasn't able to spot this package in the Developer SDK. Until better solution found, I was able to workaround this with rubyenv: https://github.com/orta/cocoapods-keys/issues/198#issuecomment-510909030
brew install rbenv ruby-build
echo 'if which rbenv > /dev/null; then eval "$(rbenv init -)"; fi' >> ~/.bash_profile
rbenv install 2.6.3
rbenv global 2.6.3
Mojave and older
This answer helped me: https://stackoverflow.com/a/53194299/2105993
xcode-select --install
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
On macOS Catalina
After installing and uninstalling the developer tools multiple times, this is the only thing that worked for me:
First install the Ruby Version Manager rvm:
curl -L https://get.rvm.io | bash -s stable
Then install the latest version of ruby:
rvm install ruby-2.7.2
Finally try again to install the cocoapods:
sudo gem install cocoapods
(from this answer: https://stackoverflow.com/a/65033418/3605761)
edit: may need rvm reinstall ruby-2.7.2 instead of rvm install ruby-2.7.2 at step 2.
edit2: #greg-dubicki mentioned swapping ruby-2.7.2 for ruby-3.0.3: rvm install ruby-3.0.3 and then making it the default: rvm --default use 3.0.3 they also mentioned: As an extra benefit, thanks to the switch from the outdated system Ruby 2 to a current version 3, you will get up to 3 x better performance.
I had the exact same problem. Could not install gems with native extensions. Running
$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
failed, because the file did not exist. Looks like Mojave can break the commandline tools.
I fixed it by removing the Xcode commandline tools, installing them again and then installing the missing headers:
$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
$ open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
If you are facing this issue in Mac Big Sur, reinstalling CommandLineTools can fix this issue.
sudo rm -rf /Library/Developer/CommandLineTools
xcode-select --install
This is because some versions of Xcode don't have the macOS SDK for the OS it's running on, when compiling native extension of gem.
make sure Xcode version and macOS version match each other:
macOS 10.15: Xcode < 12.2
macOS 11: Xcode >= 12.2, <= 13.0
macOS 12: Xcode >= 13.1, <= 14.0
macOS 13: Xcode >= 14.1
On macOS Catalina
If multiple versions of xcode are installed,xcode12/xcode12.4 etc.Please try to change your xcode command line tools in xcode preferences. It may works!!!
I tried all of the above and I eventually got it working with this little 'gem', pardon the pun.
sudo gem install -n /usr/local/bin cocoapods -v 1.8.4
From https://developer.apple.com/forums/thread/668456
2021 Advice
If you are able, updating to macOS Big Sur and then updating Xcode will also fix the issue.
Just tested on updating 10.15 -> 11.2.3 for macOS.
And 12.4 for Xcode.
MacOS Big Sur Beta 8
try this:
install rbenv
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
cd ~/.rbenv && src/configure && make -C src
Add ~/.rbenv/bin to your $PATH for access to the rbenv command-line utility.
see: https://github.com/rbenv/rbenv#basic-github-checkout
make sure export PATH="$HOME/.rbenv/shims:${PATH}" was added to your $PATH
xcode-select --switch /Applications/Xcode.app/Contents/Develope
gem install cocoapods should work like a charm!
for me it worked "rvm install ruby" (not with brew) and then doing steps from here:
$ sudo rm -rf /Library/Developer/CommandLineTools
$ xcode-select --install
and then
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
After all this, it worked.
I did the similar things to Jongwook Choi with the following environment and problem as a case reference.
I am using macOS 12.6.2.
The problem arises when I try to install cocoapods by running sudo gem install cocoapods.
After reading the suggested logs in the terminal feedback and reading the source code it is referring to, it is obviously a bug of the builtin files in macOS 12.6.2.
In my case, I do the followings and the cocoapods can be installed successfully.
Original error
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
Action 1
The file `config.h` is missing. So I build the symbolink in the folder
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22/ruby/config.h
The second one is referring to a folder called universal-darwin21.
However, I try to use uname -r and got 21.6 so I think it is obviously does not hurt to create a symbolink of "universal-darwin21" to resolve the problem.
Original error
make: *** No rule to make target `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX13.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin21/ruby/config.h', needed by `AbstractMemory.o'. Stop.
Action 2
cd /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0
sudo ln -s /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/universal-darwin22 universal-darwin21
After that, the installation runs successfully.
However, if reading the log file
/Library/Ruby/Gems/2.6.0/extensions/universal-darwin-21/2.6.0/ffi-1.15.5/gem_make.out
It is still outing some warnings, if study those warnings, will find missing folders which is obviously missing and is the problem of the system files/folders rather than anything wrong with the user actions.
My problem was different from - Yosemite upgrade broke ruby.h
As you can see in the description of the problem it's System's ruby, not Xcode's ruby so reinstall Xcode or symlink didn't help here.
Answer:
I have reinstalled macOS Mojave without losing any data and this fixed the problem.
I had a similar problem installing eventmachine 1.2.7, this worked for me (macOS 10.15.5):
(I use fish)
brew install ruby
Add the following ~/.config/fish/config.fish (without fish, just add these to path)
fish_add_path /usr/local/opt/ruby/bin
fish_add_path /usr/local/lib/ruby/gems/3.0.0/bin
set -gx CPPFLAGS "-I/usr/local/opt/ruby/include"
set -gx LDFLAGS "-L/usr/local/opt/ruby/lib"
set -gx PKG_CONFIG_PATH "/usr/local/opt/ruby/lib/pkgconfig"
sudo gem install eventmachine -v '1.2.7' --source 'https://rubygems.org/'
The set -gx commands I got after installing ruby thru brew.
I tried reinstalling the Xcode tools (12.3 as I can't upgrade to Big Sur just yet) and re-accepting agreement, but that didn't change anything
One note is that this was from installing eventmachine 1.2.7. The log error I got referenced this path as one of its flags:
-I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.1.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0 -I
Note that it was trying to look in .../MacOSX11.1.sdk/..., but I have 10.15.5. Even setting CPPFLAGS, LDFLAGS, PKG_CONFIG_PATH manually did not work as I was using either system ruby or whatever rbenv had, but I was too frustrated to dig deeper down that particular rabbit hole. So, I reinstalled w/ brew's ruby!
If you're getting this error as part of bundle install, see below -
I couldn't get any of the posted solutions to work. What worked for me was installing the specified bundler version from the logs. For example, my Console was warning me about mismatching bundler version and I ran gem install bundler:2.2.32 to fix it which then fixed the bundle install command for me. In my case, i was using rvm and ruby version 3.0.0.
I ran into this after uninstalling an older version of Xcode. Typically, I install into /Applications/Xcode-13.2.1.app for example. However, xcode-select -p still showed it was pointing to an older version.
I just ran sudo xcode-select -s /Applications/Xcode-13.2.1.app and everything started working correctly again.
I cannot find this mentioned above, and I'm not sure if that's a universal solution. Mentioning this as this may be still useful.
At least with Xcode 14/macOS 13/12, it's possible to use stock Ruby, without messing up with symlinks, provided that macOS command line tools package is installed on the host. The thing is that command line tools package bundles SDKs for most recent versions of macOS, and most notably, the one matching the host (from what I can see, that SDK has the "correct" name for the directory containing ruby/config.h). Then it's just a matter of overriding SDKROOT in the environment (this is the most crucial thing), to point all the low-level tools like clang to the custom root matching the "correct" version of SDK. (Without override, it would still use the default SDK bundled with the tools, that may or not match the version of macOS running on the host).
macos_major_vers=$(sw_vers -productVersion | sed 's/^\([^.]*\)\..*$/\1/') # e.g. 12
export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX"$macos_major_vers".sdk
# ... build commands for Ruby gems go here.
I'm using rbenv (on Catalina) and none of the solutions I found here (or elsewhere) worked for me. Ultimately what fixed my environment was pointing rbenv global to a specific version of ruby instead of system:
$ rbenv global 2.6.3
This was the state of my env while gem install was failing:
$ gem env home
=> /Users/ryanc/.gem
$ which gem
=> /Users/ryanc/.rbenv/shims/gem
$ which ruby
=> /Users/ryanc/.rbenv/shims/ruby
$ ruby -v
=> ruby 2.6.3p62 (2019-04-16 revision 67580) [universal.x86_64-darwin19]
$ rbenv local
=> rbenv: no local version configured for this directory
$ rbenv global
=> system
$ rbenv which ruby
=> /usr/bin/ruby
The result of rbenv which ruby was the key. I decided to run rbenv global 2.6.3 and suddenly I could install gems again. Here's the new state of things:
$ ruby -v
=> ruby 2.6.3p62 (2019-04-16 revision 67580) [x86_64-darwin19]
$ rbenv global
=> 2.6.3
$ rbenv which ruby
=> /Users/ryanc/.rbenv/versions/2.6.3/bin/ruby
In my case (Catalina 10.15.7) simply re-installying ruby with homebrew fixed it. No need to install rvm or rubyenv.
it's about your ruby version or bad installation.
you can install new ruby version with rvm
first install rvm with bellow command
curl -L https://get.rvm.io | bash -s stable
then close and reopen terminal or use command source [you mac bash file like .zshrc or .bashrrc] to load rvm command
next install new ruby version with bellow command
rvm install ruby-2.7.2
now you should use new version of ruby and install last version of cocoapods
do this steps:
check ruby version
check ruby version with ruby -v command
if your ruby version not 2.7.2 use 'rvm use 2.7.2' command to switch
on new ruby
then install cocoapods with 'sudo gem install cocoapods' command
for check new pods version use 'gem which cocoapods' command.
This is not cocoa pod issue, It is related to the older version of ruby.
Simply follow the below steps :
rvm install "ruby-3.0.0"
sudo gem install cocoapods
I'm encountered with the same problem a moment ago, and the following works for me.
brew install rbenv
# To get the latest stable version of ruby
rbenv install --list
# 3.1.1 is the latest version
rbenv install 3.1.1 && rbenv global 3.1.1
Do as installation tips of the previous step:
vim ~/.zhrc and append eval "$(rbenv init - zsh)"; finally, restart your term to make the line take effect.
I prefers not to make change under /Applications/Xcode.app since everything done will be lost after upgrading Xcode.
By the way, rbenv install --list tells all stable versions of ruby, and I choose the latest. You could try earlier ruby version that works for you.

Issues installing new ruby version using rbenv

I am trying to install ruby 2.5.0 on my system (macOS High Sierra) using rbenv but i'm facing a weird issue as the brew instructions are out of date:
djeustinezzz:~ JUSTINE$ rbenv install rbx-2.5.0
ERROR: Rubinius will not be able to compile using Apple's LLVM-based
build tools on OS X. You will need to install LLVM 3.5 first.
TO FIX THE PROBLEM: Install Homebrew's llvm package with this
command: brew tap homebrew/versions ; brew install llvm35
BUILD FAILED (OS X 10.13.6 using ruby-build 20160130)
The version 3.5 of LLVM was deleted. After googling here is what i've done:
brew tap homebrew/homebrew-core
brew install llvm#3.7
But nothing changed.
Homebrew, rbenv and ruby-build are installed and up-to-date.
Precision on why i'm doing this: i just installed Rails 5 on my computer and when i run the server, i have this error:
rbenv: version `ruby-2.5.0' is not installed (set by /Users/JUSTINE/desktop/code/test_five/.ruby-version)
When i run ruby -v, the output is ruby 2.5.0p0 (2017-12-25 revision 61468) [x86_64-darwin17] .
Any idea?
Clone both rbenv and ruby-build using the below links
git clone https://github.com/sstephenson/rbenv.git ~/.rbenv
git clone https://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-build
Now you'll have the ruby-build directory inside plugins.
cd ~/.rbenv
git pull
cd plugins/ruby-build
git pull
After this, you should 2.5.0 when you run rbenv install --list
So, what I'd do is try to see if you have the correct version of macOS command line tools installed. You could run:
xcode-select --install
Or you could start from scratch with:
rm -rf /Library/Developer/CommandLineTools
Then install the command line tools with the code above, or the better way which I found, was going directly to the Apple Developer site and downloading the command line tools package itself and installing that.
Install Command Line tools version 10.13 from here.
This issue also came up for me, but it came up when I started running Mojave. I believe it's the same thing here because I got the same errors.

gem install - fatal error: 'ruby/config.h' file not found in Mojave

gem install is failing in MacOs Mojave. Anything that can help me solve this? My ruby version is ruby 2.3.7p456.
➜ sudo gem install json -v '1.8.3'
current directory: /Library/Ruby/Gems/2.3.0/gems/json-1.8.3/ext/json/ext/generator
make "DESTDIR="
compiling generator.c
In file included from generator.c:1:
In file included from ./../fbuffer/fbuffer.h:5:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby.h:33:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/include/ruby-2.3.0/ruby/ruby.h:24:10: fatal error: 'ruby/config.h' file not found
#include "ruby/config.h"
^~~~~~~~~~~~~~~
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Update 15/03/2021
According to Apple, Ruby won't be included anymore in future versions of the system, so using a Ruby version manager will be the only way to go once this will actually happen.
Original answer
After hours and hours of trial and errors I wanted to go deeper into the reasons of this error and I finally found this that I think is the clean way to go around this issue:
Catalina (NdMe: I think this started earlier, on Mojave) no longer supports including macOS headers in command line
tools, they have to be explicitly used through Xcode SDK. You can do
so by running gem through the xcrun tool like:
xcrun gem install <your_gem>
Quoted from a Github issue comment.
Xcode 12 upgrade messed this up for me.
I installed ruby from brew and added this to my .zshrc
export PATH="/usr/local/opt/ruby/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
If you have the Xcode 10 beta running this might fix it
sudo xcode-select -s /Applications/Xcode-beta.app/Contents/Developer
In macOS Monterey (in the Beta at least), Ruby (ruby 2.6.3p62 (2019-04-16 revision 67580)) is still included but it doesn't seem to work well (fatal error: 'ruby/config.h' file not found), so I installed my own version of Ruby. You can install ruby manually, but I prefer to use rbenv, a Ruby version manager.
Install ruby using rbenv
Install rbenv: brew install rbenv ruby-build
ruby-build is a plugin for rbenv to actually install a ruby version, it provides ruby install command.
Setup rbenv: rbenv init, (and follow its recommended instructions, for example if you're using zsh, it says add eval "$(rbenv init -)" to ~/.zshrc)
Install ruby: rbenv install 3.0.1. Latest version listed here
Do what you came to do: sudo gem install cocoapods or bundle install
Or install ruby manually:
Run brew install ruby
Run echo 'export PATH="/opt/homebrew/opt/ruby/bin:$PATH"' >> ~/.zshrc so that this version is used
Restart terminal
asdf?
An alternative to rbenv is asdf, but I find asdf a bit complicated to use, since it supports more than just ruby, NodeJS. I would argue it does none of them very ergonomically.
Note: I have an M1 mac, and it's still working.
I got into this issue when trying to install fastlane with homebrew. None of the suggestions mentioned earlier helped me. Manually installing the macOS_SDK_headers_for_macOS_10.14.pkg fixed it.
sudo installer -pkg /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg -target /
I was having this same issue where I could not install native extensions due to a failure when including "ruby/config.h".
I believe the cause of this issue was because I was using the ruby version installed with Homebrew. After upgrading to a new version of Ruby with Homebrew, I saw the following helpful message from Homebrew:
ruby is keg-only, which means it was not symlinked into /usr/local,
because macOS already provides this software and installing another version in
parallel can cause all kinds of trouble.
If you need to have ruby first in your PATH run:
echo 'export PATH="/usr/local/opt/ruby/bin:$PATH"' >> ~/.bash_profile
For compilers to find ruby you may need to set:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
For pkg-config to find ruby you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/ruby/lib/pkgconfig"
Adding the following lines to my ~/.bash_profile fixed the issue for me:
export LDFLAGS="-L/usr/local/opt/ruby/lib"
export CPPFLAGS="-I/usr/local/opt/ruby/include"
xcrun gem install <your_gem> worked for me, but I had to do it multiple times — every time bundle install failed.
The best solution is probably to set the same vars as xcrun in your .zshrc file. xcrun env on my system adds:
SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk
CPATH=/usr/local/include
LIBRARY_PATH=/usr/local/lib
I had this problem after installing Big Sur. I found the file ruby/config.h was not present in the Xcode Packages in the Xcode versions I had installed prior to upgrading. I was able to correct it by uninstalling the Xcode versions and reinstalling them.

Trying to install ruby 2.1.2 with rbenv on OSX BUILD FAILED

So, as the title suggests, I'm trying to install ruby 2.1.2, altough I've tried to install other versions as well, and I'm getting the same errors. I'm running OSX 10.9.2.
I've tried:
Installing a fresh gcc compiler, via brew install gcc47
Installing updated OSX command line tools
Uninstalling rbenv and trying again
Restarting the machine
Here is the sum of what I'm getting:
rbenv install 2.1.2
Downloading ruby-2.1.2.tar.gz...
-> http://dqw8nmjcqpjn7.cloudfront.net/f22a6447811a81f3c808d1c2a5ce3b5f5f0955c68c9a749182feb4 25589e6635
Installing ruby-2.1.2...
BUILD FAILED
Inspect or clean up the working tree at /var/folders/6c/h_82199n12515_hd3rcp2x5w0000gn/T/ruby-build.20140528115901.38728
Results logged to /var/folders/6c/h_82199n12515_hd3rcp2x5w0000gn/T/ruby-build.20140528115901.38728.log
Last 10 log lines:
gcc version 4.2.1 (Apple Inc. build 5666) (dot 3)
compiling miniinit.c
compiling miniprelude.c
translating probes probes.d
compiling bignum.c
compiling class.c
dtrace: failed to compile script probes.d: Preprocessor not found
make: *** [probes.h] Error 1
make: *** Waiting for unfinished jobs....
compiling compar.c
Thoughts?
Gist of verbose output
I was able to build it using:
CONFIGURE_OPTS="--disable-dtrace" rbenv install 2.1.2
Basically that's what is suggested in the question's comment by wicz.
The solution by KurtPreston did not work for me. Also using OS X 10.9.
I was able to get this working in my own environment by:
Removing the gcc installed by Homebrew: brew remove gcc47
Re-installing the XCode Command Line Tools from the XCode Downloads page at https://developer.apple.com/downloads
I was trying to install 2.0 and ran into the same error. However now the CONFIGURE_OPTIONS override doesn't seem to work anymore with rvm at least, so I needed to build it with rvm install --reconfigure -C --disable-dtrace ruby-2.0.0-p594. This was the first Google result off the error message ("dtrace: failed to compile script probes.d: Preprocessor not found") so I figured I should add this as a current solution for rvm users. Running on OSX Mavericks.
I cannot reproduce this on my machine, sorry. For reference, here's my dtrace version if that should have anything to do with the error:
dtrace -V
dtrace: Sun D 1.7
You can try to check for XCode and command line tools updates. GCC 4 should not be necessary, you can use the compiler that ships with XCode:
brew uninstall gcc4
Finally, update everything and try again:
brew update
brew upgrade rbenv ruby-build
rbenv uninstall 2.1.2
rbenv install 2.1.2
If that does not work yet: some people have reported that a simple reboot of the machine solved similar errors with dprobe/dtrace.

"No available formula for gcc46" while installing Ruby 1.9.3 on OS X with RVM:

I have Homebrew installed, I'm trying to install RVM with:
rvm install 1.9.3-head
and I get this error:
Installing required packages:gcc46
Error running 'requirements_osx_brew_libs_install gcc46',
please read /Users/mike/.rvm/log/1384918134_ruby-1.9.3-head/package_install_gcc46.log
Requirements installation failed with status: 1
brew doctor says I'm ready to brew.
In the log I see:
Error: Download failed: ftp://gcc.gnu.org/pub/gcc/infrastructure/gmp-4.3.2.tar.bz2
Ruby 1.9.3+ supports compiling with Clang (which you do have) instead of GCC, so make RVM compile with Clang instead:
rvm install 1.9.3 --with-gcc=clang
When I upgraded to mavericks from mountain lion it somehow started ignoring my dev-tools (like gcc, etc.) try
xcode-select --install
also see here
When upgraded to OSX 10.12 and installing ruby 2.3.1 these steps fixed the issue.
brew install homebrew/versions/gcc46
if there are any linking issues related to any lib please follow the instructions for example
brew link --overwrite libtool
brew link --overwrite libgpg-error
Once the installation of gcc46 is successful you could
rvm install 2.3.1

Resources