Install Ruby development tools for gem installation on OSX Catalina - ruby

I know there are many instances of this question. I've done everything in those answers and have gotten nowhere after 4 hours.
I am trying to install a gem on Catalina 10.15.7 and getting the ever-popular
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/mkmf.rb:467:in `try_do': The compiler failed to generate an executable file. (RuntimeError)
You have to install development tools first.
with this additional context
ERROR: Error installing ffi:
ERROR: Failed to build gem native extension.
current directory: /Users/bmanica/.chefdk/gem/ruby/2.4.0/gems/ffi-1.13.1/ext/ffi_c
/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby -I /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0 -r ./siteconf20200925-10024-qilctf.rb extconf.rb --with-cflags\=-save-temps\=obj\ -o\ tmp/a.o
when invoking the installation via
gem install ffi -- --with-cflags="-save-temps=obj -o tmp/a.o"
to get around Catalina's draconian permissions rules.
I've freshly downloaded XCode and the command line tools:
> xcode-select --install
xcode-select: error: command line tools are already installed, use "Software Update" to install updates
> xcode-select -p
/Applications/Xcode.app/Contents/Developer
> ls /Applications/Xcode.app/Contents/Developer
Applications Library Makefiles Platforms Toolchains Tools usr
I've accepted the license at least four times via
sudo xcodebuild -license accept
I've tried
sudo xcode-select -switch /
as Gem installation error: You have to install development tools first suggests. I am not on Windows so the rubyinstaller link does not help me.
Can't Find ffi.h When Installing ffi ruby gem references the exact gem I am trying to install, but as indicated xcode-select --install is not the answer.
None of the answers in Developer tools issues when installing Ruby gems are helpful either; I have already brew install openssl and brew install libffi and have exported the variables it told me to:
> set | grep FLAGS
CPPFLAGS=-I/usr/local/opt/libffi/include
LDFLAGS=-L/usr/local/opt/libffi/lib
> set | grep PATH
PKG_CONFIG_PATH=/usr/local/opt/libffi/lib/pkgconfig
I've also tried the suggestions in How to update Xcode from command line - xcode-select -r does nothing, xcode-select -s /Library/Developer/CommandLineTools does nothing, and $ sudo rm -rf /Library/Developer/CommandLineTools prevents xcode-select --install from working, and additionally I moved it anyway and redownloaded the command line dmg package from Apple's developer site. Still same problem.
What do I try next to get this gem to install?

Finally got it after hours.
I followed this instruction, changed it a bit
Make sure brew is installed. If not
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
Set shell to zsh
curl -L http://install.ohmyz.sh | sh
or, set PATH
eval "$(rbenv init -)"
Install Ruby Version Manager
brew update
brew install rbenv ruby-build
Install Ruby
rbenv install 2.6 # I used my systems default version number because I was not sure if it messes with my OS X system version.
rbenv global 2.6
rbenv rehash
Add it to your zsh
echo 'eval "$(rbenv init -)"' >> ~/.zshrc
source ~/.zshrc
That did it for me. All the other stuff like installing Xcode, accept the Xcode License, Xcode command line tools did not do it.

Judging by the path names in your error message, you are trying to modify Apple's System Ruby. This is not allowed.
Apple's System Ruby is exclusively for internal use by macOS and/or support for legacy applications. You must not use it, and you most certainly must not modify it. Modifying it would negate the whole "support for legacy applications" thing.
Apple itself has the following to say in the release notes for macOS 10.15 Catalina:
Scripting Language Runtimes
Deprecations
Scripting language runtimes such as Python, Ruby, and Perl are included in macOS for compatibility with legacy software. Future versions of macOS won’t include scripting language runtimes by default, and might require you to install additional packages. If your software depends on scripting languages, it’s recommended that you bundle the runtime within the app. (49764202)
There are many, many options for installing Ruby on macOS, including but not limited to compiling it yourself, downloading pre-compiled binaries, Homebrew, ruby-install, ruby-build, RVM. There are many options for managing Ruby installations on macOS, including but not limited to chruby, asdf, rbenv, and RVM.
Most of these have the added advantage that they support newer versions than the one Apple ships, and even more interesting, they support different implementations than just YARV. My personal favorite is TruffleRuby, which, when run on the GraalVM, was up to 1000 times faster for me, depending on the benchmark.
Please, do not use System Ruby.

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.

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.

Port install ruby stuck in Building gettext

I've just installed Mavericks OSX, loosing my previous ruby versions which I used to work in several Redmine based projects. Not to say I'm currently not happy with apple.
Anyway, I'm following #RyanWilcox steps described here to install a ruby version prior 2.0.-
Trouble downgrading Ruby on OS X Mavericks
which looks promising, but sadly I'm stuck installing ruby through macports. When I run
sudo port install ruby
everything seems ok, but then it get stuck in
---> Building gettext
step. I'm not a macports user and have no idea what's happening here nor even where should I start looking. Anyone could point me in the right direction to fix this issue?
Did you install the xcode command line tools? Try xcode-select --install first.
I also suggest you to use Homebrew instead of MacPorts. Here are the steps to install rbenv via Homebrew: https://github.com/sstephenson/rbenv#homebrew-on-mac-os-x
brew install rbenv ruby-build
rbenv init
echo 'eval "$(rbenv init -)"' >> ~/.bash_profile && source ~/.bash_profile
rbenv install 1.8.7-p374 # or any version listed in `rbenv install -l`
rbenv local 1.8.7-p374
Now 1.8.7 is the default Ruby version for your user.
In my case, I had to switch to Xcode5 command-line tools, using xcode-select -s <Xcode5 Developer folder path>, because I had two versions of Xcode (4.6 and 5) on my machine and at the time of building ports I was using Xcode4 command-line tools.
Also, I enabled multi-core build in /opt/local/etc/macports/macports.conf by setting buildmakejobs field to:
buildmakejobs 2
This made the build process much faster, so that there are smaller chances that it would give you false impressions that it got stuck elsewhere.

How can I install Ruby 1.9.3 in Mac OS X Mountain Lion without Xcode?

I would like to know about alternative ways to build a development machine for Ruby 1.9.3 on OS X 10.8 Mountain Lion, that does not require Xcode.
Mountain Lion is now Golden Master as I'm writing this question, so it could be considered as final version. That cannot be said about Xcode, that is a preview release yet.
RVM recommends to install osx-gcc-installer over Xcode, but I would like not to mess my system.
What is the cleanest way to install Ruby 1.9.3 on Mountain Lion without Xcode?
osx-gcc-installer turns out to be a very good option to replace Xcode in order to install Ruby 1.9.3
These are the steps I have followed:
Download & install the latest version of osx-gcc-installer here (GCC-10.7-v2 is fine): https://github.com/kennethreitz/osx-gcc-installer
Install RVM as usual and select 1.9.3-head as the default ruby installation: https://rvm.io/rvm/install/
Install Homebrew: https://github.com/mxcl/homebrew/wiki/installation
Install libksba to resolve some dependencies with Ruby 1.9.3: brew install libksba
That's it! You should now have Ruby 1.9.3 installed on Mountain Lion working perfectly.
If you need some other packages, install them now through Homebrew, such as Imagemagick for example: brew install imagemagick
It's possible that you need XQuartz for Homebrew to work properly, as Apple is not shipping X11 since Mountain Lion. You can download it here: http://xquartz.macosforge.org/trac/wiki
EDIT:
Now (since 29th July) Command line tools for Xcode 4.4 are available.
So, the new steps are these:
Download & install Command line tools for Xcode 4.4 (you don't need to download Xcode): https://developer.apple.com/downloads/index.action
Install Homebrew: https://github.com/mxcl/homebrew/wiki/installation
Install automake: brew install automake
Install RVM as usual and select 1.9.3-head as the default ruby installation: https://rvm.io/rvm/install/
Optional step: You may need XQuartz for some components, for example for Imagemagick, so download & install XQuartz: http://xquartz.macosforge.org/trac/wiki
I also had to add this:
export CC=/usr/bin/gcc-4.2
in order to make the Apple command line tools work with the rvm. Without this I had repeated llvm issues:
The provided CC(gcc) is LLVM based, it is not yet fully supported by ruby and gems, please read rvm requirements.
I had to add
export CPPFLAGS=-I/opt/X11/include
as well as
export CC=/usr/local/bin/gcc-4.2
I was still getting compilation errors due to readline (things like readline.c: In function ‘readline_s_vi_editing_mode_p’: in the make.log file), and the RVM readline page didn't seem to help, so I ran
brew install readline
followed by
rvm install 1.9.3 -C --with-readline-dir=/usr/local/Cellar/readline/6.2.4

Can't install Ruby Enterprise Edition with RVM on OSX Lion

Here is what I have done so far.
Clean install of OS X Lion
Downloaded and installed latest version of Xcode from the App Store.
Installed Git
Installed Homebrew
Installed RVM
I am now trying to install Ruby Enterprise Edition for a project with rvm install ree and receive the following error:
$ rvm install ree
ree-1.8.7-2011.03 - #installing
ERROR: Error running './installer -a /Users/FaraazKhan/.rvm/rubies/ree-1.8.7-2011.03
--no-tcmalloc --dont-install-useful-gems ', please read
/Users/FaraazKhan/.rvm/log/ree-1.8.7-2011.03/install.log
ERROR: There has been an error while trying to run the ree installer. Halting
the installation.
I have already tried CC=/usr/bin/gcc-4.2 rvm install ree and with the same result.
I was able to duplicate your error, just now. This solved it for me:
$ rvm remove ree
$ export CC=/usr/bin/gcc-4.2
$ rvm install --force ree
Using MacPorts you can install Ruby Enterprise Edition, as well as Ruby 1.9.2 for the local user in OS X Lion while having Xcode 4.2 installed by using "Apple's version of gcc 4.2."
Prerequisites:
OS X Lion (tested in 10.7.2)
Xcode 4.2
rvm 1.9.1
MacPorts 2.0.3
Execute the following commands:
$ sudo port install apple-gcc42
$ export CC=/opt/local/bin/gcc-apple-42
then
$ rvm install ree
$ rvm use ree
or
$ rvm install 1.9.2
$ rvm use 1.9.2
optionally
$ rvm use ree --default
or
$ rvm use 1.9.2 --default
I hope this helps.
-Joe
No need to install MacPorts or downgrade to 4.1 to get GCC, I used the installer package at https://github.com/kennethreitz/osx-gcc-installer with xCode 4.2 already installed, and had no problem installing 1.9.2-head and 1.9.2-p290.
I did something similar to what jbg advised. Only I didn't use MacPorts. I just used the latest GCC package for Lion here.
This was after spending about a day and a half trying all of the other suggestions, downgrading to Xcode 4.1, etc. to no avail.
By the way, the direct link to Xcode 4.1 at Apple's site gave me an invalid checksum error, all three times I downloaded it. I saw a Twitter post from someone else who had the same problem.
At the risk of redundancy, I'll post my answer as well, since I tried everything on this page (and many others) and ended up with a hybrid of some of them which seemed the most likely to work. Note that some of these steps may not have been explicitly necessary but they were sufficient (i.e., I didn't go back and remove potentially unnecessary steps to get the simplest path to success).
Environment: Mac OS Lion 10.7.3, Homebrew components, rvm 1.10.2, ree 1.8.7-2012.01, Xcode 4.2.1 with legacy gcc-4.2 available.
Steps:
Ensure that a stable Ruby is current. Used 1.9.2 (rvm use 1.9.2) as 1.9.3 was a potential problem.
rm -fr $rvm_path/usr
rvm pkg install ree_dependencies
rvm remove ree
export CC=/usr/bin/gcc-4.2
rvm install ree \
--with-openssl-dir=$rvm_path/usr \
--with-readline-dir=$rvm_path/usr \
--with-iconv-dir=$rvm_path/usr \
--with-zlib-dir=$rvm_path/usr
I had previously tried the brew-specific solutions but those didn't work for me. Hope this helps someone!
Please do NOT use sudo with RVM, nor do you need to use rvmsudo EXCEPT for when upgrading RVM itself. Please see and read https://rvm.io/support/faq/ (Do I need to use sudo with gems? entry) and https://rvm.io/support/troubleshooting/ (Multi-User Installs - Using the sudo command entry)
Please remove your current installation and start over as using sudo will definitely mess up the permission structure for RVM. Please see the very bottom of https://rvm.io/support/troubleshooting/ (How do I completely clean out all traces of RVM from my system, including for system wide installs? entry)
Then begin again strictly following the Multi-User installation segment of https://rvm.io/rvm/install/
Thank you.
If you are on Lion 10.7.2, and have installed XCode 4.2, you need to downgrade XCode to 4.1
Here's how I did it (it was more complicated than you might think):
Download XCode 4.1 from Apple Dev Center (you'll need to login with your dev centre creds)
uninstall XCode 4.2
$ sudo /Developer/Library/uninstall-devtools --mode=all
remove the XCode installer from your /Applications directory
run the XCode 4.1 package you downloaded, this will install a new XCode installer into /Applications
run the XCode installer in /Applications
When it stops, asking you to quit iTunes, you need to quit iTunes, and also use Activity Monitor to force quit the iTunes Helper
Wait for XCode 4.1 to install
Use the steps outlined above to install ree
Cheers,
Ian
This is how i did to install it. May be previous answers are already solve your problem. My step may be help people who experience same as me.
Frist, Install MacPort latest version
>rvm uninstall ree
>sudo port install apple-gcc42
>export CC=/opt/local/bin/gcc-apple-4.2
>rvm pkg install zlib openssl readline
>rvm install --force ree
Result is:
IronB:~ ...$ rvm install --force ree
Installing Ruby Enterprise Edition from source to: /Users/.../.rvm/rubies/ree-1.8.7-2011.03
ree-1.8.7-2011.03 - #fetching (ruby-enterprise-1.8.7-2011.03)
ree-1.8.7-2011.03 - #extracting ruby-enterprise-1.8.7-2011.03 to /Users/.../.rvm/src/ree-1.8.7-2011.03
Applying patch 'tcmalloc' (located at /Users/.../.rvm/patches/ree/1.8.7/tcmalloc.patch)
Applying patch 'stdout-rouge-fix' (located at /Users/.../.rvm/patches/ree/1.8.7/stdout-rouge-fix.patch)
Applying patch 'no_sslv2' (located at /Users/.../.rvm/patches/ree/1.8.7/no_sslv2.diff)
ree-1.8.7-2011.03 - #installing
Removing old Rubygems files...
Installing rubygems-1.8.10 for ree-1.8.7-2011.03 ...
Installation of rubygems completed successfully.
ree-1.8.7-2011.03 - adjusting #shebangs for (gem irb erb ri rdoc testrb rake).
ree-1.8.7-2011.03 - #importing default gemsets (/Users/.../.rvm/gemsets/)
I'm also put this to my ~/.rvmrc for next time
# Make this work with OS X Lion... for now...
if [[ `uname -v` =~ "Darwin Kernel Version 11" ]] ; then
export CC=/opt/local/bin/gcc-apple-4.2
fi

Resources