Problems installing Nokogiri - ruby-on-rails

I'm following this tutorial and I've come to where I need to install these gems:
gem 'rails', '3.0.3'
gem 'sqlite3-ruby', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.1'
end
group :test do
gem 'rspec', '2.0.1'
gem 'webrat', '0.7.1'
end
Then I do a:
bundle install
But terminal gives me this:
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.3)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.3)
Using erubis (2.6.6)
Using rack (1.2.2)
Using rack-mount (0.6.14)
Using rack-test (0.5.7)
Using tzinfo (0.3.26)
Using actionpack (3.0.3)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.16)
Using actionmailer (3.0.3)
Using arel (2.0.9)
Using activerecord (3.0.3)
Using activeresource (3.0.3)
Using bundler (1.0.12)
Using diff-lcs (1.1.2)
Installing nokogiri (1.4.4) /Library/Ruby/Site/1.8/rubygems/installer.rb:574:in `initialize': Permission denied - /Library/Ruby/Gems/1.8/gems/nokogiri-1.4.4/.autotest (Errno::EACCES)
from /Library/Ruby/Site/1.8/rubygems/installer.rb:574:in `open'
I've done a bunch of research on this and I've found some people who had the same problems:
http://taleswithrails.com/2011/01/error-gemfile-could-not-find-gem-webrat/
And I've read the installation guide: http://nokogiri.org/tutorials/installing_nokogiri.html
But I can't get:
sudo port ...
or
sudo apt-get ...
To work. They return with "command not found". So I think I have two issues here...
1) Nokogiri is not installing properly and I'm not sure why. I also don't know what "flavor" of machine I'm running (in other words, which of the Nokogiri installation instructions pertains to my setup).
2) Those commands don't work on my system (OSX 10.6) and I'm not sure why. I've read up on Macports and libxml2 but it's a little unclear to me what it is and what I need to do (or if it's even applicable to me). I did try installing macports, but I don't have Xcode, which is required. But I'm not a "mac developer". Is this my only option?

So it seems like you have several different problems going on at the same time and you need to sort them out one by one.
First, can you run gem install Nokogiri in your terminal, and then try using it in IRB to check that it works?
Then, you should that sudo apt-get is the command for getting software using aptitude which you will NOT be using on your mac, it is used for Linux. and sudo port uses macports to install nokogiri, which will only work if you have Macports installed.
I would recommend getting Homebrew and using brew install nokogiri
once you have it working locally in a ruby script, then worry about rails.
The permission denied error is probably because you have been using some sudo's where you should not be, on a mac you really should never be using that command. If you need to install ruby gems, look into RVM which will let you install 'most' gems without needing to sudo

Related

AWS Elastic Beanstalk Rails Bundler Failing

I'm using the eb CLI to install my rails app on AWS. I've gotten a test one to work before, but now I'm trying to deploy some actual code that I wrote. When I do git aws.push, the update fails. "eb logs" command shows that the bundler failed.
I am running this on 64bit Amazon Linux 2014.03 v1.0.0 running Ruby 2.1 (Puma)
Fetching source index from https://rubygems.org/
Using rake (10.3.2)
Using i18n (0.6.11)
Using minitest (4.7.5)
Using multi_json (1.10.1)
Using thread_safe (0.3.4)
Using tzinfo (0.3.41)
Using activesupport (4.0.8)
Using builder (3.1.4)
Using erubis (2.7.0)
Using rack (1.5.2)
Using rack-test (0.6.2)
Using actionpack (4.0.8)
Using mime-types (1.25.1)
Using polyglot (0.3.5)
Using treetop (1.4.15)
Using mail (2.5.4)
Using actionmailer (4.0.8)
Using activemodel (4.0.8)
Using active_model_serializers (0.9.0)
Using activerecord-deprecated_finders (1.0.3)
Using arel (4.0.2)
Using activerecord (4.0.8)
Using addressable (2.3.6)
Using execjs (2.2.1)
Using autoprefixer-rails (3.0.1.20140826)
Installing bcrypt (3.1.7)
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/opt/rubies/ruby-2.1.2/bin/ruby extconf.rb
Cannot allocate memory - /opt/rubies/ruby-2.1.2/bin/ruby extconf.rb 2>&1
Gem files will remain installed in /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/gems/bcrypt-3.1.7 for inspection.
Results logged to /opt/rubies/ruby-2.1.2/lib/ruby/gems/2.1.0/extensions/x86_64-linux/2.1.0-static/bcrypt-3.1.7/gem_make.out
An error occurred while installing bcrypt (3.1.7), and Bundler cannot continue.
Make sure that `gem install bcrypt -v '3.1.7'` succeeds before bundling.
2014-09-03 00:22:36,561 [ERROR] (3331 MainThread) [directoryHooksExecutor.py-33] [root directoryHooksExecutor error] Script /opt/elasticbeanstalk/hooks/appdeploy/pre/10_bundle_install.sh failed with returncode 5
I'm not calling bcrypt in my gem file either. It must be a dependency of the sorcery gem.
I've attempted to use the "bundle package" for the vendor/cache trick, but it kept saying some gems were missing on AWS. As you can tell, I'm fairly new to not only elastic beanstalk/aws but to rails as well, so I could just be doing something totally wrong.
Also, when I remove bcrypt references (which I'm sure will break something) in the gemfile.lock, it just throws the same error on a different gem later on (ffi). I'm sure there are many gems that it will eventually throw the error on if I just manage to fix the issue one gem at a time.
The error is actually caused by instance running out of memory while running make:
Cannot allocate memory - /opt/rubies/ruby-2.1.2/bin/ruby extconf.rb 2>&1
More than likely you are running a micro instance--bump it up to a larger instance size and it should build reliably.
Rohit is right though in his answer that missing system packages are often a cause of gems failing to install in Elastic Beanstalk.
So there may be some dependencies on C libraries that are required for gem install bcrypt -v '3.1.7'. You can install native dependencies using yum and ebextensions.
You can use ebextensions to install yum packages required for gem install to succeed. Create a file called .ebextensions/01-yum.config in your app source and put the following contents in it.
packages:
yum:
<required-native-dependency>: []
This file is in YAML format so indentation is important.
Read more about pacakges section of ebextensions here:
http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/customize-containers-ec2.html#customize-containers-format-packages

$ bundle install: Failed to build gem native extension

Using Snow leopard, Rails 3.0.3, ruby 1.9.2p0 and RVM. When trying to install bundle I get:
[first_app]$ bundle install
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.3)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.3)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.7)
Using tzinfo (0.3.24)
Using actionpack (3.0.3)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.14)
Using actionmailer (3.0.3)
Using arel (2.0.7)
Using activerecord (3.0.3)
Using activeresource (3.0.3)
Using bundler (1.0.7)
Using thor (0.14.6)
Using railties (3.0.3)
Using rails (3.0.3)
Installing sqlite3 (1.3.3) with native extensions /Users/dawson/.rvm/rubies/ruby-1.9.2-p
0/lib/ruby/1.9.1/rubygems/installer.rb:483:in `rescue in block in build_extensions': ERROR: Failed to build gem native extension. (Gem::Installer::ExtensionBuildError)
/Users/dawson/.rvm/rubies/ruby-1.9.2-p0/bin/ruby extconf.rb
checking for sqlite3.h... *** 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.
You are missing some libraries on your system related to sqlite. This is a common problem with gems that depend on libraries which should be installed on your computer. try installing libsqlite3-dev.
I ran into almost exactly this problem (Snow Leopard, Ruby1.9.2-p0, RVM, Rails 3.1.0rc4, with developer tools installed), and resolved it by upgrading to a newer patch level of Ruby.
Using RVM, you'd write:
rvm upgrade ruby-1.9.2-p180 ruby-1.9.2-p0
(180 is the current patch, but there might be a newer one when you try this. Use the stable release version named here: http://www.ruby-lang.org/en/downloads/)
Try:
gem "sqlite-ruby", "~> 1.3.1"
You may be having issues because you're on Ruby 1.9. This gem is said to work with 1.9:
http://isitruby19.com/sqlite3-ruby
Use 'sudo bundle install' since native extensions try to write in system directories.
sudo -s
export ARCHFLAGS='-arch x86_64'
export PATH=/Library/PostgreSQL/9.1/bin:${PATH}
gem install pg

Error trying to run rails server

I am trying to get a basic Rails application to run on my Mac OS X 10.6.5. I created a new app called demo (rails new demo), then went into the demo directory and tried to start the app with rails server.
Here is the error message I received:
"/Users/dpetrovi/.gem/ruby/1.8/gems/sqlite3-ruby-1.3.2/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
Abort trap"
I checked bundle install in the demo folder:
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.3)
Using builder (2.1.2)
Using i18n (0.5.0)
Using activemodel (3.0.3)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.6)
Using tzinfo (0.3.23)
Using actionpack (3.0.3)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.9)
Using mail (2.2.13)
Using actionmailer (3.0.3)
Using arel (2.0.6)
Using activerecord (3.0.3)
Using activeresource (3.0.3)
Using bundler (1.0.7)
Using thor (0.14.6)
Using railties (3.0.3)
Using rails (3.0.3)
Using sqlite3-ruby (1.3.2)
Your bundle is complete! Use `bundle show [gemname]` to see where a bundled gem is installed.
Ruby, RubyGems, and sqlite3 were installed using MacPorts. Then I used gem to try to install the sqlite3-ruby interface. (sudo gem install sqlite3-ruby). Here is where I first noticed something could be off:
Successfully installed sqlite3-ruby-1.3.2
1 gem installed
Installing ri documentation for sqlite3-ruby-1.3.2...
No definition for libversion
Enclosing class/module 'mSqlite3' for class Statement not known
Installing RDoc documentation for sqlite3-ruby-1.3.2...
No definition for libversion
Enclosing class/module 'mSqlite3' for class Statement not known
I had rails running well on my system a few months ago, so I figured maybe I had some duplicates and it was trying to use the wrong one. I ran: for cmd in ruby irb gem rake; do which $cmd; done and got:
/opt/local/bin/ruby
/opt/local/bin/irb
/opt/local/bin/gem
/opt/local/bin/rake
Checking where sqlite3 also gets me: "/opt/local/bin/sqlite3" so they all seem to be in the right place. Obviously /opt/local/bin is in my system path.
If I check gems server, it shows that I have installed sqlite3-ruby 1.3.2 gem. Not sure what the problem could be?
I am using ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]. Macports claims this is the latest (although ive seen 1.9.1)
One more thing-- in irb, I tried to check which version of sqlite3 my sqlite3-ruby is bound to, but I can only get this far:
:irb(main):001:0> require 'rubygems'
=> true
irb(main):002:0> require 'sqlite3'
/Users/dpetrovi/.gem/ruby/1.8/gems/sqlite3-ruby-1.3.2/lib/sqlite3/sqlite3_native.bundle: [BUG] Segmentation fault
ruby 1.8.7 (2010-12-23 patchlevel 330) [i686-darwin10]
Abort trap
Any suggestions? Im hoping I overlooked something obvious. Thanks
Have you upgraded to Snow Leopard recently? If so, you need to reinstall MacPorts and all the ports installed with it.
I recommend using RVM instead MacPorts installed ruby.
Definitely use RVM as mentioned above and then try this in your app's directory:
rm -rf .bundle && bundle install
i had the same problem. here is how i resolved it.
removed the gem sqlite3-ruby
did bundle install
reinstalled the gem
recreated the rails app
now webrick works fine.

Error Installing rails on Ubuntu 10.04

I am trying to install rails on Ubuntu 10.04. So far, I've executed these commands:
apt-get install build-essential libapache2-mod-passenger apache2 rubygems ruby1.8-dev libopenssl-ruby
gem install fastthread
gem install rails
Fastthread installed easily. However, trying to install rails results in:
ERROR: Error installing rails:
bundler requires RubyGems version >= 1.3.6
So, I tried gem -v which returned 1.3.5.
How do I upgrade rubygems? apt-get won't install above 1.3.5. And gem update --system results in:
ERROR: While executing gem ... (RuntimeError)
gem update --system is disabled on Debian. RubyGems can be updated using the official Debian repositories by aptitude or apt-get.
So right now I simply can't install rails, because I need a newer version of rubygems, and ubuntu won't let me upgrade my current version of rubygems.
As a side note, i tried installed rails via apt-get install rails which seemed to work, but I don't see rails as a gem when i type gem list. What's the deal with that?
Another note: The result of gem list is:
*** LOCAL GEMS ***
abstract (1.0.0)
actionmailer (3.0.1, 3.0.0)
actionpack (3.0.1, 3.0.0)
activemodel (3.0.1, 3.0.0)
activerecord (3.0.1, 3.0.0)
activeresource (3.0.1, 3.0.0)
activesupport (3.0.1, 3.0.0)
arel (2.0.1, 1.0.1)
builder (2.1.2)
erubis (2.6.6)
fastthread (1.0.7)
i18n (0.4.2)
mail (2.2.9)
mime-types (1.16)
mysql (2.8.1)
polyglot (0.3.1)
rack (1.2.1)
rack-mount (0.6.13)
rack-test (0.5.6)
railties (3.0.1, 3.0.0)
rake (0.8.7)
rubygems-update (1.3.7)
thor (0.14.4)
treetop (1.4.8)
tzinfo (0.3.23)
I assume installing rails via apt-get installed those gems? Prior to installing rails through apt-get I only had mysql and fastthread.
There is also a gem available which handles the update
sudo gem install rubygems-update
sudo /var/lib/gems/1.8/bin/update_rubygems
You have to manually install rubygems 1.3.7 (wget from website, extract, run setup.rb).
Install rvm and take control of your ruby environment.
http://rvm.io/
This may be a newer way of doing it that wasn't available before, but I ran
sudo gem update --system
and it gave me the latest version.
For some reason, Debian/Ubuntu Ruby package doesn't include the RubyGems library. Even worst, RubyGems has been bundled into Ruby 1.9.x but if you try to install it via apt-get, the package manager will force you to install them as two separate packages.
Debian/Ubuntu RubyGems package is outdated, as you noticed, and to make things even more complicated you can't upgrade the packaged version of RubyGems just installing a new RubyGems versions on top of it because the system is patched to prevent you to complete the task, as you experienced.
My suggestion is to avoid using the Ubuntu/Debian pckaged version.
The alternatives are:
for a development system, use RVM
for a production server, install Ruby from source. If you want Ruby < 1.9 you can use Ruby Enterprise edition that is also available as Debian/Ubuntu package. If you want Ruby 1.9.x, compile it from the source.

Can't find header files while running bundle install

I am just getting started learning rails.
I am building my first app using Ruby on Rails tutorial by Michael Hartl.
the book said to use this gem file.
source 'http://rubygems.org'
gem 'rails', '3.0.0.rc'
gem 'sqlite3-ruby', '1.2.5', :require => 'sqlite3'
group :development do
gem 'rspec-rails', '2.0.0.beta.18'
end
group :test do
gem 'rspec', '2.0.0.beta.18'
end
However I get the following error when I run bundle install in the terminal:
Fetching source index for http://rubygems.org/
Using rake (0.8.7)
Using abstract (1.0.0)
Using activesupport (3.0.0.rc)
Using builder (2.1.2)
Using i18n (0.4.1)
Using activemodel (3.0.0.rc)
Using erubis (2.6.6)
Using rack (1.2.1)
Using rack-mount (0.6.13)
Using rack-test (0.5.4)
Using tzinfo (0.3.23)
Using actionpack (3.0.0.rc)
Using mime-types (1.16)
Using polyglot (0.3.1)
Using treetop (1.4.8)
Using mail (2.2.6.1)
Using actionmailer (3.0.0.rc)
Using arel (0.4.0)
Using activerecord (3.0.0.rc)
Using activeresource (3.0.0.rc)
Using bundler (1.0.0)
Using diff-lcs (1.1.2)
Installing nokogiri (1.4.3.1) with native extensions /Library/Ruby/Site/1.8/rubygems/installer.rb:483: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
Paths suggest you are using a Mac, right? Maybe this answer solves your problem?
gem install mysql failure in Snow Leopard
Error looks the same. Accepted answer said that "Installing the Xcode that's bundled with the Snow Leopard fixed the problem."
Are you on Linux? Here is a list of common problems you might run into when installing stuff in Ubuntu Linux - http://rbjl.net/20-rubybuntu-2-troubleshooting-common-ruby-ubuntu-problems
I am on Linux and had to do the following to get nokogiri to install:
sudo apt-get install libxml2 libxml2-dev libxslt1-dev
gem install nokogiri (remember to use sudo if you are not using RVM)
Just FYI, Rails 3.0 was released on August 29. So you can use
gem 'rails', '3.0.0'

Resources