Why can't I install the SQLite gem?

Ruby on-RailsRubySqliteGem

Ruby on-Rails Problem Overview


I'm try to install the SQLite gem on a Fedora 9 Linux box with Ruby 1.8.6, Rails 2.2.2, gem 1.3, and sqlite-3.5.9. Here's the command I'm running and its results:

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/bin/ruby extconf.rb install sqlite3-ruby
can't find header files for ruby.

Gem files will remain installed in /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4 for inspection.
Results logged to /usr/lib/ruby/gems/1.8/gems/sqlite3-ruby-1.2.4/ext/sqlite3_api/gem_make.out

gem_make.out just repeats what was already sent to the console. How can I install this gem?

Ruby on-Rails Solutions


Solution 1 - Ruby on-Rails

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 and in order to do that it needs the C header files for the Ruby interpreter.

If you compile Ruby yourself, those header files will be installed automatically, however, in RedHat-ish systems, such header files are usually packaged in a seperate package, called <whatever>-dev. So, in this case you will need to install the ruby-dev package and possibly the libsqlite3-dev (Ubuntu) or sqlite-devel (Fedora) package as well.

However, you might be better off just installing your Operating System's pre-packaged libsqlite3-ruby package, that way all the dependencies are automatically satisfied.

(Note: all package names pulled out of thin air, might be different on your system.)

Solution 2 - Ruby on-Rails

You probably need the ruby dev package. For Ubuntu you have to install ruby1.8-dev which includes the ruby header files. A quick google says that the yum package is ruby-devel. so run this:

> sudo yum install ruby-devel

Solution 3 - Ruby on-Rails

I faced problem installing sqlite3-ruby gem on my fedora 13 box. It was fixed after sudo yum install sqlite-devel

Solution 4 - Ruby on-Rails

When I had that problem:

gem install sqlite3 -v '1.3.9'
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
	ERROR: Failed to build gem native extension.

For me worked, installing the "libsqlite3-dev" with:

apt-get install libsqlite3-dev

Solution 5 - Ruby on-Rails

sudo apt-get install ruby-dev

Fixed it for me.

Solution 6 - Ruby on-Rails

On Ubuntu 9 and 10 try:

sudo apt-get install ruby-dev
sudo apt-get install sqlite3-dev

Then run

gem install sqlite3

Solution 7 - Ruby on-Rails

Run the following for Fedora OS:

yum install rubygem-sqlite3

Solution 8 - Ruby on-Rails

On alpine, you need to install the sqlite-dev package.

Solution 9 - Ruby on-Rails

I also faced this same issue, the problem is that your Linux installation requires the development libraries for SQLite3 to be installed in order to build the gem.

Here's how I fixed the issue

Open your terminal and run the following commands

sudo apt-get install sqlite3

sudo apt-get install libsqlite3-dev

And then try installing Sqlite3 gem again using this command

gem install sqlite3

That's all.

I hope this helps

Solution 10 - Ruby on-Rails

Do you have all the source code required to build sqlite3-ruby? Gem is trying to compile some C code and cannot find the headers. You can probably use a fedora rpm for sqlite3-ruby (I don't use fedora, but I'm sure one exists) if you prefer to forgo compiling. Personally for ruby stuff, I prefer to use gem rather than a distro's packaging system.

Solution 11 - Ruby on-Rails

I'm not really familiar with Fedora, but in Ubuntu when you are installing packages you have apt-get, and you have to install the build-essentials which includes gcc and other compilation tools for C. I would say that could be your issue, and you make look into how that can be install either using RPM or apt-get on Fedora.

Solution 12 - Ruby on-Rails

I fixed the problem on my OLPC (Fedora 9) by installing 'gcc' oddly enough. It seems like it should have been one of those dev packages, but no.

Also, regarding the other packages, the suffix is "-devel", not "-dev", so make sure you get those ending right: "ruby-devel", "sqlite-devel"...

Once you get that installed, if you get errors about your gems being too old "< 1.3.1" when you try to run various rails scripts, eg: script/server or script/console, google "upgrade_rubygems" to fix that problem...

HTH...

Solution 13 - Ruby on-Rails

I had this same exact issue...instead of gem'ing the missing pieces I used synaptic on unbuntu.

The key package for me was libsqlite-ruby1.9.1 ... I documented my experience (for reference) with this error at : Sqlite3-gem-error-during-bundle-install

Solution 14 - Ruby on-Rails

Run "sudo yum install sqlite-devel" and then "gem install sqlite3". Had the same problem on my Fedora 15.

Solution 15 - Ruby on-Rails

I encountered this error while running bundle install after generating a react-rails app on Fedora 29. I was able to identify a suitable development package by running dnf search sqlite3, then installed it dnf install libsqlite3x-devel. This fixed it for me.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionEric NoobView Question on Stackoverflow
Solution 1 - Ruby on-RailsJörg W MittagView Answer on Stackoverflow
Solution 2 - Ruby on-RailshacintoshView Answer on Stackoverflow
Solution 3 - Ruby on-RailsRahulView Answer on Stackoverflow
Solution 4 - Ruby on-RailsmatiasmascaView Answer on Stackoverflow
Solution 5 - Ruby on-RailsSachaView Answer on Stackoverflow
Solution 6 - Ruby on-RailsldemonView Answer on Stackoverflow
Solution 7 - Ruby on-RailsChaseView Answer on Stackoverflow
Solution 8 - Ruby on-RailsOmer Levi HevroniView Answer on Stackoverflow
Solution 9 - Ruby on-RailsPromise PrestonView Answer on Stackoverflow
Solution 10 - Ruby on-RailsbarneytronView Answer on Stackoverflow
Solution 11 - Ruby on-RailsTim KnightView Answer on Stackoverflow
Solution 12 - Ruby on-Railscosmo leeView Answer on Stackoverflow
Solution 13 - Ruby on-RailsRiding RailsView Answer on Stackoverflow
Solution 14 - Ruby on-RailsrapidrorView Answer on Stackoverflow
Solution 15 - Ruby on-Railsg4k13View Answer on Stackoverflow