El Capitan Update rails - ruby-on-rails

Just updated my system to El Capitan and when launching the rails server (that worked perfectly on Yosemite) I get the following warning.
Ignoring bcrypt-3.1.10 because its extensions are not built. Try: gem pristine bcrypt --version 3.1.10
Ignoring bcrypt-ruby-3.1.2 because its extensions are not built. Try: gem pristine bcrypt-ruby --version 3.1.2
Ignoring bcrypt-ruby-3.0.1 because its extensions are not built. Try: gem pristine bcrypt-ruby --version 3.0.1
Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.7.2
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
when running the referenced commands I get:
-bash: bundle: command not found
rails update
Ignoring json-1.8.1 because its extensions are not built. Try: gem pristine json --version 1.8.1
Ignoring json-1.8.2 because its extensions are not built. Try: gem pristine json --version 1.8.2
Ignoring json-1.8.3 because its extensions are not built. Try: gem pristine json --version 1.8.3
Ignoring nokogiri-1.6.6.2 because its extensions are not built. Try: gem pristine nokogiri --version 1.6.6.2
Ignoring atomic-1.1.14 because its extensions are not built. Try: gem pristine atomic --version 1.1.14
Ignoring atomic-1.1.14 because its extensions are not built. Try: gem pristine atomic --version 1.1.14
Ignoring bcrypt-ruby-3.0.1 because its extensions are not built. Try: gem pristine bcrypt-ruby --version 3.0.1
Ignoring binding_of_caller-0.7.2 because its extensions are not built. Try: gem pristine binding_of_caller --version 0.7.2
Warning: Running `gem pristine --all` to regenerate your installed gemspecs (and deleting then reinstalling your bundle if you use bundle --path) will improve the startup performance of Spring.
Could not find bcrypt-3.1.10 in any of the sources
Run `bundle install` to install missing gems.
also tried running:
sudo gem pristine --all
Restoring gems to pristine condition...
ERROR: While executing gem ... (Errno::EPERM)
Operation not permitted - /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/gems/2.0.0/gems/CFPropertyList-2.2.8/README
So now, it can't even find the bundle install path. Seems like the update has really messed it up.
When I run gem pristine --all I get the following:
Restored bcrypt-ruby-3.1.5
Skipped bigdecimal-1.2.0, it is a default gem
Building native extensions. This could take a while...
Restored binding_of_caller-0.7.2
Restored bootstrap-sass-3.3.5.1
Restored builder-3.2.2
Restored builder-3.1.4
Restored bundler-1.10.6
Restored bundler-1.9.6
Building native extensions. This could take a while...
ERROR: While executing gem ... (Gem::Ext::BuildError)
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r ./siteconf20151001-3494-1jca623.rb extconf.rb
creating Makefile
make "DESTDIR=" clean
make "DESTDIR="
make: *** No rule to make target `/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.10.sdk/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/universal-darwin15/ruby/config.h', needed by `breakpoint.o'. Stop.
make failed, exit code 2
Gem files will remain installed in /Library/Ruby/Gems/2.0.0/gems/byebug-6.0.2 for inspection.
Results logged to /Library/Ruby/Gems/2.0.0/extensions/universal-darwin-15/2.0.0/byebug-6.0.2/gem_make.out

