Nokogiri and Rails wont install. [Ruby On Rails] - ruby-on-rails

So I have been following this guide to learn ruby on rails. I just installed ubuntu and was making an effort to install the required gear but I am facing a lot of problems. I tried searching online but couldn't really find a solution. So basically, Im following this guide (https://www.railstutorial.org/book), and I was learning how to make my first app.
There was this point after installing lots and lots of stuff where I was asked to modify the gemfile with the following text.
source 'https://rubygems.org'
gem 'rails', '4.2.0.rc3'
gem 'sass-rails', '5.0.0.beta1'
gem 'uglifier', '2.5.3'
gem 'coffee-rails', '4.1.0'
gem 'jquery-rails', '4.0.0.beta2'
gem 'turbolinks', '2.3.0'
gem 'jbuilder', '2.2.3'
gem 'sdoc', '0.4.0', group: :doc
group :development, :test do
gem 'sqlite3', '1.3.9'
gem 'byebug', '3.4.0'
gem 'web-console', '2.0.0.beta3'
gem 'spring', '1.1.3'
end
And I had ruby before itself but it was outdated so I updated it to 2.1.5.
Now when I used the command "bundle install" it gave me errors saying it couldnt install rails and nokogiri. I tried installing rails and nokogiri seperately too but it didnt work out.
Here's the error:
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 -r ./siteconf20141220-9232-x08jtr.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.1.0/gems/nokogiri-1.6.5 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.5/gem_make.out
And for rails:
Fetching: rack-1.6.0.gem (100%)
Successfully installed rack-1.6.0
Building native extensions. This could take a while...
ERROR: Error installing rails:
ERROR: Failed to build gem native extension.
/usr/bin/ruby2.1 -r ./siteconf20141220-9321-6z0v97.rb extconf.rb
mkmf.rb can't find header files for ruby at /usr/lib/ruby/include/ruby.h
extconf failed, exit code 1
Gem files will remain installed in /var/lib/gems/2.1.0/gems/nokogiri-1.6.5 for inspection.
Results logged to /var/lib/gems/2.1.0/extensions/x86_64-linux/2.1.0/nokogiri-1.6.5/gem_make.out
What is happening ? And please do give me a detailed solution because I'm quite new to this.
Thanks for the help in Advance !

It sounds like you didn't install the ruby-dev libraries. So you've got a Ruby VM, but not the libraries required to build gems. Try installing the ruby-dev package.
sudo apt-get install ruby-dev
And then rebundle.

First off, don't try to use the system Ruby for development. That Ruby version is packaged to run specific system level packages for the OS, you can break OS utils by manually updating it or a OS update can break your dev environment. Plus, it will most likely require you run everything as sudo which is just a pain. I recommend installing rvm or rbenv for managing your development rubies.
Now, as for your specific error, you probably just need to install libxml development packages for Ubuntu:
sudo apt-get install libxslt-dev libxml2-dev

Related

Add `gem 'mysql2'` to your Gemfile (and ensure its version is at the minimum required by ActiveRecord)

