Fix this error on my Ruby install - ruby-on-rails

I'm new to Ruby and trying to get it to run, but when I do I get this message:
Could not find gem 'sqlite3 (>= 0)' in any of the gem sources listed
in your Gemfile. Run bundle install to install missing gems.
after I run "bundle install" on the terminal (using a Mac) I get the following:
Installing sqlite3 (1.3.4) with native extensions
/Library/Ruby/Site/1.8/rubygems/installer.rb:551:in
`build_extensions': ERROR: Failed to build gem native extension.
(Gem::Installer::ExtensionBuildError)
/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
How can I fix this? I've been Googling for a while but haven't been able to figure it out, and I need this to successfully run "rails server" to see my app on the browser =/

From here:
Can't find header files for ruby
If you get the can't find header files for ruby error message when
trying to build an extension or a gem, it means that Ruby cannot
locate its header files.
Header files are not delivered by default with Mac OS X, you need to
install the Xcode Tools package after the installation. You can find
it in the Optional Installs / Xcode Tools directory on the Leopard
DVD.
That's it, the system doesn't have the Ruby header files. To install them, you need to install the Xcode Tools package.

Related

Ruby on rails.. rails server command, strange output? [duplicate]

I'm running a clean install of Ruby 2.2.1 on Windows 8.1 with DevKit. After the installation I run:
gem install rails
rails new testapp
cd testapp
rails server
leaving everything else at default.
The process fails at the last line when, instead of running the server, I get the error message
in 'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError)
It happens every time and I've looked around and tried everything I found to fix it, but nothing so far has worked.
What is the problem here and how do I get a simple test Rails app to work?
Nokogiri doesn't support Ruby 2.2 on Windows yet. The next release will. See https://github.com/sparklemotion/nokogiri/issues/1256
Nokogiri doesn't support native builds (e.g. with devkit) on Windows. Instead it provides gems containing prebuilt DLLs.
There's a discussion which you may want to join or watch on the topic of devkit build support here: https://github.com/sparklemotion/nokogiri/issues/1190
First, uninstall the version of Nokogiri you currently have with:
gem uninstall nokogiri
Download Nokogiri 1.6.6.2 (x64) or Nokogiri 1.6.6.2 (x86)
Install this version locally using:
gem install --local C:\Users\$user$\Downloads\nokogiri-1.6.6.2-x64-mingw32.gem
or if you're running 32bit Ruby:
gem install --local C:\Users\$user$\Downloads\nokogiri-1.6.6.2-x86-mingw32.gem
The path may differ depending on where you downloaded the file to.
Try to start the server again using ruby bin\rails server, and it should work.
I got Nokogiri running with Ruby 2.2 on Windows 10 with a mix of Mike Dalessios and Julios answer:
Look for the latest version of Nokogiri in Nokogiri's github repo.
Run gem uninstall nokogiri.
Add gem "nokogiri", ">= 1.6.7.rc" to your Gemfile.
Run bundle install.
Run bundle update nokogiri if bundle has locked Nokogiri at some version.
Fix
Bundle install (gets Nokogiri files)
Browse to ruby_dir\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2\ext\nokogiri
Open extconf.rb
Add dir_config('iconv').any? or pkg_config('libiconv') to #376
Download MinGW64 & MSYS folders from Mega
Add them to PATH in Windows (remove Devkit path refs - it doesn't work)
Download libxml2,libxslt, iconv libraries (or here)
Run ruby extconf.rb --platform=ruby --n --use-system-libraries referencing downloaded libraries
Run make
Run make install
Steps
Bundle Install
First step is to bundle.
This will put the nokogiri gem on your machine without running the pre-packaged compiler (which mostly doesn't work in Windows).
This will show Nokogiri as installed:
Browse
Browse to the nokogiri folder, to find ext/nokogiri/extconf.rb:
Open extconf.rb
... and add dir_config('iconv').any? or pkg_config('libiconv') to #376
Standard Nokogiri installs "rely" on the libxml2 inclusion of iconv - we need to explicitly define it, otherwise iconv.h is missing errors will occur.
Add Toolchain
Don't use devkit for this - it doesn't work.
You need MinGW:
I have zipped my exact MinGW64 and MSYS64 folders on Mega (key: !FJtcq25l-QMsNltCxllMhc1IGqORvap8xv8gWxSUbDA):
Add to PATH
This gives access to gcc & make (both required):
Remove the devkit ref from your path, and add the following:
MINGW64_PATH/bin
MSYS64_PATH/bin
Download Libs
I have added the libs to Mega:
You will unzip them here:
All the libs are from this source.
Run extconf.rb
Once libs are on your system, you can run ruby extconf.rb to configure the build:
32bit
ruby extconf.rb --platform=ruby -N -- --use-system-libraries --with-xml2-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxml2-2.9.2-win32-x86 --with-xml2-include=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxml2-2.9.2-win32-x86/include/libxml2 --with-iconv-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/iconv-1.14-win32-x86 --with-xslt-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxslt-1.1.28-win32-x86
64bit
#64
ruby extconf.rb --platform=ruby -N -- --use-system-libraries --with-xml2-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxml2-2.9.2-win32-x86_64 --with-xml2-include=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxml2-2.9.2-win32-x86_64/include/libxml2 --with-iconv-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/iconv-1.14-win32-x86_64 --with-xslt-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxslt-1.1.28-win32-x86_64
make
This may create errors / warnings, as long as it says "Error 1 (ignored)", it should be okay.
Following that, use make install:
Then browse to your Rails installation and run rails s:
Explanation
To give context:
Ruby 2.2+ on Windows doesn't compile the extensions Nokogiri requires.
The extensions of a gem are the extra dependencies (libraries) it uses.
They are built when you install the gem:
Extensions
Lack of extensions is preventing Nokogiri from running.
Extensions exist in the ext folder of a gem (you can read about them here):
Mysql2,RMagick,PGSQL, Nokogiri etc all use extensions/libraries.
This is why - on Windows - you have to use custom switches (--with-opt-dir) when installing the gem. This gives Ruby / the shell / (cmd) the required lib / include directories required to build the gem's files (it's the equivalent of how PATH works).
On Linux/Mac, these directories are managed with the respective package managers (brew/apt-get). Windows does not have this, so you have to install the extensions manually.
Because Windows does not have a standard set of libraries, you have to download them yourself. You also have to build them yourself (which is tricky).
The fix for Nokogiri install is to use the right libraries and build tools to get the gem installed.
Build
The difference with Ruby 2.2+ is the gem will "install" without showing any exceptions. You think it has installed, only to find Rails does not load (hence the nokogiri/nokogiri.so error).
This means you have to make sure you have the files on your system, and run the compiler to install them.
The above documentation should show you how to do that.

'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError) when running `rails server`

I'm running a clean install of Ruby 2.2.1 on Windows 8.1 with DevKit. After the installation I run:
gem install rails
rails new testapp
cd testapp
rails server
leaving everything else at default.
The process fails at the last line when, instead of running the server, I get the error message
in 'require': cannot load such file -- 'nokogiri\nokogiri' (LoadError)
It happens every time and I've looked around and tried everything I found to fix it, but nothing so far has worked.
What is the problem here and how do I get a simple test Rails app to work?
Nokogiri doesn't support Ruby 2.2 on Windows yet. The next release will. See https://github.com/sparklemotion/nokogiri/issues/1256
Nokogiri doesn't support native builds (e.g. with devkit) on Windows. Instead it provides gems containing prebuilt DLLs.
There's a discussion which you may want to join or watch on the topic of devkit build support here: https://github.com/sparklemotion/nokogiri/issues/1190
First, uninstall the version of Nokogiri you currently have with:
gem uninstall nokogiri
Download Nokogiri 1.6.6.2 (x64) or Nokogiri 1.6.6.2 (x86)
Install this version locally using:
gem install --local C:\Users\$user$\Downloads\nokogiri-1.6.6.2-x64-mingw32.gem
or if you're running 32bit Ruby:
gem install --local C:\Users\$user$\Downloads\nokogiri-1.6.6.2-x86-mingw32.gem
The path may differ depending on where you downloaded the file to.
Try to start the server again using ruby bin\rails server, and it should work.
I got Nokogiri running with Ruby 2.2 on Windows 10 with a mix of Mike Dalessios and Julios answer:
Look for the latest version of Nokogiri in Nokogiri's github repo.
Run gem uninstall nokogiri.
Add gem "nokogiri", ">= 1.6.7.rc" to your Gemfile.
Run bundle install.
Run bundle update nokogiri if bundle has locked Nokogiri at some version.
Fix
Bundle install (gets Nokogiri files)
Browse to ruby_dir\lib\ruby\gems\2.2.0\gems\nokogiri-1.6.6.2\ext\nokogiri
Open extconf.rb
Add dir_config('iconv').any? or pkg_config('libiconv') to #376
Download MinGW64 & MSYS folders from Mega
Add them to PATH in Windows (remove Devkit path refs - it doesn't work)
Download libxml2,libxslt, iconv libraries (or here)
Run ruby extconf.rb --platform=ruby --n --use-system-libraries referencing downloaded libraries
Run make
Run make install
Steps
Bundle Install
First step is to bundle.
This will put the nokogiri gem on your machine without running the pre-packaged compiler (which mostly doesn't work in Windows).
This will show Nokogiri as installed:
Browse
Browse to the nokogiri folder, to find ext/nokogiri/extconf.rb:
Open extconf.rb
... and add dir_config('iconv').any? or pkg_config('libiconv') to #376
Standard Nokogiri installs "rely" on the libxml2 inclusion of iconv - we need to explicitly define it, otherwise iconv.h is missing errors will occur.
Add Toolchain
Don't use devkit for this - it doesn't work.
You need MinGW:
I have zipped my exact MinGW64 and MSYS64 folders on Mega (key: !FJtcq25l-QMsNltCxllMhc1IGqORvap8xv8gWxSUbDA):
Add to PATH
This gives access to gcc & make (both required):
Remove the devkit ref from your path, and add the following:
MINGW64_PATH/bin
MSYS64_PATH/bin
Download Libs
I have added the libs to Mega:
You will unzip them here:
All the libs are from this source.
Run extconf.rb
Once libs are on your system, you can run ruby extconf.rb to configure the build:
32bit
ruby extconf.rb --platform=ruby -N -- --use-system-libraries --with-xml2-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxml2-2.9.2-win32-x86 --with-xml2-include=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxml2-2.9.2-win32-x86/include/libxml2 --with-iconv-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/iconv-1.14-win32-x86 --with-xslt-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/32bit/libxslt-1.1.28-win32-x86
64bit
#64
ruby extconf.rb --platform=ruby -N -- --use-system-libraries --with-xml2-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxml2-2.9.2-win32-x86_64 --with-xml2-include=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxml2-2.9.2-win32-x86_64/include/libxml2 --with-iconv-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/iconv-1.14-win32-x86_64 --with-xslt-dir=C:/Dev/Dependencies/Ruby/lib/nokogiri/64bit/libxslt-1.1.28-win32-x86_64
make
This may create errors / warnings, as long as it says "Error 1 (ignored)", it should be okay.
Following that, use make install:
Then browse to your Rails installation and run rails s:
Explanation
To give context:
Ruby 2.2+ on Windows doesn't compile the extensions Nokogiri requires.
The extensions of a gem are the extra dependencies (libraries) it uses.
They are built when you install the gem:
Extensions
Lack of extensions is preventing Nokogiri from running.
Extensions exist in the ext folder of a gem (you can read about them here):
Mysql2,RMagick,PGSQL, Nokogiri etc all use extensions/libraries.
This is why - on Windows - you have to use custom switches (--with-opt-dir) when installing the gem. This gives Ruby / the shell / (cmd) the required lib / include directories required to build the gem's files (it's the equivalent of how PATH works).
On Linux/Mac, these directories are managed with the respective package managers (brew/apt-get). Windows does not have this, so you have to install the extensions manually.
Because Windows does not have a standard set of libraries, you have to download them yourself. You also have to build them yourself (which is tricky).
The fix for Nokogiri install is to use the right libraries and build tools to get the gem installed.
Build
The difference with Ruby 2.2+ is the gem will "install" without showing any exceptions. You think it has installed, only to find Rails does not load (hence the nokogiri/nokogiri.so error).
This means you have to make sure you have the files on your system, and run the compiler to install them.
The above documentation should show you how to do that.

RubyGems, can't install JSON

I got way too many problems setting up a ruby development enviornment on my windows.
I already installed Ruby 1.9.3, DevKit for Ruby 1.9.3, RubyGems and Ruby on Rails. (Also the client for Heroku and Git, but I don't think these tools do matter for a solution.)
I now have several problems:
-> bundle update doesn't do what it should do, it always cancels because JSON isn't installed
-> same goes for bundle install, it cancels because JSON is missing
-> can't use rails server because of the missing JSON
-> if I try to use gem install json I'm getting the following error:
D:\Bibliotheken\Dokumente\RailsProjects\first_app>gem install json
Temporarily enhancing PATH to include DevKit...
Building native extensions. This could take a while...
ERROR: Error installing json:
ERROR: Failed to build gem native extension.
"D:/Program Files (x86)/Ruby 1.9.3/bin/ruby.exe" extconf.rb
D:/Program Files (x86)/Ruby 1.9.3/bin/ruby.exe: invalid switch in RUBYOPT: -F (RuntimeError)
Gems will remain installed in D:/Program Files (x86)/Ruby 1.9.3/lib/ruby/gems/1.9.1/gems/json-1.8.1 for inspection.
Results logged to D:/Program Files (x86)/Ruby 1.9.3/lib/ruby/gems/1.9.1/gems/json-1.8.1/ext/json/ext/generator/gem_make.out
-> after this try I can't call rails -v anymore, it's putting an error to the console aswell
<[31mCould not find gem 'sdoc <= 0.3.20) x86-mingw32' in the gems available on this machine.<[0m
<[31mRun 'bundle install' to install missing gems.<[0m
And there is the joke, how can I use "bundle install" if it's not working? :(
Every help is appreciated, I'm a bloody beginner in setting up development enviorments. If you need any additional information, I will provide them as soon as I can get them!
Edit:
Content of gem_make.out:
"D:/Program Files (x86)/Ruby 1.9.3/bin/ruby.exe" extconf.rb
D:/Program Files (x86)/Ruby 1.9.3/bin/ruby.exe: invalid switch in RUBYOPT: -F (RuntimeError)
I installed Ruby 1.9.3 manually using the Rubyinstaller because the Railsinstaller didn't work for me (it nearly put the same error if I wanted to get JSON!). Then I did an update to install DevKit, and used gem install rails to get rails.
Zerotime
Note: English isn't my native language, don't feel bothered by mistakes :)

Failed to build native gem extension sqlite3

I'm trying to install sqlite3-ruby on Cygwin with gem install sqlite3-ruby -v x.x.x and I get the following error:
Building native extensions. This could take a while...
ERROR: Error installing sqlite3-ruby:
ERROR: Failed to build gem native extension.
/usr/bin/ruby.exe extconf.rb
checking for fdatasync() in -lrt... *** 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.
Does anyone know how to install sqlite3 for Ruby on Rails on Cygwin. As I understand it the SQLite RubyGem isn't actually a *Ruby*Gem, it's a "*C*Gem", IOW it's written in C. This means it has to be compiled and linked to the Ruby interpreter when you install it, so any help?
So this isn't a complete solution as I don't have a windows box and cygwin handy but the error message suggests that the linux utility fdatasync can't be found.
The tools linux man page can be found here
http://linux.die.net/man/2/fdatasync
Maybe find out if you have fdatasync installed correctly and try again.
I ran into this issue just now – the first time I wanted to install a Ruby gem
on my new Cygwin 64-bit system.
As I understand it the SQLite RubyGem isn't actually a RubyGem, it's a
"CGem", IOW it's written in C. This means it has to be compiled and linked
to the Ruby interpreter when you install it.
Cygwin actually provide a pre-compiled package which installs the sqlite3
gem files including the sqlite3_native.so linked library file. The name of
the package is ruby-sqlite3 and you can install it using Cygwin’s Setup.exe.
I personally like to use apt-cyg
when possible (not always) so I installed the package using:
apt-cyg install ruby-sqlite3
This package installs the appropriate gem files as can be seen by running
cygcheck -l ruby-sqlite3:
/usr/lib/gems/ruby/2.0.0/sqlite3-1.3.9/gem.build_complete
/usr/lib/gems/ruby/2.0.0/sqlite3-1.3.9/sqlite3/sqlite3_native.so
/usr/share/gems/gems/sqlite3-1.3.9/API_CHANGES.rdoc
/usr/share/gems/gems/sqlite3-1.3.9/ChangeLog.cvs
/usr/share/gems/gems/sqlite3-1.3.9/CHANGELOG.rdoc
/usr/share/gems/gems/sqlite3-1.3.9/faq/faq.rb
/usr/share/gems/gems/sqlite3-1.3.9/faq/faq.yml
/usr/share/gems/gems/sqlite3-1.3.9/Gemfile
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/constants.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/database.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/errors.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/pragmas.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/resultset.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/statement.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/translator.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/value.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3/version.rb
/usr/share/gems/gems/sqlite3-1.3.9/lib/sqlite3.rb
/usr/share/gems/gems/sqlite3-1.3.9/LICENSE
/usr/share/gems/gems/sqlite3-1.3.9/Manifest.txt
/usr/share/gems/gems/sqlite3-1.3.9/README.rdoc
/usr/share/gems/gems/sqlite3-1.3.9/tasks/faq.rake
/usr/share/gems/gems/sqlite3-1.3.9/tasks/gem.rake
/usr/share/gems/gems/sqlite3-1.3.9/tasks/native.rake
/usr/share/gems/gems/sqlite3-1.3.9/tasks/vendor_sqlite3

Installe RMagick gem locally but unable to do the same using bundle install [windows 7(32 bit)]

I was able to install the rmagick-2.6.0-x86-mswin32.gem gem in my windows 7 machine using gem install command and I got the following success messages:
D:\dev>gem install rmagick-2.6.0
Successfully installed rmagick-2.6.0-x86-mswin32
1 gem installed
Installing ri documentation for rmagick-2.6.0-x86-mswin32...
Installing RDoc documentation for rmagick-2.6.0-x86-mswin32...
But when I try to install using bundle install (with the same version mentioned in the Gemfile) it throws the following error messages:
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension
. D:/Ruby187/bin/ruby.exe extconf.rb
checking for Ruby version >= 1.8.2... yes
checking for gcc... yes
checking for Magick-config... no
Can't install RMagick 2.6.0. Can't find Magick-config in D:\Ruby187\bin;D:\Ruby1
....
I already have ImageMagick installed and its paths included in the env vars, but the paths mentioned in the error message above seem to be different somehow(?!)
When i type rails -v now, I get the following message:
D:\dev>rails -v
←[31mCould not find gem 'rmagick (= 2.6.0) x86-mingw32' in the gems available on
this machine.←[0m
←[33mRun `bundle install` to install missing gems.←[0m
Do i need to make any other changes/ setups to install this gem with my gemfile using bundle install?
Also I actually need an earlier gem '2.5.2' but the win32 specific version of that gem does not seem to available, is there any way to get it?
I need to do this development on windows for the moment so I can switch to any other OS for the moment. Also since this is a legacy app I am working on, I will need to stick with rmagick and can't switch to any other solution.
Env info:
Ruby: 1.8.7
Rails:
Please help!
Many thanks.
Hey have you tried installing Devkit, for installing gems with native extensions on windows.
Try the steps in the following link, and check whether the Devkit has been installed in your path variable, try opening a new command shell and install the gems.
http://doelsengupta.blogspot.in/2010/10/unable-to-download-gem-with-native.html
all the best!!
I kept having this problem but was finally able to get around it using the following solution from #Martin Cohen - after modifying the gemspec file as he has suggested and rebuilding it, i was able to successfully install rmagick gem using bundle install...
https://stackoverflow.com/a/5595274/1865578
cheers!

Resources