Solution is in the following link.
Hardware
Upgrade to El Capitan, with Homebrew & Ruby
... and Xcode and Java, etc.
If you don't already have homebrew installed, do that first, so you don't have to deal with SIP issues. Install all Software Updates available in the Apple Menu, up to and including El Capitan.
After the installs and forced reboots my 27" Thunderbolt display wouldn't display anything. Unplug, replug didn't help. One more reboot fixed it.
Software
In order...
Xcode
The El Capitan install wiped out my Xcode install, so I had to search for it in the App Store and reinstall. I now believe that I deleted Xcode awhile ago and forgot, hence the reinstall. I did this on a machine that I rarely use.
After Xcode is finished installing, open iTerm, which I use as a Terminal.app replacement, or Terminal.app if you are so inclined.
∴ xcode-select --install
xcode-select: note: install requested for command line developer tools
A dialog opened, I chose "Install", which finished in about a minute.
Java
Next, run java, which prompts with a dialog that has a button "More Info" which takes you to a website where you can accept the license and download the Java .dmg file. You need the JDK, not the JRE, if you intend to run java command-line based tools.
Unable to find any JVMs matching version "1.7".
No Java runtime present, try --request to install.
∴ java
No Java runtime present, requesting install.
Once downloaded, open the .dmg (for me it was jdk-8u60-macosx-x64.dmg) and install, then restart iTerm.
∴ java -version
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
Apps like RubyMine should work now, well, at least launch.
Homebrew
The doctor informed me of several warnings which I took care of as instructed.
∴ brew doctor
∴ sudo chown -R $(whoami):admin /usr/local
∴ cd /usr/local/Library && git stash && git clean -d -f
∴ cd ~
∴ brew prune
∴ brew unlink qt5
Then I was able to update Homebrew.
∴ brew update
qt5
I know the capybara-webkit gem will require qt5, and I know qt is one of the primary remaining pain points in homebrew / El Capitan issues tracker, so I decided to get it out of the way first.
∴ brew uninstall qt5
∴ brew install qt5
∴ brew linkapps qt5
∴ brew link --force qt5
That last line is required to make qmake available. Check with which qmake. Otherwise you will end up with this on the Capybara install later on:
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/Users/pboling/.rvm/rubies/ruby-2.1.2/bin/ruby -r ./siteconf20150930-48087-1vw6bye.rb extconf.rb
sh: qmake: command not found
*** extconf.rb failed ***
GPG
Some software is now being signed with GPG, like RVM, for example, so install it.
∴ brew install gpg
RVM
My Ruby was working, but I was having trouble with some native gem installations, so I decided to start fresh with a Ruby compiled against all the new homebrew and Xcode libraries.
∴ rvm implode
Implode actually failed to remove the main ~/.rvm directory due to permissions issues. I had to sudo remove it.
∴ sudo rm -rf /Users/pboling/.rvm
Follow the instructions here for installing RVM, I installed the development version, hoping it would have more El Capitan fixes in it:
∴ gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3
∴ \curl -sSL https://get.rvm.io | bash
The main app I currently work on is using Ruby 2.1.2, so I install that first, and then go to the project directory to have the gemset created and to bundle.
∴ rvm install 2.1.2
∴ cd ~/project
∴ gem install bundler -v 1.9.7
∴ bundle install
Bundler version 1.9.7 because that's what Heroku is on, and I want to stay in sync, because 1.10* changed things that make the Gemfile.lock incompatible with 1.9.7 on the deployed server (for me, with multiple gem sources, private gem server, etc).
Postgres
I also took the opportunity to upgrade to the latest Postgres.app. Alternatively you can install postgres with brew install postgres. I choose Postgres.app begause it is supported directly by Heroku, and I like to think there is a parity win there somewhere.

You should try RVM or RBENV or whatever the flavor of the week is. This will allow you to easily manage your Ruby Interpreters and Gemsets on a per project basis. I still use RVM and I'm quite happy with it.
https://rvm.io/rvm/install

Related

Gemset error when updating to Ruby 2.4.2

