JSON gem failing to compile on Mac OS X 10.8.2 - ruby-on-rails

OS: Mac OS X 10.8.2
XCode: Latest with command line tools installed (version 4.6)
Rails: version 3.2.3
I was trying to generate the routes for a project I am working on (been doing that on regular basis), when I got an error message, with a recommendation that I do bundle install and bundle exec. I did, and this time around, the process broke off while compiling the JSON Gem (version 1.7.7).
Doing some research on StackOverflow, the recommendation was to update the XCode's command line tools, and I did, but that did not solve the problem.
I tried installing the JSON version 1.7.7 separately, and it failed, telling me to look for the error log in:
~/.rvm/gems/ruby-1.9.3-p125/gems/json-1.7.7/ext/json/ext/generator/gem_make.out
Which reads:
/Users/mine/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb
creating Makefile
make
compiling generator.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [generator.o] Error 1
I looked for /usr/bin/gcc-4.2, and indeed, it's not there. But, when I do:
ls -l /usr/bin/gcc
Here's what I get:
lrwxr-xr-x 1 root wheel 12 Feb 14 15:49 /usr/bin/gcc -> llvm-gcc-4.2
How do I fix this problem?

I think the problem is that when you install the Xcode command line tools, gcc is sym-linked to llvm, and llvm can't always compile Ruby and gems correctly.
If you install autoconf, automake, and gcc directly (or through something like Homebrew), you should be able to fix the compiler errors.

The problem is that the gcc you used to compile your installed version of ruby got removed as part of the xcode upgrades. Using RVM rebuild your ruby (you might want to upgrade to the latest version as well). Once you do that, you should have no problem building gems with native extensions.

Related

zendesk app tools ZAT Installation errorFailed to build gem native extension

I am trying to install "ZAT" the Zendesk app tools following the documentation, but receiving this error: \
Building native extensions. This could take a while...
ERROR: Error installing zendesk_apps_tools:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/eventmachine-1.2.7/ext
/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 ./siteconf20220105-47488-6pwgmm.rb extconf.rb
checking for -lcrypto... *** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of necessary
libraries and/or headers. Check the mkmf.log file for more details. You may
need configuration options.
ruby version => ruby 2.6.3p62 (2019-04-16 revision 67580)
xcode-select => xcode-select version 2384.
macOs : BIg Sur version 11.6.2
any idea what is the issue?
Installation via rvm resolves this issue.
I had the same problem on my Mac Big Sur 11.6 with M1 chip. None of the suggested solutions helps me (I tried to reinstall Xcode, updating/reinstalling command line tools, deal with the installation of thin separately, etc.). One thing that really helps me it's changing the ruby version to 2.6.9 with rbenv (https://gorails.com/setup/osx/11-big-sur - check Installing Ruby . Follow this instruction, but choose another ruby version). After change ruby version, make sure the correct version of ruby is currently selected with ruby -v and then try execute gem install zendesk_apps_tools again. I tried several versions of ruby before it worked for me, but in the end everything was fine on 2.6.9 version

Unable to install cocoapods

Hi I am learning React Native, I was able to build Android version successfully but here in the iOS version I am facing so many issues. I'm developing a Podcast application for both Android and iOS but when I'm trying to install cocoapods in my Application I am getting the following error,
Building native extensions. This could take a while...
ERROR: Error installing cocoapods:
ERROR: Failed to build gem native extension.
current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.3.1/ext/json/ext/generator
/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 ./siteconf20201214-42573-vm30sv.rb extconf.rb
creating Makefile
current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.3.1/ext/json/ext/generator
make "DESTDIR=" clean
current directory: /Library/Ruby/Gems/2.6.0/gems/json-2.3.1/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/MacOSX11.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/MacOSX11.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
#include "ruby/config.h"
^~~~~~~~~~~~~~~
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/include/ruby-2.6.0/ruby/ruby.h:24:10: note: did not find header 'config.h' in framework 'ruby' (loaded from '/Library/Developer/CommandLineTools/SDKs/MacOSX10.15.sdk/System/Library/Frameworks')
1 error generated.
make: *** [generator.o] Error 1
make failed, exit code 2
Gem files will remain installed in /Library/Ruby/Gems/2.6.0/gems/json-2.3.1 for inspection.
Results logged to /Library/Ruby/Gems/2.6.0/extensions/universal-darwin-19/2.6.0/json-2.3.1/gem_make.out
Hardware: Mac Mini
Can anyone help me in solving this issue. I'd like to install it with sudo gem install cocoapods rather than brew
You should not use Apple's Ruby installation. That installation exists solely for internal use by Apple itself.
Since you have specified in your question that you want to use Apple's Ruby installation, I am afraid there is nothing that can be done to fix the problem.
If, on the other hand, you are willing to use a different Ruby installation (installed by hand, with Homebrew, with ruby-install, with ruby-build, with RVM, asdf, or any other way), then the problem should not present itself in the first place.
For more information, see for example
macOS 10.15 Catalina Release Notes
PSA: Do not use system Ruby
Why you shouldn't use the System Ruby
If possible, do not use the ruby system version on Mac OSX
you need to install Xcode Command Line Tools。
command:
xcode-select --install

