ffi fails to build via bundler on MacOS 10.8.5 - ruby-on-rails

PROBLEM:
bundler fails to build ffi and so my rails apps are broken in my development environment.
None of the posts that I've read have solutions that work for me. I get the same error in a number of rails apps.
What other troubleshooting steps can I take?
How do I fix this issue?
BACKGROUND:
After an upgrade to Mountain Lion from Snow Leopard, Xcode upgrade, Clean Homebrew install, I did a clean install of rvm. Now I am trying to recreate the gemsets used by my rails apps. I did:
gem install rails -v3.2.16 (to get the base rails gems installed)
rvm gemset import ruby-1.9.3-p545#CLIENTNAME.gems (to import gems)
bundle install (to install dependencies and resync gemfile.lock)
ISSUE:
bundle install fails with this error message:
An error occurred while installing ffi (1.9.3), and Bundler cannot continue.
Make sure that gem install ffi -v '1.9.3' succeeds before bundling.
The complete gem_make.out is here: https://gist.github.com/mattmartini/b2f8ad3b4e6c57325d38
The mkmf.log is here: https://gist.github.com/mattmartini/d3256cb52e5eafb2346b
The config.log is here: https://gist.github.com/mattmartini/69407e118e92cadda2b0
I would like to stay on ruby 1.9.3 as the Production servers are using this.
OBSERVATIONS:
One of the errors thrown is that 'C compiler cannot create executables' - this is not true. I can compile C programs and bundler built nokogiri without a problem.
I did just notice that libffi, which was installed (along with gcc46) by rvm, is keg only. Would bundler be able to use the lib in creating the gem?
ENVIRONMENT:
Mac OS X 10.8.5 (Mountain Lion)
Xcode 5.0.2 (command line tools installed)
Homebrew 0.9.5 (recent fresh install)
rvm 1.25.25 (stable)
ruby 1.9.3-p545
libffi 3.0.13 (brew via rvm)
gcc46 (brew via rvm)
REVIEWED:
I reviewed a number of posts of similar issues, but none had a solution that worked for me, including:
https://github.com/ffi/ffi/issues/286
Note I had a bunch of stack overflow links here but I couldn't submit this question with them.

My hunch about libffi being keg only was correct. After linking libffi, bundle used this lib instead of trying to compile it. This resolves the issue of getting the gem installed, but doesn't resolve why it fails to compile.
Since the lib is keg only you have to force it to link:
brew link libffi --force

Related

Rails bundler is not finding correct Ruby version in OSX Catalina

I've recently upgraded to OSX Catalina and when I try to do
bundle install
on the Rails project, I get an error:
Cannot bundle the project, current system is on Ruby 2.6.3 and gemfile
specified Ruby 2.4.2.
What's bizarre is that the Catalina system is a fresh install and I used rbenv to do a single install of Ruby version 2.4.2. In fact, if I run
ruby -v
It comes back with ruby version 2.4.2 as the only ruby version installed (and the default).
I'm totally stumped, has anyone else seen this behaviour or have any idea of how I can resolve this?
So I finally solved this, although I'm a little mystified as to the cause/solution.
Basically, I uninstalled the bundler gem and installed the one the project had in it's Gemfile (1.16.2)
For whatever reason, I'm not sure how bundler got installed on the fresh machine, I suspect maybe through RVM or Rbenv, but with that version of bundler it was somehow assuming that I had Ruby 2.6.3 installed, even though it didn't appear as a version on my machine.

What's the best way to run a RoR project on my localhost

I have a friend's website code, which is in Ruby on Rails.
I have tried to install RoR on my Mac using instructions at gorails.com
OS : Mac Mojave
ruby -v : ruby 2.2.3p173 (2015-08-18 revision 51636) [x86_64-darwin18]
rails -v :
/System/Library/Frameworks/Ruby.framework/Versions/2.3/usr/lib/ruby/2.3.0/rubygems.rb:241:in `bin_path': can't find gem railties (>= 0.a) (Gem::GemNotFoundException)
from /usr/local/bin/rails:22:in `<main>'
What I tried : I installed ruby, and then rails, using gorails tutorial, and kept getting errors stating version number mismatch.
Keep in mind that creating a new app, worked, but trying to run this existing code is a problem.
So then I uninstalled everything and updated the version using rvm, and since then I am getting this error.
When I cd into the webapp folder and run bundle install, I get errors, such as:
zsh: /Users/abc/.rvm/gems/ruby-2.2.3#hs/bin/bundle: bad interpreter: /Users/abc/.rbenv/versions/2.5.3/bin/ruby: no such file or directory
Could not load OpenSSL.
You must recompile Ruby with OpenSSL support or change the sources in your
Gemfile from 'https' to 'http'. Instructions for compiling with OpenSSL using
RVM are available at rvm.io/packages/openssl.
This project uses a PostgreSQL database, which I have setup already.
If required, I can share the gemfile of this project too.
What is the best way to get this project working?
Am I missing something crucial?
You can't run RVM and RBENV on the same machine. Pick one and remove the other. You're probably best to uninstall both and then pick one, start over.
Uninstall RBENV instructions here or in your case probably brew uninstall rbenv
Uninstall RVM see How can I remove RVM (Ruby Version Manager) from my system?
Close all terminals and then start a new one.
Install RVM see https://rvm.io/rvm/install
Then go to your project, make sure you have the correct ruby version needed by your project. If not, you will need to install with rvm install 2.5.1 for example.
Then run
rvm use 2.5.1 #or some other version
Then you should be able to run bundle install
The rest of the instructions in your link should be ok.

