Error while installing cucumber (involving gherkin) - ruby-on-rails

I'm trying to set up cucumber for rails. I included this in my Gemfile and ran bundle install.
gem 'cucumber-rails'
gem 'database_cleaner'
I got this error. What should I do?
ERROR: Error installing gherkin:
ERROR: Failed to build gem native extension.
/Users/[my_user_name]/.rvm/rubies/ruby-1.9.2-p290/bin/ruby extconf.rb
checking for main() in -lc... *** 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.

This question is a bit old, but as I just had a similar problem on my machine I will document my solution here.
The problem seems to be related to OS X Lion, GCC, clang etc. (see https://github.com/carlhuda/bundler/issues/1590 and https://github.com/carlhuda/bundler/issues/1600). As how ruby was compiled seems to be the problem I decided to re-install (and also upgrade) ruby.
Here is what solved this issue for me:
I use the Command Line Tools for Xcode package.
Furthermore the current version of rbenv and ruby-build (both installed via homebrew)
rbenv install 1.9.3-p125 failed (see https://github.com/sstephenson/ruby-build/issues/129 and https://github.com/sstephenson/ruby-build/issues/130)
remove the require_gcc line for 1.9.3-p125 (if installed with homebrew you find the file under /usr/local/Cellar/ruby-build/20120216/share/ruby-build/1.9.3-p125)
finally successfully install 1.9.3-p125 with env CC=/usr/bin/gcc rbenv install 1.9.3-p125
Complicated but I can now install gems with natiive extensions.
Hope this helps.
Update: btw. It is possible to keep using ruby-1.9.2-p290, all you have to do is re-install it.
First "uninstall" the old ruby-1.9.2-p290: rm -rf .rbenv/versions/1.9.2-p290
Next remove the require_gcc line for 1.9.2-p290
Finally install with env CC=/usr/bin/gcc rbenv install 1.9.2-p290

Related

ERROR: Error installing rmagick: in Windows with Ruby 2.2

I cloned my code from git to my Windows machine and when I run bundle install, I am getting this error:
An error occurred while installing rmagick (2.13.4), and Bundler
cannot continue. Make sure that gem install rmagick -v '2.13.4'
succeeds before bundling.
D:\project\MyProject2>gem install rmagick -v '2.13.4'
Temporarily enhancing PATH to include DevKit... Building native
extensions. This could take a while... ERROR: Error installing
rmagick:
ERROR: Failed to build gem native extension.
D:/RailsInstaller/Ruby2.2.0/bin/ruby.exe -r ./siteconf20160721-7208-bn9t3e.rb extconf.rb checking for Ruby version
= 1.8.5... yes Invalid drive specification. Unable to get ImageMagick version
* 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.
I tried downloading ImageMagick, and set environment paths as:
CPATH=D:\ImageMagick-6.9.5-Q8\include
LIBRARY_PATH=D:\ImageMagick-6.9.5-Q8\lib
and run bundle install but no use and also tried running
gem install rmagick -v '2.13.4' --platform=ruby -- --with-opt-lib=D:\ImageMagick-6.9.5-Q8\lib --with-opt-include=D:\ImageMagick-6.9.5-Q8\include
it is showing:
Unable to get ImageMagick version
* 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.
Please help.
I had this same issue myself until I finally stumbled upon the answer on Stackoverflow here and here.
Basically you need to follow these steps:
Install DevKit. Since I used RailsInstaller to install Ruby on Rails on my laptop, it was already included in the default directory ‘C:\Serever\RailsInstaller\DevKit‘. Otherwise, find the .exe at the RubyInstallers downloads.
Install ImageMagick-6.9.5-9-Q16-x86-dll.exe from imagemagick.org. It seems that rmagik2.16 only supports ImageMagick 6, not ImageMagick 7.
Make sure that you install the correct version of ImageMagick x86 or x32. If you are unsure what ruby version you have install try this command: ruby -e "puts 1.size". It print 4 if x86 and 8 if x64. answer from here
Check the following options on the install screen (more info on the redmine website) :
[v] Add application directory to your system path
[v] Install development headers and libraries for C and C++
Setup in windows environment variables the PATH variable to include the path to ImageMagick. In my case: C:\Server\ImageMagick\. Make sure it is the first variable in the variables list, or you may encounter an “Invalid drive specification” error when extconf.rb tries to identify the ImageMagick version.
cd C:\YourRubyProject. Example: C:\Server\htdocs\dev-ruby\redmine.
Set CPATH and LIBRARY_PATH environment variables to point respectively to ImageMagick installation directory include and lib subdirectories (so the DevKit will find them at build time)
Open C:\Serever\RailsInstaller\DevKit\msys.bat. More details here
Run gem install rmagick --platform=ruby -- --with-opt-lib=C:/Server/ImageMagick/lib --with-opt-include=C:/Server/ImageMagick/include. Adjust paths as necessary for your project.
Finally, run bundle install, or if necessary bundle update
Note: for those that are looking to install redmine in xampp follow this tutorial. If you get stuck on installing the rmagick lib, return here to this answer and follow the provided steps.

Installing pg gem; ERROR: Failed to build gem native extension

After updating to OS X 10.9 Mavericks I tried to start a Rails 3 app, but the connection to the PG database was not working. Checking on PGAdmin III, the database is still there and it works fine.
So I tried to reinstall the pg gem:
gem uninstall pg
gem install pg
But the last command doesn't succeed, and gives the following error:
Building native extensions. This could take a while... ERROR: Error
installing pg:
ERROR: Failed to build gem native extension.
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/bin/ruby extconf.rb checking for pg_config... yes Using config values from
/usr/local/bin/pg_config
* 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.
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in
`try_do': The compiler failed to generate an executable file.
(RuntimeError) You have to install development tools first. from
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:461:in
try_link0' from
/Users/XXX/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:476:in
try_link' from extconf.rb:39:in `'
I guess the problem is related to the Xcode developer tools. I updated Xcode to the latest version, but that didn't solve the problem. Do you know how to fix it?
You're right that the problem is related to the Xcode developer tools. It's not a bad idea to make sure you have all the developer tools installed (as opposed to solely installing gcc as mentioned in the previous answer):
Open up Xcode
In the application menu item "Xcode" select Open Developer Tool > More Developer Tools...
This takes you to a site with a bunch of software. Go ahead and download and install "Command Line Tools (OS X Mavericks) for Xcode - Late October 2013".
You will now be able to properly install the gem.
For anyone else coming to this issue off of a fresh install of the Postgres 9.3.0 app on Mac OS X Mavericks (i.e. you're not using homebrew for your Postgres installation) you may notice that even though you can build the pg gem you cannot run rake because of a dylib issue:
rake aborted!
dlopen(/Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle, 9): Library not loaded: #loader_path/../lib/libpq.5.dylib
Referenced from: /Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle
Reason: image not found - /Users/[USERNAME]/.rbenv/versions/2.0.0-p195/lib/ruby/gems/2.0.0/gems/pg-0.15.1/lib/pg_ext.bundle
Unfortunately this is a problem with the current release version of 9.3.0 of Postgres. Winding back to a previous version will fix it for you:
uninstall the pg gem: gem uninstall pg
delete your 9.3.0 Postgres app by dragging it to the trash and emptying the trash
install version 9.2.2.0 of the Postgres app here: http://postgres-app.s3.amazonaws.com/PostgresApp-9-2-2-0.zip
reinstall the pg gem: gem install pg
*Thanks to the comment by jhiro009 on this thread for pointing me in the right direction on this last Postgres app part of the issue although the 9.2.4.3 version that he mentioned didn't work for me.
Using homebrew fixed this for me:
gem uninstall pg
brew install apple-gcc42
gem install pg
EDIT: I also manually installed "devtools"
xcode-select --install
On OS X Mavericks
sudo ln -s /usr/bin/llvm-gcc /usr/bin/gcc-4.2
gem uninstall pg; gem install pg;
works with homebrew Postgresql (9.3.1) installation and Apple Command Line Tools installed (pg 0.17.0).
None of the previous solutions worked for me (I just upgraded to Mavericks and updated XCode). Instead, I installed Postgress.app. and called
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
None of the solutions worked for me, and I didn't want to use MacPorts. Try and download the Postgres App and put it into the Application directory.
Then, specify the location of newly downloaded pg_config, which resides inside the app:
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/MacOS/bin/pg_config
If you run in to missing headers problem, try specifying the include directory of the app:
gem install pg -- --with-pg-include='/Applications/Postgres.app/Contents/MacOS/include/'
If you are looking for just a quick fix, add the following to your database.yml file:
host: localhost
I had the exact problem, added that line, and now all is well.
I had luck following this post from the guys at New-Bamboo:
3 Quick Tips for Coding with OS X 10.9 Mavericks
After installing the xcode dev tools, the third step sorted everything out:
brew tap homebrew/versions && brew install apple-gcc42
brew link --force apple-gcc42
ln -nsf $(which gcc-4.2) /usr/bin/gcc-4.2
I had this problem the first time I tried to install pg. Through various trials and errors I found something that worked. Thankfully, my notes also worked when Mavericks broke everything.
Hope this helps:
Do not do any brewing.
download the enterpriseDB one-click installer, mount and run.
If it doesn't work, run it through the command line (unattended mode) and it will change the memory settings. Restart, run again.
Makes a user called postgres with the password you supply. Also installs pgadmin III.
run this in app directory:
env ARCHFLAGS="-arch x86_64" gem install pg -- --with-pg-include=/Library/PostgreSQL/9.2/include/ --with-pg-lib=/Library/PostgreSQL/9.2 sudo env ARCHFLAGS='-arch i386' gem install pg/lib/
Open pgadmin3 and create a user and password for rails, then add it to config.
psql [database_name] # to check on your db. Or use pgadmin III

pg gem install fails saying version is too old?

I am trying to install the pg (PostreSQL) gem for Ruby. I am receiving this error:
postgres/9.2-pgdg/bin/64/pg_config
Using config values from /location/to/install/postgres/9.2-pgdg/bin/64/pg_config
checking for libpq-fe.h... yes
checking for libpq/libpq-fs.h... yes
checking for pg_config_manual.h... yes
checking for PQconnectdb() in -lpq... yes
checking for PQconnectionUsedPassword()... no
Your PostgreSQL is too old. Either install an older version of this gem or upgrade your database.
*** 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.
PostgreSQL version: postgres (PostgreSQL) 9.2.3
OS: solaris 10
I have also tried:
gem install pg -- --with-pgsql-lib=/location/of/install/postgres/9.2-pgdg/lib/64/ --with-pg-config=/location/of/install/postgres/9.2-pgdg/bin/64/pg_config
I have no idea why this error is occurring and I cannot find any useful info on Google.
Any help is greatly appreciated.
Lots of things can go wrong installing a database client, the gem and using it.
I generally install PostgreSQL from source, not from a distro. At that point I know I have all the source and know exactly where things got installed. That's important when installing the gem that talks to the client drivers.
I also rely on installing Ruby from source, either by directly installing it myself, or by using rbenv or RVM if it's on one of my development boxes. Then I also install the pg gem directly, using gem install pg; I've had too many bad experiences using distros when installing languages so I go old-school on it.
I wrote a little script I use on my Mac OS systems, that I've found useful for my CentOS Linux boxes:
#!/bin/sh -x
PATH=/Library/PostgreSQL/9.2/bin:$PATH
gem install pg
I adjust the PATH addition depending on where PostgreSQL got installed, and it seems to do the trick. I've used the longer, more "comprehensive" options also, but this seems to work as well.
The issue is that the installer needs to dig out installation information from the pg_config executable and being able to find pg_config does the trick.
I was going nuts with this until I realized that postgresql-devel and postgresql-libs were from 8.1.23!!!
$ yum list installed postgres*
Loaded plugins: fastestmirror, security
Installed Packages
postgresql-devel.i386 8.1.23-10.el5_10 installed
postgresql-devel.x86_64 8.1.23-10.el5_10 installed
postgresql-libs.i386 8.1.23-10.el5_10 installed
postgresql-libs.x86_64 8.1.23-10.el5_10 installed
---------------
$ sudo yum install postgresql94-libs
$ sudo yum install postgresql94-devel
$ gem install pg
Successfully installed pg-0.18.1
Installing and linking postgresql from homebrew fixed it for me:
brew install postgresql
brew unlink postgresql91
brew link --overwrite postgresql

Rubygems do not install on OS X Lion

I used to have no problems at all with ruby, gems and all related stuff. But after installing X Code Developer Tools and upgrading to Lion the gems do not install.
I get the following error for every gem. This is the message for sqlite as an example:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3:
ERROR: Failed to build gem native extension.
/System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb
mkmf.rb can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-1.3.4 for inspection.
Results logged to /Library/Ruby/Gems/1.8/gems/sqlite3-1.3.4/ext/sqlite3/gem_make.out
What went wrong? How to fix it?
I had to install the Command Line Tools in the latest Xcode-Version (4.3.1) and
sudo gem install rails
worked like a charm.
To install Command Line Tools, go to Xcode Preferences > Downloads or use the following command in terminal (thx #Purell):
xcode-select --install
I'm using Mavericks and Ruby 2.0.0 and I also got this error (mkmf.rb can't find header files) when installing gems. I solved this issue by creating some symbolic links in Terminal.
#First install developer tools again:
xcode-select --install
#Create symbolic link to Ruby include (updated for 10.9)
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0 /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/lib/ruby/include
#Create symbolic link to config.h (updated for 10.9)
sudo ln -s /System/Library/Frameworks/Ruby.framework/Versions/2.0/Headers/ruby/config.h /System/Library/Frameworks/Ruby.framework/Versions/2.0/usr/include/ruby-2.0.0/ruby/config.h
I faced same problem while trying to install rails on my Lion. This is how i could solve it.
Install rvm
$ curl https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer | bash -s stable
Install osx-gcc-installer
https://github.com/kennethreitz/osx-gcc-installer
Installed new version of ruby
rvm install 1.9.3
Typed to following command to show the requirements
rvm requirements
To use an RVM installed Ruby as default, instead of the system ruby:
rvm system ; rvm gemset export system.gems ; rvm 1.9.3 ; rvm gemset import system.gems # migrate your gems
rvm alias create default 1.9.3
Installed rails:
sudo gem install rails
My Mac is now read for rails!! YAY!!
Not a direct solution to your problem, but I'd suggest using rvm to install fresh rubies and gems. That should take care of it.
While installing Rails I had the error :
can't find header files for ruby at /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/lib/ruby/ruby.h
As i had already Xcode installed, I had just to install Command Line Tools to resolve this problem
You need to have XCode installed, it includes ruby.h as well as some other important files needed to compile other native gems.
Hello i'm sorry i can't test this answer but i would suggest to change the default search paths in your bashrc and extconf.rb since the Library files seem to be moved in Lion.
(P.S. if he wants to work with the default 1.8 Version, rvm would be an unneeded hassle)
Update to the latest version of xcode, that fixed the problem for me. Make sure xcodebuild is in your path.
running xcodebuild -version in a terminal window should output 4.2.1 (4.x at least).
After a OS-Update make sure that you do accept the X-Code license even when you have used command-line-tools before. Only then some header-files will be available. To accept the license you have to run X-Code once.
I just forgot to run it with the sudo command.
sudo gem install sqlite3
not:
gem install sqlite3

Snow Leopard upgrade -> reinstalling sqlite3-ruby gem problem

I got ruby 1.8.7 (native compiled), rails 2.3.4, OSX 10.6.2 and also sqlite3-ruby.
The error I'm getting when accessing the rails app is
NameError: uninitialized constant SQLite3::Driver::Native::Driver::API
History:
I upgraded to snow leopard by migrating my apps with a FW-cable from my old macbook to the new one. Everything was running perfectly for months, but Yesterday I needed to install watir, which was dependant on rb-appscript, which didn't build due a "wrong architecture" error in libsqlite3.dylib. I figured the build was made on the old machine, so i wanted to rebuild sqlite3-ruby:
$ sudo gem uninstall sqlite3-ruby
$ sudo gem install sqlite3-ruby
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/usr/local/bin/ruby extconf.rb
checking for fdatasync() in -lrt... no
checking for sqlite3.h... yes
checking for sqlite3_open() in -lsqlite3... no
* 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.
It seems like the sqlite3 libs are not working properly. I've tried to install macports sqlite3 (sudo port install sqlite3) and use that instead, but with same result... so i rebuild sqlite3 from scratch.. download->configure->make->make install. After that, the gem now builds perfectly, but doesn't work in rails, giving the error in the top of this article.
I'm not really sure where to go from here because I've tried the following
Rebuild sqlite3 from newest source (http://www.sqlite.org/download.html)
Reinstalled sqlite3-ruby (sudo gem uninstall sqlite3-ruby && sudo gem install sqlite3-ruby)
Used sqlite3 from macports (sudo port install sqlite3 && sudo gem install sqlite3-ruby)
Reinstalled rails (sudo gem install rails sqlite3-ruby ) and updated environment.rb to rails 2.3.5.
No avail, I still get this error:
NameError: uninitialized constant SQLite3::Driver::Native::Driver::AP
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:105:in const_missing'
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/driver/native/driver.rb:76:inopen'
from /usr/local/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.5/lib/sqlite3/database.rb:76:in `initialize'
Btw, I have Xcode installed from the Snow Leopard CD.
What can i do to solve the problem?
My problem was slightly different, and in fact non of the solutions I found on-line worked.
When trying to install sqlite3-ruby after upgrading to Snow Leopard and XCode 4.0 trial, I got the message
checking for sqlite3.h... yes
checking for sqlite3_libversion_number() in -lsqlite3... no
sqlite3 is missing. Try 'port install sqlite3 +universal' or 'yum install sqlite3-devel'
however sqlite3 was installed, and also re-installing did not help. I already had the troub le before with 64-bit and universal versions, but that I had cleared as well.
In fact, I could work with sqlite3.
So gem install should also tell you something along these lines:
Gem files will remain installed in /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 for inspection.
So cd to that directory and there look for extconf.rb, mine was in ./ext/sqlite3/extconf.rb
I found that ruby was checking for the the sqlite3 library using
asplode('sqlite3') unless find_library 'sqlite3', 'sqlite3_libversion_number'
So I fired up irb and checked why this didn't work:
require 'mkmf'
find_library 'sqlite3', 'sqlite3_libversion_number'
Well, in fact this works and my ruby find the library.
So why doesn't it work from the setup?
Inspecting extconf.rb closely showed the following line:
sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
When I execute this in irb:
require 'mkmf'
sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
find_library 'sqlite3', 'sqlite3_libversion_number'
I will surprisingly not find the library anymore. In fact I do not understand how this can be, but that's what happens.
So this is the cure:
comment out the line
sqlite = dir_config('sqlite3', ['/usr/local', '/opt/local', '/usr'])
in extconf.rb
Then from /Library/Ruby/Gems/1.8/gems/sqlite3-ruby-1.3.1 I issued
sudo ruby ./setup.rb
This went through with no problems (I tried before commenting out the sqlite= line, and it did not work)
Restarted the ruby application that had the problems with sqlite.
Works fine.
Hope this will help someone.
Icecream
Thanks for the answers. Here is what i did to solve the problem:
Complete reinstall of ruby1.8.7 to /usr/local, see here: http://hivelogic.com/articles/ruby-rails-leopard
Note: readline wasn't working when recompiling ruby on my mac, so i had to build that too from scratch and make sure to add the --with-readline-dir option to configure:
./configure --enable-shared --enable-pthread CFLAGS=-D_XOPEN_SOURCE=1 --prefix=/usr/local --with-readline-dir=/usr/local
Complete reinstall of sqlite3 to /usr/local
Rebuild all gems on the system with sudo gem install XXX, including sqlite3-ruby. This is only necessary with platform specific gems, but i found it to be faster just to install everything in a oneliner:
sudo gem install gem1 gem2 ... gemN --no-ri --no-rdoc
I tried to go with ruby1.9 but everything stopped working due to broken dependencies in gems and plugins, so I wouldn't recommend switching to 1.9 unless you are up for some heavy debugging and know how to restore your old system!
Finally everything is running again!
I found some guidance on this at Don Park's blog at:
http://blog.docuverse.com/2009/09/24/installing-sqlite3-ruby-gem-on-snow-leopard/
His solution points right back to Stack Overflow at the following thread:
Snow Leopard, sqlite3-ruby
The answer about the ln command seems to have solved my problem. Hope it helps you too.
If the gem isn't building it's not because you need necessarily to rebuild sqlite3 from source, but to build the gem you will require the sqlite3 developer libraries.
On most Linux/Unix systems you can install them by doing 'sudo apt-get install sqlite3-dev', however I'm not sure how it works with Macports - but make sure you have that package. You have to make sure they're in your path or pass the dir they're in when you install the gem (see the gem's output for hints as to the options for doing that).
I have sqlite3 running on my Mac just fine, both with 1.8.7 and now my updated 1.9.1 Ruby. You might want to make sure you have the XCode Developer Tools installed as well.
For those on Snow Leopard 64 and having this issue installing this macport fixed the issue for me.
sudo port install rb-sqlite3 +universal

Resources