I'm updating from Ruby 2.0 to 2.4.2 using RVM, and receive the following error messages during an install using $ rvm install ruby-2.4.2:
Making gemset ruby-2.4.2 pristine - please wait
'command gem pristine --extensions bigdecimal --version 1.3.0 gem-wrappers --version 1.3.2 io-console --version 0.4.6 json --version 2.0.4 openssl --version 2.0.5 psych --version 2.2.2' failed, you need to fix this gems manually.
Error running '__rvm_with ruby-2.4.2 gemset_pristine',
please read /Users/myname/.rvm/log/1507820191_ruby-2.4.2/gemset.pristine-ruby-2.4.2.log
Making gemset ruby-2.4.2#global pristine - please wait
'command gem pristine --extensions bigdecimal --version 1.3.0 io-console --version 0.4.6 json --version 2.0.4 openssl --version 2.0.5 psych --version 2.2.2' failed, you need to fix this gems manually.
Error running '__rvm_with ruby-2.4.2#global gemset_pristine',
please read /Users/myname/.rvm/log/1507820191_ruby-2.4.2/gemset.pristine-ruby-2.4.2#global.log
I'm… not quite sure what this means, or what I should do next. Any thoughts? I'm running macOS 10.12.6.
[Edit]: Here's a copy of the error log.
According to the RVM docs, you don't use ruby- in the command.
It should be:
$ rvm install 2.4.2
I'm not sure if that matters or not though.
Have you tried upgrading RVM and Homebrew?
[Edit] Based on this info from the log file:
bigdecimal-1.3.0 +gemset_pristine:20> gem pristine --extensions bigdecimal --version 1.3.0
ERROR: Loading command: pristine (LoadError)
cannot load such file -- zlib
ERROR: While executing gem ... (NoMethodError)
undefined method `invoke_with_build_args' for nil:NilClass
+gemset_pristine:21> _failed+=( 'bigdecimal --version 1.3.0' )
Looks like a zlib problem. Try installing (or re-installing) Command Line Tools.
$ xcode-select --install
There is a very similar issue on github https://github.com/rvm/rvm/issues/4090
It was solved by running $ brew doctor
Just came up against this after needing to use SASS after a while. During which time I had upgraded to El Capitan. So Ruby was 'Old'.
You could probably cut a lot of my steps out by running the following (with a little prior knowledge of the latest Ruby Version).
xcode-select --install
brew install zlib
rvm reinstall ruby-<latest_version> --with-zlib-dir=/usr/local/Cellar/zlib/<latest_version>
This was how I had to go about it. I didn't need to uninstall in the end but I took a lot of wrong turns.
Initially I had to run this line to get xcode up to date:
xcode-select --install
Then install zlib
brew install zlib
Take a note of the directory zlib is installed in
/usr/local/Cellar/zlib/1.2.11
Next update rvm
\curl -sSL https://get.rvm.io | bash -s stable --ruby
Following these steps got me to the point where I was running the latest version of ruby 2.4.1. But zlib wasn't linked to ruby.
So the final step was to run a reinstall
rvm reinstall ruby-2.4.1 --with-zlib-dir=/usr/local/Cellar/zlib/1.2.11
Found a fix as referenced in this RVM GitHub issue that involves installing zlib using brew and then re-installing ruby while pointing to that zlib directory.
As someone in that thread pointed out, this shouldn't be necessary. Still not sure why the problem arose.
Steps
$ brew install zlib
$ rvm remove 2.4.2
$ rvm install 2.4.2 —-with-zlib-dir=/usr/local/Cellar/zlib/1.2.11

error occurred while installing pg (0.17.1)

When I run a bundle on a rails project I seem to be getting the following:
Installing pg 0.17.1 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/bin/ruby -r
./siteconf20151024-43303-t81fnp.rb extconf.rb checking for
pg_config... yes Using config values from /usr/local/bin/pg_config An
error occurred while installing pg (0.17.1), and Bundler cannot
continue. Make sure that gem install pg -v '0.17.1' succeeds before
bundling.
I have visited the following SO questions:
An error occurred while installing pg (0.17.1), and Bundler cannot continue
Installing pg -v 0.17.1
Installing PG gem on OS X - failure to build native extension.
Additionally to this I've tried executing the following:
gem install pg
env ARCHFLAGS="-arch x86_64" gem install pg
gem install pg -- --with-pg-config=/usr/local/Cellar/postgresql/9.4.5/bin/pg_config
And I keep getting:
ERROR: While executing gem ... (Gem::FilePermissionError)
You don't have write permissions for the /Library/Ruby/Gems/2.0.0 directory.
FYI I have rbenv installed too. Also tried a rbenv rehash also and executed the above commands and have had no luck. I've also tried uninstalling and reinstalling Postgres and get the same. To also be on the safe side i've also ran:
brew update
brew uinstall posgresql > brew install postgresql
updated Xcode
Info:
Mac OSx Yosemite 10.10.5
Postgres v9.4.5
rbenv v0.4.0
rbenv global => 2.0.0-p247
I don't know Mac, but I've had this problem on Windows.
--
The issue is here:
Failed to build gem native extension
When you install a gem, many of the advanced ones actually compile / "build" through the extconf.rb file. I've forgotten the significance of this, but it basically allows the gem to run natively on the OS environment you're using.
In short, the error occurs because your OS does not have access to the "developer headers" the gem requires to compile.
The most common instance of this problem is with the mysql2 gem on Windows, but happens for others too.
--
What you need is to download PGSQL on your system before attempting to install the gem.
After installing PGSQL, you may need to reference the developer headers with some "switches", but it does not appear to be the case in this instance:
Installing PG gem on OS X - failure to build native extension
Install Xcode command line tools (Apple Developer site)
brew uninstall postgresql
brew install postgresql
ARCHFLAGS="-arch x86_64" gem install pg
Maybe this won't work? I don't know... I know that in Windows, you have to install the binaries before expecting the gem to work.
Greetings I hope I can help. May I ask how you created your rails project? Did you simply use:
rails new *appname*
If so maybe try creating a new rails app like so:
rails new *appname* -d postgresql
And before you create your database and run migrations/seed, you should go into "config/database.yml" and change the username and password to the postgreSQL user that you've hopefully setup after installing postgreSQL on your machine.
Good Luck!

How to create Migration File in rails? [duplicate]

I have done all kinds of research and tried many different things. I know this question has been answered many times, but none of the suggested solutions are working for me.
After upgrading to Lion I am getting segmentation faults in Ruby. I'm fairly confident it's Nokogiri. So I installed libxml2 via Homebrew. I ran brew link libxml2. Then I reinstalled Nokogiri using that version of the library.
For proof:
$ nokogiri -v
# Nokogiri (1.5.0)
---
warnings: []
nokogiri: 1.5.0
ruby:
version: 1.9.2
platform: x86_64-darwin11.0.0
description: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.0.0]
engine: ruby
libxml:
binding: extension
compiled: 2.7.8
loaded: 2.7.8
I've already included Nokogiri at the top of my gemfile and I've also required it in my environment file. I have no idea why I am still getting that warning.
Any suggestions or ideas to make sure it's loading the right version libxml2?
If you installed Nokogiri with gem install nokogiri, you can resolve this warning by running gem pristine nokogiri to recompile the gem's C extension.
If you installed Nokogiri with bundle install, you can resolve this warning by running bundle exec gem pristine nokogiri to recompile the C extension of the gem wherever Bundler installed it.
To fix this if you're using homebrew and bundler, add gem 'nokogiri' to the top of your Gemfile, then run these commands:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle install
If you don't use bundler, run these commands instead:
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2 --with-xml2-config
brew install libxslt
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
In your app, you should require nokogiri first, to force the app to load the dynamic libxml2 library instead of the older system version of libxml2 loaded by gems that failed to specify which library to load.
I just spent the better part of the morning working through this warning. This fix is for people using Mac OS Lion. The fix above using
bundle config build.nokogiri --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
is for Snow Leopard with libxml2 installed via MacPorts.
With Lion, libxml2 is loaded as part of the bootstrap process. Regardless of which libxml2 Nokogiri is pointing to, the Lion system default library for libxml2 will be used at runtime. Lion uses libxml2.2.7.3 found in /usr (not /usr/local).
As mentioned many other places, one can just ignore the warning. If, like me, the warning drives you crazy, you can do this:
bundle config build.nokogiri --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
Interestingly, if you type nokogiri -v at the command line you will get the opposite warning:
WARNING: Nokogiri was built against LibXML version 2.7.3, but has dynamically loaded 2.7.8
This suggests there is more to how libxml2 is being loaded, with Ruby and Rails using the system loaded libxml2 and the command line using libxml2 from the environment path. Anyway, this silences the error for me.
I’ll say it again – this is only for Lion. The previous fix will work for Snow Leopard.
This is the end of the answer. Stop reading here.
OK, you didn’t stop reading... well...
NOT RECOMMENDED!!!!!!
You have been warned. You can verify that Mac OSX is loading the libxml2 library in its bootstrap by disabling libxml2 found in /usr/lib. Do something like copying all versions of libxml2*.dylib to libxml2*.dylib.old (on my machine this was libxml2.2.7.3, libxml2.2 and libxml2).
After you have done this, running Nokogiri will not produce any errors. That is because it can’t find the loaded libxml2 and will now follow the environment path, eventually finding libxml2.2.7.8 in /opt/local.
BUT you won’t be able to copy the old libxml files back. This is because the OS needs the libxml2 that was loaded in the bootstrap.
Powering off and powering on again will brick your machine. The login screen will hang and hang and hang. Power off and power on again in single-user mode (hold Command-S while rebooting). You can watch the bootstrap occur. Low and behold, it throws an error that it can’t load libxml2 and then stops working.
Power off and power on again. This time boot into recovery mode (either hold Command-R or hold Option and then select the recovery disk). In recovery mode open the terminal (utilities/terminal). Mount /usr/lib on your HD (try /Volumes/Macintosh\ HD/usr/lib) and copy the libxml2 files back. Reboot and all will be fine.
None of this worked for me.
I had libxml2 installed at a later version (2.7.8) with brew. This caused nokogiri to compile against it and the later problems. Solution, remove it, then build, then install if desired.
Here's what worked:
brew uninstall libxml2 (if previously installed)
gem uninstall nokogiri
gem install nokogiri
brew install libxml2 (optional)
The solution (for me) after updating to Mountain Lion was much simplier:
gem uninstall nokogiri
# (and ignore the warnings about dependencies)
gem install nokogiri
As per the comment from patrickmcgraw above, simply putting nokogiri as the first entry in my Gemfile worked for me. I'm putting it as a separate answer because the original comment has been buried.
source 'http://rubygems.org'
gem 'nokogiri'
gem 'rails', '3.0.20'
etc...
Bundler has options to set the default build locations. So for instance, with libxml2 installed via macports:
$ bundle config build.nokogiri --with-xml2-include=/opt/local/include/libxml2 --with-xml2-lib=/opt/local/lib --with-xslt-dir=/opt/local
After doing this and bundle install, the warning went away.
There's also some helpful examples for setting build options on the nokogiri wiki.
Looks like you have updated your system libraries after installing the gem, so you have to update Nokogiri. To use the current lib version:
gem install nokogiri -- --use-system-libraries
I had similar problem and just solved this way:
In my case, I have RVM installed, and I had #global and #project gem sets.
Both of them had nokogiri installed and one of them had built with with different libxml.
Rebuilding both of them (I have reason to do this) solved the problem.
Hope this helps..
gem uninstall nokogiri
bundle #install nokogiri again
If that fails with "libxml2 is missing." and you see gems/nokogiri-1.5.0/ext/nokogiri/mkmf.log trying to use "/usr/bin/gcc-4.2 ...", then you're missing /usr/bin/gcc-4.2
Solution:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
Before:
$ ll /usr/bin/gcc*
lrwxr-xr-x 1 root wheel 12 Jan 15 00:16 /usr/bin/gcc -> llvm-gcc-4.2
After:
$ ll /usr/bin/gcc*
lrwxr-xr-x 1 root wheel 12 Jan 15 00:16 /usr/bin/gcc -> llvm-gcc-4.2
lrwxr-xr-x 1 root wheel 12 Jan 15 21:07 /usr/bin/gcc-4.2 -> /usr/bin/gcc
If you're really missing libxml2 libxslt, then
brew update
brew install libxml2 libxslt
brew link libxml2 libxslt
bundle config build.nokogiri --with-xml2-include=/usr/local/Cellar/libxml2/2.8.0/include/libxml2/ --with-xml2-lib=/usr/local/Cellar/libxml2/2.8.0/lib/ --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.26/
bundle
FYI: I'm running Mountain Lion with brew, and bundler.
gem install libxml-ruby helps me
I actually had 2 versions of libxml installed, one from source, one from an RPM.
The following is my complete solution
I uninstalled source (from the source directory)
sudo make uninstall
Remove bundles
rm -rf ~/.bundle ~/.bundler
Updated LD (might have to do this as root, not sudo)
sudo ldconfig
Then reinstalled the bundle
bundle install
Just ran into this myself (OS X Lion 10.7.5). My exact message was: Nokogiri was built against LibXML version 2.8.0, but has dynamically loaded 2.7.3
I tried a few suggestions mentioned here, none worked, but this did:
gem install nokogiri -- --with-xml2-dir=/usr --with-xslt-dir=/opt/local --with-iconv-dir=/opt/local
The explanation is: "This happens because the Lion system default libxml2 (loaded at bootstrap) is used, regardless of which libxml2 Nokogiri was built against."
Credits to: https://coderwall.com/p/o5ewia
OS : Maverick 10.9.3
Ruby 1.9.3
WARNING: Nokogiri was built against LibXML version 2.9.1, but has dynamically loaded 2.9.0
My solution:
gem uninstall nokogiri
brew update
cd /usr/local
brew versions libxml2
git checkout 5dd45d7 /usr/local/Library/Formula/libxml2.rb # libxml version 2.9.0
brew install libxml2
bundle install or gem install nokogiri -v "1.5.11"
Hope this help
If you have this message and your nokogiri is out-of-date with the version available from the gem source, simply run bundle update nokogiri to get the new code and recompile. Your error should go away.
OS: Catalina
Warning: warning nokogiri was built against libxml version 2.9.10 but has dynamically loaded 2.9.4
I followed Michiel de Mare steps, but brew install libxml2 --with-xml2-config failed with invalid option error. So I installed libxml2 and libxslt and took note of the output from both commands.
brew install libxml2
==> Downloading https://homebrew.bintray.com/bottles/libxml2-2.9.10_2.catalina.bottle.tar.gz
Already downloaded: /Users/alberto/Library/Caches/Homebrew/downloads/9ddf5cb90fd16a7eb531e37bb748fd392f30214d9fe1568b2b70d28cc368c8f7--libxml2-2.9.10_2.catalina.bottle.tar.gz
==> Pouring libxml2-2.9.10_2.catalina.bottle.tar.gz
==> Caveats
libxml2 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 libxml2 first in your PATH run:
echo 'export PATH="/usr/local/opt/libxml2/bin:$PATH"' >> ~/.zshrc
For compilers to find libxml2 you may need to set:
export LDFLAGS="-L/usr/local/opt/libxml2/lib"
export CPPFLAGS="-I/usr/local/opt/libxml2/include"
For pkg-config to find libxml2 you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxml2/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/libxml2/2.9.10_2: 280 files, 10.6MB
brew install libxslt
==> Downloading https://homebrew.bintray.com/bottles/libxslt-1.1.34.catalina.bottle.tar.gz
==> Downloading from https://d29vzk4ow07wi7.cloudfront.net/cbadecf3186f45754220dff4cbdfbb576882a211d615b52249a4c9d8ba4d7c3a?response-content-disposition=attachment%3Bfil
######################################################################## 100.0%
==> Pouring libxslt-1.1.34.catalina.bottle.tar.gz
==> Caveats
To allow the nokogiri gem to link against this libxslt run:
gem install nokogiri -- --with-xslt-dir=/usr/local/opt/libxslt
libxslt 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 libxslt first in your PATH run:
echo 'export PATH="/usr/local/opt/libxslt/bin:$PATH"' >> ~/.zshrc
For compilers to find libxslt you may need to set:
export LDFLAGS="-L/usr/local/opt/libxslt/lib"
export CPPFLAGS="-I/usr/local/opt/libxslt/include"
For pkg-config to find libxslt you may need to set:
export PKG_CONFIG_PATH="/usr/local/opt/libxslt/lib/pkgconfig"
==> Summary
🍺 /usr/local/Cellar/libxslt/1.1.34: 136 files, 2.8MB
And I used those directories when configuring bundle for nokogiri
bundle config build.nokogiri --with-xml2-include=/usr/local/opt/libxml2/include --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt/libxslt
To summarize I executed these steps
gem uninstall nokogiri libxml-ruby
brew update
brew uninstall libxml2
brew install libxml2
brew install libxslt
bundle config build.nokogiri --with-xml2-include=/usr/local/opt/libxml2/include --with-xml2-lib=/usr/local/opt/libxml2/lib --with-xslt-dir=/usr/local/opt/libxslt
bundle install

Unable to install gem - Failed to build gem native extension - cannot load such file -- mkmf (LoadError)

Ruby 1.9.3
The part of Gemfile
#...............
gem "pony"
gem "bcrypt-ruby", :require => "bcrypt"
gem "nokogiri"
#..................
When I'm trying to install gems, I get an error
alex#ubuntu:~/$ bundle
Fetching gem metadata from http://rubygems.org/.........
Fetching gem metadata from http://rubygems.org/..
Enter your password to install the bundled RubyGems to your system:
#####............................................................
Installing bcrypt-ruby (3.0.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:36:in `<main>'
Gem files will remain installed in /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /home/alex/.bundler/tmp/5526/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
An error occurred while installing bcrypt-ruby (3.0.1), and Bundler cannot continue.
Make sure that `gem install bcrypt-ruby -v '3.0.1'` succeeds before bundling.
Then I'm doing this
sudo gem install bcrypt-ruby -v '3.0.1'
Building native extensions. This could take a while...
ERROR: Error installing bcrypt-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby1.9.1 extconf.rb
/usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError)
from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require'
from extconf.rb:36:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/bcrypt-ruby-3.0.1/ext/mri/gem_make.out
and getting an error as well.
What did I miss?
There are similar questions:
`require': no such file to load -- mkmf (LoadError)
Failed to build gem native extension (mkmf (LoadError)) - Ubuntu 12.04
Usually, the solution is:
sudo apt-get install ruby-dev
Or, if that doesn't work, depending on your ruby version, run something like:
sudo apt-get install ruby1.9.1-dev
Should fix your problem.
Still not working? Try the following after installing ruby-dev:
sudo apt-get install make
For WSL (Windows Subsystem for Linux) you need install build-essential package:
sudo apt install build-essential
Just finished a 2 hour wild goose chase trying to solve this. None of the posted answers worked for me. Im on a Mac (Mojave Version 10.14.6, Xcode Version 11.3).
It turns out the ruby file headers were missing so i had to run open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
That didnt work for me at first because the version of CommandLineTools i had installed did not have the "Packages" folder. So i uninstalled and reinstalled like this:
rm -rf /Library/Developer/CommandLineTools
xcode-select --install
Then i ran the previous command again:
open /Library/Developer/CommandLineTools/Packages/macOS_SDK_headers_for_macOS_10.14.pkg
After install the error was fixed!
I had the same issue trying to install jquery-rails. The fix was
sudo apt-get install zlibc zlib1g zlib1g-dev
For MacOS users:
Just do this and easily it will solve your problem:
brew install cocoapods
In case anyone in the future had this problem, I'm using a Mac and just had to install the Command Line Tools using 'xcode-select --install'
I found that I needed to install another version of ruby. So running the command
$ sudo apt-get install ruby1.9.1-dev
and then attempt to install the extension
If you run into issues where it is telling you that you don't have g++ you can run the following command to install it
$ sudo apt-get install g++
Make sure ruby-dev is installed
Make sure make is installed
If you still get the error, look for suggested packages. If you are trying to install something like gem install pg you will also need to install the lib libpq-dev (sudo apt-get install libpq-dev).
I created a small hackMD to install cocoapods on MacOS 10.15 (Catalina) and 11 (Big Sur)
https://hackmd.io/#sBJPlhRESGqCKCqV8ZjP1A/S1UY3W7HP
Installing Cocoapods on MacOS Catalina(MacOS 10.15.X) and Big Sur (MacOS 11)
Make sure you have xcode components are installed.
Download 'Command Line Tools' (about 500MB) directly from this link (Requires you to have apple account)
https://developer.apple.com/downloads/index.action
Install the downloaded file
Click on Install
Install COCOAPODS files in terminal
sudo gem install -n /usr/local/bin cocoapods
This worked for me.
bundle config --global build.snappy --with-opt-dir="$(brew --prefix snappy)"
It also helps to ensure libmysqlclient-dev is installed (Ubuntu 14.04)
What ended up working for me after a few hours of pain..
if you're running brew..
brew install ruby
in the terminal output/log, identify the path where ruby was installed, brew suggests 'You may want to add this to your PATH', so that's what we'll do. For example, mine is
/usr/local/lib/ruby/gems/3.0.0/bin
Add this to your path by running (omitting braces)
echo 'export PATH"{the_path_you_found_above}:$PATH"' >> ~/.bash_profile
then update your environment by running
source ~/.bash_profile
now, try running your install, i.e.,
sudo gem install middleman
If you are a mac user you must need to update the clang version being used
I burnt hours searching this and installed uninstalled xcode commandline tools but it didn't help.
I ran gcc -v and Apple clang version 11.0.0 (clang-1100.0.33.8 was the output.
Then I ran xcode-select -s /Library/Developer/CommandLineTools/ and clang version was updated to Apple clang version 12.0.0 (clang-1200.0.32.29).
bundle install was successful after that.
I hope this may help.
I was making a word search app and I had to install cocoapods and after formatting my mac and reinstalling xcode, I still got the error when I wanted to install cocoapods.
And the solution for this was the following:
It looks like CocoaPods 1.9.0, the latest version as of this writing, depends on a newer version of Ruby than 2.3.7. But macOS Mojave only includes Ruby 2.3.7, so you have a few different options.
Upgrade to macOS Catalina and get Ruby 2.6.3
Use Ruby Version Manager to install a newer version of Ruby
Install an older version of CocoaPods
sudo gem install cocoapods -v 1.8.4
I did 3:
sudo gem install cocoapods -v 1.8.4
In Mac, for me this works:
CONFIGURE_OPTS="--enable-shared" rbenv install 2.2.2
After some search for a solution, it turns out the -dev package is needed, not just ruby1.8. So if you have ruby1.9.1 doing
sudo apt-get install ruby1.9.1-dev
or to install generic ruby version, use (as per #lamplightdev comment):
sudo apt-get install ruby-dev
should fix it.
Try to locate mkmf to see if the file is actually there.
first set your Xcode version on the terminal:
sudo xcode-select -switch /Applications/Xcode.app
then install:
sudo gem install cocoapods

Why do I get a bcrypt-ruby gem install error?

Getting an error when trying to install the gem devise, the installation is stopping on
the gem bcrypt-ruby:
$ gem install bcrypt-ruby
Error installing bcrypt-ruby:
ERROR: Failed to build gem native extension.
I'm running OSX 10.6.7 with Ruby under RVM.
I reinstalled the lastest version of xcode & reinstalled Ruby 64bit, Rails and all the gems.
I had the same problem installing under OSX 10.7.3. When installing the gem, my error message was:
Building native extensions. This could take a while...
ERROR: Error installing bcrypt-ruby:
ERROR: Failed to build gem native extension.
creating Makefile
make
compiling bcrypt_ext.c
make: /usr/bin/gcc-4.2: No such file or directory
make: *** [bcrypt_ext.o] Error 1
Looks like the gem is looking for gcc-4.2 but I only had a file called gcc. Now since I had just installed the latest Xcode (4.3), I knew that my C compiler was compliant but the gem had gcc-4.2 hardcoded into it. So my solution was:
sudo ln -s /usr/bin/gcc /usr/bin/gcc-4.2
The linking worked like a charm.
Looks like there might be some info missing here - for me, this was due to a brew install of gcc. gcc was in /usr/bin, but not gcc-4.2. So I just did the following:
$ cd /usr/bin
$ sudo ln -s gcc gcc-4.2
which creates a link, gcc-4.2, which the gem is looking for that goes back to gcc.
Hope that helps.
It requires to install ruby-dev before installing bcrypt-ruby.
If you are using Ubuntu, run
sudo apt-get install ruby1.9.1-dev
or
sudo apt-get install ruby1.8-dev
based on RUby version.
I'm using RVM & I kept having this issue whenever installing gems with native extensions (bcrypt-ruby, bson-ext, json, eventmachine, nokogiri, linecache19, etc.)
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
Only way I could finally get things working was to uninstall then re-install ruby.
rvm remove 1.9.2
rvm install 1.9.2
Thanks to tip from #doublebee here:
https://github.com/flori/json/issues/78#issuecomment-1499920
You only need use rvm (ruby version manager)
rvm uninstall 1.9.3
and then
rvm install 1.9.3
looks this error is on build of rvm 1.9.3, but uninstall and reinstalling fix the problem with bcrypt-ruby 3.0.1
sudo apt-get install ruby1.9.1-dev
whoked charm for me! Thanks a lot
Well, it works with Ruby 1.9.2 under RVM on MacOS 10.6.7:
$ ruby -v
ruby 1.9.2p180 (2011-02-18 revision 30909) [x86_64-darwin10.6.0]
$ gem install bcrypt-ruby
Fetching: bcrypt-ruby-2.1.4.gem (100%)
Building native extensions. This could take a while...
Successfully installed bcrypt-ruby-2.1.4
1 gem installed
Installing ri documentation for bcrypt-ruby-2.1.4...
Installing RDoc documentation for bcrypt-ruby-2.1.4...
Try rvm notes and see if it says you need to install anything.
If you are using version 1.8 the required packages for bcrypt are in the dev bundle. Try using
$sudo apt-get install ruby1.8-dev
then
$gem install bcrypt-ruby
This fix work for me on ubuntu on osx use homebrew, macports whatever:
sudo apt-get install ruby1.9.1-dev
I think you need to reinstall bundler gem.
gem install bundler
and then
bundle install

Resources