Uninstall Ruby, rbenv and homebrew and reinstall Ruby on Rails with RVM on MAC

I'm very new to RoR specially on Mac. I have installed it many times on Ubuntu with RVM and I'm very comfortable with that. Here is what happened on Mac:
I went through instructions as explained here http://goo.gl/zsHcCC then when I got to the point to install Rails with " gem install rails " I got this error:
Error installing rails:
ERROR: Failed to build gem native extension.
Now I want to roll-back everything and uninstall rbenv and it's ruby versions and reinstall the Ruby On Rails environment using RVM.
I tried to find how to uninstall Homebrew, RBENV and Ruby, but no success.
Thank you.
Sia
Homebrew or Rbenv are very good tools to have as a dev, I would think twice before removing either.
In this case I doubt they are at fault.
Can you confirm you have installed the GCC command line utils for OSX by running $ xcode-select --install in your terminal.
Here is a useful post explaining that process but I find that command generally works fine for me.
If this succeeds what does your $ gem install rails output next?
If you are very new you and you don't need specially the last version of Ruby. You can use Rails Installer http://railsinstaller.org/fr-FR.
To uninstall brew https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/FAQ.md

Issue installing capybara-webkit gem, recursive error?

Installing capybara-webkit (0.11.0) with native extensions Unfortunately, a fatal error has occurred. Please report this error to the Bundler issue tracker at https://github.com/carlhuda/bundler/issues so that we can fix it. Please include the full output of the command, your Gemfile and Gemfile.lock. Thanks!
/Users/me/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/site_ruby/1.9.1/rubygems/installer.rb:551:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/Users/me/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
/Users/me/.rvm/gems/ruby-1.9.2-p290/gems/bundler-1.0.15/lib/bundler/spec_set.rb:87:in `block in materialize': Could not find capybara-webkit-0.11.0 in any of the sources (Bundler::GemNotFound)
When I try to install the capybara-webkit gem, it says it cannot find the capybara-webkit gem. I already have qt4 installed:
$ sudo port list installed | grep qt4
qt4-mac #4.7.4 aqua/qt4-mac
Any idea what the issue could be?
I'd try installing qt using brew rather than port.
I have capybara-webkit installed on my mac right now (version 0.11.0 just as you were attempting to install) and it installed and works great.
However, I don't have port on my machine. I use brew to install most everything now.
So
brew install qt
could make a difference.
Here's a link to an installation script used by the team at Thoughtbot (the people who built and support capybara-webkit) -- you can see that it installs qt using brew as well:
https://github.com/thoughtbot/laptop/blob/master/mac
echo "Installing QT, used by Capybara Webkit for headless Javascript integration testing ..."
brew install qt
I'm quite late on this one, but I've had a similar problem and figured out the problem was I had Macports and Homebrew installed.
So I uninstalled Macports:
sudo port -fp uninstall installed
Updated my Homebrew:
brew update (that took a while)
And then installed QT with only brew installed asking to build from source:
brew install qt --build-from-source (that took like 25 minutes to finish)
If you try qmake -v now, you'll probably get an error saying qmake is not in /opt/local/bin. This is because Homebrew installed QT in /usr/local/bin, and you have to add it to your PATH with the next command:
export PATH="/usr/local/bin:$PATH"
In the end it took me like 3 hours to find the solution, but it worked like a charm.
I hope this helps other people having the same issue.

Can't install Ruby on OS X

I'm trying to follow the installation instructions for Ruby on Rails from Hivelogic.com. I've done this before on previous installs of OSX without trouble. I'm having trouble this time installing on Snow Leopard.
At the end of the "make" step installing Ruby, I get a number of errors related to readline. Not sure if this matters, but here they are:
readline.c: In function ‘username_completion_proc_call’:
readline.c:730: error: ‘username_completion_function’ undeclared (first use in this function)
readline.c:730: error: (Each undeclared identifier is reported only once
readline.c:730: error: for each function it appears in.)
make[1]: *** [readline.o] Error 1
make: *** [all] Error 1
When I try to sudo make install, I get more errors. When I "which ruby", I get /usr/local/bin/ruby which is correct. But as soon as I try to use ruby, I get this message: "You need the Rosetta software to run ruby. The Rosetta installer is in Optional Installs on your Mac OS X installation disc." That's weird, but I installed Rosetta, and was able to proceed.
Except: I still have Ruby1.8.6 installed (not 1.8.7). "ruby -v" reports 1.8.6. 1.8.6 was the version that was migrated (I assume) from the Leopard install on this machine. In other words: where's my new Ruby? How do I get 1.8.7 (required by the current version of Rails) installed correctly?
I've always found macports the best way to install/manage my ruby versions. I have 1.8.6, 1.8.7 and 1.9.1 all installed using macports.
First, grab macports and install it.
Then, update (or create) your ~/.bashrc file to include the following line:
export PATH=/opt/local/bin:$PATH
This places all macports executables in front of you path, so you system will find them first.
Finally, install any of the versions of ruby you want:
sudo port install ruby186
sudo port install ruby
sudo port install ruby19
I also recommend installing rubygems from scratch after ruby is installed. Grab the latest rubygems release here and then run the following from inside the downloaded rubygems directory:
sudo ruby setup.rb
Hope this works out for you.
If you have snow leopard than 1.8.7 is pre-installed in /usr/bin
Another option is to use VirtualBox and install Ubuntu on VirtualBox. Ruby installation and usage is much smoother this way I have found, as I wasted a lot of time trying to get Ruby working properly on the Mac.

Resources