In my Gemfile I have: mysql2 (0.4.4)
I got this error when launching my Rails server: Specified 'mysql2' for database adapter, but the gem is not loaded. Add gem 'mysql2' to your Gemfile (and ensure its version is at the minimum required by ActiveRecord).
I read and searched some threads on this website. The recommendations were to downgrade mysql2
"version 0.3.18 of mysql2 by adding this line to your gemfile:
gem 'mysql2', '~> 0.3.20'"
When I did this I tried to rerun bundle install and I got this error.
[!] There was an error parsing Gemfile: unterminated string meets end of file. Bundler cannot continue.
# from /Users/john-michaelnalettenalette/simple_cms/Gemfile:7
# -------------------------------------------
# # Use mysql as the database for Active Record
gem ‘mysql2’, `~> 0.3.20’
# # Use SCSS for stylesheets
# -------------------------------------------
Any Ideas would be appreciated.
You started a string which you didn't end at the end of this line :
gem 'mysql2', '~> 0.3.20'"
Change it to this:
gem 'mysql2', '~> 0.3.20'
I had the same error on rails v 4.2.10. Ubuntu 18:10
Installing mysql2 0.3.21 with native extensions
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
the solution suggested in the error message was:
libmysqlclient is missing. You may need to 'apt-get install libmysqlclient-dev'
or 'yum install mysql-devel', and try again.
this worked!
note: I am bundling an old app which depended on mysql, which is not yet installed on my machine. installing mysql may also have solved my issue.

Rails 4: Error when installing tiny_tds gem?

I have developed a rails web project with Ruby v2 and Rails v4. It was perfectly working in my current system and when i tried to run this project in another Linux machine (Ubuntu 12.4 ) i am getting a Tidy_tds error .
This error is showing at the time of bundle install ,
Error Details below
Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
/home/action/.rvm/rubies/ruby-2.1.1/bin/ruby extconf.rb
checking for iconv_open() in iconv.h... yes
checking for sybfront.h... no
-----
freetds is missing.
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.
Provided configuration options:
--with-opt-dir
--without-opt-dir
--with-opt-include
--without-opt-lib=${opt-dir}/lib
--with-make-prog
--without-make-prog
--srcdir=.
--curdir
--ruby=/home/action/.rvm/rubies/ruby-2.1.1/bin/ruby
--enable-lookup
--disable-lookup
--with-iconv-dir
--without-iconv-dir
--with-iconv-include
--without-iconv-include=${iconv-dir}/include
--with-iconv-lib
--without-iconv-lib=${iconv-dir}/lib
--with-freetds-dir
--without-freetds-dir
--with-freetds-include
--without-freetds-include=${freetds-dir}/include
--with-freetds-lib
--without-freetds-lib=${freetds-dir}/lib
extconf failed, exit code 1
Gem files will remain installed in /home/action/.rvm/gems/ruby-2.1.1/gems/tiny_tds-0.6.1 for inspection.
Results logged to /home/action/.rvm/gems/ruby-2.1.1/extensions/x86_64-linux/2.1.0/tiny_tds-0.6.1/gem_make.out
An error occurred while installing tiny_tds (0.6.1), and Bundler cannot continue.
Make sure that `gem install tiny_tds -v '0.6.1'` succeeds before bundling.
I have also tried installing tiny_tds seperatly, but still i am getting the same issue
gem install tiny_tds -v '0.6.1'
My gem file,
source 'https://rubygems.org'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '4.0.2'
# Use SCSS for stylesheets
gem 'sass-rails', '~> 4.0.0'
gem 'tiny_tds'
# Use Uglifier as compressor for JavaScript assets
gem 'uglifier', '>= 1.3.0'
# Use CoffeeScript for .js.coffee assets and views
gem 'coffee-rails', '~> 4.0.0'
# See https://github.com/sstephenson/execjs#readme for more supported runtimes
# gem 'therubyracer', platforms: :ruby
# Use jquery as the JavaScript library
gem 'jquery-rails'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
gem 'jquery-ui-rails' # jquery ui
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
gem 'jbuilder', '~> 1.2'
group :doc do
# bundle exec rake doc:rails generates the API under doc/api.
gem 'sdoc', require: false
end
# Use sqlserver as the database for Active Record
gem 'activerecord-sqlserver-adapter', :git => 'https://github.com/nextgearcapital/activerecord-sqlserver-adapter.git'
gem "therubyracer"
gem "less-rails"
gem "twitter-bootstrap-rails"
gem 'bootstrap-datepicker-rails'
gem 'will_paginate'
gem 'sqlite3'
gem 'formtastic'
Why is this error appearing and how to solve this issue.
Any help is appreciated
Looks like you don't have freetds installed on this machine:
sudo apt-get install freetds-dev
If you see the details of the freetds-dev package you will see it has the missing file sybfront.h
There is no gem that I know for freetds and building the tiny_tds gem requires it to compile. However it should be possible for you build your own version of the gem using MiniPortile.
Rather than using the normal gem install mechanism you need to clone the tiny_tds from GitHub and then build a native gem for your environment. This process will include downloading a specific version of freetds which is used to compile the gem against.
This should get you round the problem of not being able to install freetds-dev package, but does have the disadvantage that if tiny_tds gem is updated in the future you will need to repeat this process each time - you can't simply take advantage of bundle update.
The steps you need to follow are detailed here.
For MacOS you need additional lib installed.
brew install freetds
This worked for me in Ubuntu 17.04
Install wget to download packages from remote URL
$ sudo apt-get install wget
Install dependencies
$ sudo apt-get install build-essential
$ sudo apt-get install libc6-dev
Download remote file
$ wget ftp://ftp.freetds.org/pub/freetds/stable/freetds-1.00.21.tar.gz
Unzip
$ tar -xzf freetds-1.00.21.tar.gz
Configure and Run Test for the package in your system
$ cd freetds-1.00.21
$ sudo ./configure --prefix=/usr/local --with-tdsver=7.3
$ sudo make
Now, Install
$ sudo make install
Now install the gem
$ gem install tiny_tds -v '2.0.0'
If still, you cannot install the gem tiny_tds then try using sudo
$ sudo gem install tiny_tds -v '2.0.0'
Output
Building native extensions. This could take a while...
Successfully installed tiny_tds-2.0.0
Parsing documentation for tiny_tds-2.0.0
Installing ri documentation for tiny_tds-2.0.0
Done installing documentation for tiny_tds after 1 seconds
1 gem installed

Twitter Bootstrap in Ruby on Rails

I want to integrate twitter-boostrap in my Ruby on Rails project.
For that i have written- gem "therubyracer" gem "less-rails" gem "twitter-bootstrap-rails" on my gemfile. And then bundle install in rails command prompt.
After installing less-rails. This error is comming
Gem::Installer::ExtensionBuildError: ERROR:
Failed to build gem native extension`
c:/row/Ruby200/bin/ruby.exe extconf.rb`
creating Makefile
The system cannot find the path specified.
The system cannot find the path specified.`
c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8-3.16.14.3/ext/libv8/builder.rb:58:
in `setup_python!': libv8 requires python 2 to be installed in order to build, b
ut it is currently not available (RuntimeError)
from c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8-3.16.14.3/ext/libv8/builder.rb:42:in `block in build_libv8!'
from c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8-3.16.14.3/ext/libv8/builder.rb:40:in `chdir'
from c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8-3.16.14.3/ext/libv8/builder.rb:40:in `build_libv8!'
from c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8-3.16.14.3/ext/libv8/location.rb:24:in `install!'
from extconf.rb:7:in `<main>'
Gem files will remain installed in c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8 -3.16.14.3 for inspection.
Results logged to c:/row/Ruby200/lib/ruby/gems/2.0.0/gems/libv8-3.16.14.3/ext/libv8/gem_make.out
An error occurred while installing libv8 (3.16.14.3), and Bundler cannotcontinue.
Make sure that `gem install libv8 -v '3.16.14.3'` succeeds before bundling.
Help. thanks
Remove
group :assets do
end
But keep gems mentioned inside this group, then do bundle install.
gem 'therubyracer', :platforms => :ruby
gem 'less-rails'
gem 'devise'