Issues with installing Ruby 2.0.0 on macOS Catalina

I'm running to issue installing Ruby 2.0.0 on a new macbook with macOS Catalina (version 10.15.7). At first I installed Ruby with rvm which did not work. I figured out that it was because Catalina's default terminal is ZSH instead of Bash (https://gorails.com/setup/osx/10.15-catalina). I was able to install Ruby 2.6.3 with the instructions but the issue is that the project I'm currently working on was written in Ruby 2.0.0. I tried installing this version with rbenv install 2.0.0-p0 but I ran to the following errors:
ruby-build: using libyaml from homebrew
Downloading openssl-1.0.2u.tar.gz...
-> https://dqw8nmjcqpjn7.cloudfront.net/ecd0c6ffb493dd06707d38b14bb4d8c2288bb7033735606569d8f90f89669d16
Installing openssl-1.0.2u...
Installed openssl-1.0.2u to /Users/vydoan/.rbenv/versions/2.0.0-p0
Downloading ruby-2.0.0-p0.tar.bz2...
-> https://cache.ruby-lang.org/pub/ruby/2.0/ruby-2.0.0-p0.tar.bz2
Installing ruby-2.0.0-p0...
WARNING: ruby-2.0.0-p0 is past its end of life and is now unsupported.
It no longer receives bug fixes or critical security updates.
ruby-build: using readline from homebrew
BUILD FAILED (Mac OS X 10.15.7 using ruby-build 20201005)
Inspect or clean up the working tree at /var/folders/m4/3k5xfdwx7x7gqkzzlyrlc_gc0000gn/T/ruby-build.20201006082731.4615.0q3Cat
Results logged to /var/folders/m4/3k5xfdwx7x7gqkzzlyrlc_gc0000gn/T/ruby-build.20201006082731.4615.log
Last 10 log lines:
compiling cont.c
compiling ./enc/ascii.c
thread.c:928:27: error: implicit conversion loses integer precision: 'long' to '__darwin_suseconds_t' (aka 'int') [-Werror,-Wshorten-64-to-32]
tp->tv_usec = ts.tv_nsec / 1000;
~ ~~~~~~~~~~~^~~~~~
compiling ./enc/us_ascii.c
1 error generated.
make: *** [thread.o] Error 1
make: *** Waiting for unfinished jobs....
1 warning generated.
I've tried doing the follow:
1.
brew tap homebrew/dupes
which gives me this error log
Error: homebrew/dupes was deprecated. This tap is now empty and all its contents were either deleted or migrated.
brew install gcc
rbenv install 2.0.0-p0
which gives me the same errors as above.
I've asked my team and found that another person also have issue with installing ruby on their new mac machines. The older mac didn't not have this problem. Was anyone able to successfully install Ruby 2.0.0 on the newer mac?
Hello I had numerous issues trying to install ruby 2.2.7 the project I work on has quiet a deprecated version of ruby necessary stated above now I ran into numerous problems they use rvm I could not install 2.2.7 using rvm I have however succeeded using rbenv the thing that ruins your experience is mainly the command line tools provided by Apple since in newer version it does not support compiling older ruby versions.
I also run the same version of MacOS :
Your best bet (since I've tried several days in a row to get my setup working installing ruby being the biggest blocker).Go to apple's developer site and download an older version of command line tools here and browse for 11.4.1(Before running the next steps make sure to purge previous attempts and ruby version managers and symlinks so it won't interfere with you next install and make your life hard).
Before downloading and installing it check your gcc -v remember that and install the command line tools you've downloaded and check it again to see if things went according to plan you should get something like:
Apple clang version 11.0.3 (clang-1103.0.32.59)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
I haven't tried other versions but this one works afterwards go to rbenv official website install the tools add the shell scripts to your local .zshrc file (if you don't have one just create it).Besides adding what the guide says it ommits an important step you also need to add this to your .zshrc:
export PATH="$HOME/.rbenv/bin:$PATH"
Then you should just close and open the terminal and install the ruby version you need :
# list latest stable versions:
$ rbenv install -l
# list all local versions:
$ rbenv install -L
# install a Ruby version:
$ rbenv install 2.0.0-p247
Consult the docs as of how to use them globally or locally also if use is not working end all terminal windows and the process restart and it should work just okay.
!Important mentions is to not change the command line tools when compiling different ruby related version may break the setup (ignore brew messages to update command line tools when running brew doctor)!

Inspect or clean up the working tree error when installing Ruby 2.1.3 on Mac OS X 10.9.5

I'm trying to install Ruby 2.1.3 on Mac OS X 10.9.5 using the rbenv install 2.1.3 command. However I get the error message below. I tried every suggestion on stack overflow and elsewhere. Nothing seems to be working. I currently have the original ruby version that came with 10.9.5, Ruby 2.1.3p242. Brew doctor says everything is fine and rbenv is up to date. Thanks so much! Trying to learn Ruby and Ruby on Rails but I can't get passed this stage.
Inspect or clean up the working tree at /var/folders/zg/s1jqg94n0hjggdnmb442n2lc0000gn/T/ruby-build.20141025184549.88303
Results logged to /var/folders/zg/s1jqg94n0hjggdnmb442n2lc0000gn/T/ruby-build.20141025184549.88303.log
Last 10 log lines:
linking shared-object openssl.bundle
installing default openssl libraries
compiling raddrinfo.c
compiling ifaddr.c
installing default socket libraries
compiling init.c
compiling constants.c
linking shared-object socket.bundle
linking shared-object ripper.bundle
make: [build-ext] Error 2
I have a m1 mac and I also got this error installing ruby,
this command worked for me:
export optflags="-Wno-error=implicit-function-declaration";
run this and then try rbenv install again.
Did you try this:
CC=/usr/bin/gcc rbenv install 2.1.3
From this SO answer: Unable to build Ruby 2.1.3 on OSX 10.10 GM 3.0 with rbenv
I had to remove the existing openssl that came with macOS and instead install from brew with brew install openssl.
NOTE: I also had to disable SIP with csrutil disable and then remount root with writable permissions, with sudo mount -uw /.

"Failed to build gem native extension" when installing Rails

I'm new to Terminal so please bear with me. Completed installing the following successfully (in this particular order):
xCode 4.5
RVM 1.16
GCC 4.2.1
Ruby 1.9.3
When trying to install Rails ("gem install rails") the installation starts but is then interrupted with an error: "Failed to build gem native extension". No idea what this refers to. Ideas? Something else I need to install beforehand?
On my first attempt to install Rails I accidentally ran it with sudo. Will this affect anything?
Edit: And the output -
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/Users/staffanestberg/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb
creating Makefile
make
compiling generator.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [generator.o] Error 1
Gem files will remain installed in /Users/staffanestberg/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5 for inspection.
Results logged to /Users/staffanestberg/.rvm/gems/ruby-1.9.3-p194/gems/json-1.7.5/ext/json/ext/generator/gem_make.out
Edit: Solved using iouri's suggestion. Add export CC=gcc in .bash-profile then create a symlink for the correct compiler,
sudo ln -sf /usr/bin/llvm-gcc-4.2 /usr/bin/gcc-4.2
Make sure you have command line tools for Xcode installed first, Xcode > Preferences > Downloads > Components. Then add this line to your .bash_profile file in your home folder ~/.bash_profile:
export CC=gcc
Double check that you have gcc (probably a symlink) in your /usr/bin (most likely), and that it is pointing to a valid gcc compiler, ex: gcc -> llvm-gcc-4.2
You might have to restart your terminal for this change to take affect.
Ruby is not fully ready for LLVM compilation, this includes clang, there is at least one known isue with Fibers, but depending on LLVM version other problems might appear.
The right way to fix it is to get gcc-4.2 there are many ways for it and the best ones are described in requirements:
rvm get stable
rvm reload
rvm requirements run
rvm reinstall 1.9.3

Resources