65

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?

Makoto
  • 104,088
  • 27
  • 192
  • 230
Eric Noob
  • 1,471
  • 3
  • 15
  • 14

15 Answers15

138

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.)

Andres Riofrio
  • 9,851
  • 7
  • 40
  • 60
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653
13

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

hacintosh
  • 3,784
  • 4
  • 19
  • 22
10

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
matiasmasca
  • 605
  • 8
  • 14
10

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

Rahul
  • 101
  • 1
  • 2
6
sudo apt-get install ruby-dev

Fixed it for me.

4b0
  • 21,981
  • 30
  • 95
  • 142
Sacha
  • 61
  • 1
  • 1
3

On Ubuntu 9 and 10 try:

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

Then run

gem install sqlite3
ldemon
  • 31
  • 3
2

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

Omer Levi Hevroni
  • 1,935
  • 1
  • 15
  • 33
2

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

Promise Preston
  • 24,334
  • 12
  • 145
  • 143
2

Run the following for Fedora OS:

yum install rubygem-sqlite3
Chase
  • 21
  • 1
1

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.

barneytron
  • 7,943
  • 3
  • 23
  • 25
  • The fedora rpm for the mysql headers is something like 'mysql-dev', so the correct sqlite rpm is likely to be 'sqlite3-dev' – erik Jan 07 '09 at 17:58
  • I'm using FreeBSD 7.1 right now, and I have the sqlite3-3.6.4 port installed, which provided everything that gem needed if I remember right. I'm trying to check out Rails 2.2.2 myself. Good luck Erik! – barneytron Jan 07 '09 at 18:14
1

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.

g4k13
  • 31
  • 3
0

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.

Tim Knight
  • 8,346
  • 4
  • 33
  • 32
0

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

Mayur Birari
  • 5,837
  • 8
  • 34
  • 61
0

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

rapidror
  • 131
  • 11
0

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...