Nokogiri gem installation error with spree

I'm getting this error when I try to bundle install
Bundler::GemspecError: Could not read gem at /home/theareba/.rvm/gems/ruby-2.0.0-p353/cache/nokogiri-1.6.1.gem. It may be corrupted.
An error occurred while installing nokogiri (1.6.1), and Bundler cannot
continue.
Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling.
I've tried removing nokogiri in the cache and bundle installing again in vain.
Here's my gemfile
source 'https://rubygems.org'
gem 'rails', '4.0.0'
ruby "2.0.0"
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '2-1-stable'
gem 'spree', github: 'spree/spree', branch: '2-1-stable'
gem 'bootstrap-sass', '2.3.2.0'
gem 'sass-rails'
gem 'uglifier'
gem 'coffee-rails'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder'
group :development, :test do
gem 'turn', :require => false
gem 'sqlite3'
gem 'taps', :require => false
gem 'rspec-rails'
end
group :production do
gem 'pg', '0.15.1'
gem 'rails_12factor'
end
UPDATE
Error that occurs when I run gem install nokogiri -v '1.6.0'
Fetching: mini_portile-0.5.2.gem (100%)
Fetching: nokogiri-1.6.0.gem (100%)
Building native extensions. This could take a while...
ERROR: Error installing nokogiri:
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:5:in `<main>'
Gem files will remain installed in /var/lib/gems/1.9.1/gems/nokogiri-1.6.0 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/nokogiri-1.6.0/ext/nokogiri/gem_make.out
Note: I've installed both libxslt1-dev and libxml2-dev that are requirements in nokogiri installation.
I've also tried gem install nokogiri -v '1.6.1' but it still fails. I've installed nokogiri -v 1.5.0 in another app so I tried it in this app and got the error that spree requires nokogiri version 1.6.0 or greater. I'm I missing something?
So here's what solved my problem. I created a new gemset i.e
rvm gemset create nokogiri
rvm use ruby-2.0.0-p353#nokogiri
Note: I'm using rvm and ruby 2.0.0. Then I made sure I've got necessary lib installed by running
sudo apt-get install libxml2-dev libxslt-dev
The libraries happened to be already installed. Then I installed nokogiri
gem install nokogiri -v '1.6.1'
It installed successfully. And finally ran bundle install to get all my gems. Hope this helps anyone having the same issue.
Check the RVM gemset. I fixed it by restoring the gemset. If you try upgrading to 4.0.2? I used Nokogiri 1.6.1 with Ruby 2.0.0 and Rails 4.0.2
try this
sudo apt-get install ruby-dev
sudo apt-get install libxml2 libxml2-dev libxslt1-dev
and reinstall nokogiri
sudo gem install nokogiri

Installing pg gem on ubuntu

I'm developing a rails app using sqlite3. I want to push it to Heroku. In Heroku tutorial it says that I have to first change:
gem 'sqlite3'
to
gem 'pg'
and run
bundle install
I got this error:
Installing pg (0.14.1) with native extensions
Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension.
...
Can't find the PostgreSQL client library (libpq)
*** 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.
...
next I tried the solution proposed here:
running gem install pg -- --with-pg-config= /usr/bin/pg_config
I also tried running:
sudo apt-get install postgresql
sudo apt-get install libpq-dev
and
gem install pg
works fine..
But
bundle install
still gives me the same error
Note: I'm using rvm
did you try
group :development, :test do
gem 'sqlite3'
end
group :production do
gem 'pg'
end
in your gemfile so that you can use sqlite in development and when you push to heroku as production it will be pg.
Change your gemfile to the following:
gem 'sqlite3', :group => :development
gem 'pg', :group => :production
This way you will use SQL locally in development. Heroku will ignore the sqlite gem, and use Postgres instead.

Resources