1

I'm a complete Ruby newbie. I'm trying to load the sqlite3 module. Here's the entirety of my script:

#!/usr/bin/ruby -w
require 'sqlite3'

Running that command results in this output:

/usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- sqlite3 (LoadError)
    from /usr/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require'
    from ./sqlite.rb:2:in `<main>'

The go-to page for this problem seems to be this page. However, none of the solutions there help.

The most popular solution is to edit sqlite3's gemspec file. I can only find one file on my system that looks like a gemspec file for sqlite3. It has the following rather odd path:

/home/terry/.gem/specs/api.rubygems.org%443/quick/Marshal.4.8/sqlite3-1.3.13.gemspec

The contents of that file look like this (word wrapped for reading):

;;F;U;  [[[I"~>;TU;[I"  3.15;T0I"jamis@37signals.com;TI"luislavena@gmail.com;TI"
aaron@tenderlovemaking.com;TI"Jamis Buck;TI"Luis Lavena;TI"Aaron Patterson;TI"▒
This module allows Ruby programs to interface with the SQLite3 database engine
(http://www.sqlite.org).  You must have the SQLite engine installed in order
to build this module.
Note that this module is only compatible with SQLite 3.6.16 or newer.;TI"
2https://github.com/sparklemotion/sqlite3-ruby;TT@[I" BSD-3;T

That doesn't match with anything like the stackoverflow page's description.

So I'm lost.

Here are some of my system specifications:

Ubuntu Linux 16.04.1

# sqlite3 -version
3.11.0 2016-02-15 17:29:24 3d862f207e3adc00f78066799ac5a8c282430a5f

# ruby --version
 ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]

Let me know if there is other information I should post. Any help is appreciated. Thanks!


-- update --

In response to Amadan's suggestion, I tried the suggested command and got this result:

# gem install sqlite3
ERROR:  While executing gem ... (Gem::FilePermissionError)
    You don't have write permissions for the /var/lib/gems/2.3.0 directory.

So I tried it with sudo and got this:

# sudo gem install sqlite3
[sudo] password for terry:
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
/usr/bin/ruby2.3 -r ./siteconf20170308-16463-q46juc.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.3.0/gems/sqlite3-1.3.13 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out

I checked that log file and it just has the same error.


-- another update --

On @maxple's suggestion, I installed ruby2.3-dev. That seemed to go well:

# sudo apt-get install ruby2.3-dev
[sudo] password for terry:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libgmp-dev libgmpxx4ldbl
Suggested packages:
  gmp-doc libgmp10-doc libmpfr-dev
The following NEW packages will be installed:
  libgmp-dev libgmpxx4ldbl ruby2.3-dev
0 upgraded, 3 newly installed, 0 to remove and 0 not upgraded.
Need to get 1,357 kB of archives.
After this operation, 6,493 kB of additional disk space will be used.
Do you want to continue? [Y/n]
Get:1 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libgmpxx4ldbl amd64 2:6.1.0+dfsg-2 [8,948 B]
Get:2 http://nyc2.mirrors.digitalocean.com/ubuntu xenial/main amd64 libgmp-dev amd64 2:6.1.0+dfsg-2 [314 kB]
Get:3 http://nyc2.mirrors.digitalocean.com/ubuntu xenial-updates/main amd64 ruby2.3-dev amd64 2.3.1-2~16.04 [1,034 kB]
Fetched 1,357 kB in 0s (3,228 kB/s)
Selecting previously unselected package libgmpxx4ldbl:amd64.
(Reading database ... 125914 files and directories currently installed.)
Preparing to unpack .../libgmpxx4ldbl_2%3a6.1.0+dfsg-2_amd64.deb ...
Unpacking libgmpxx4ldbl:amd64 (2:6.1.0+dfsg-2) ...
Selecting previously unselected package libgmp-dev:amd64.
Preparing to unpack .../libgmp-dev_2%3a6.1.0+dfsg-2_amd64.deb ...
Unpacking libgmp-dev:amd64 (2:6.1.0+dfsg-2) ...
Selecting previously unselected package ruby2.3-dev:amd64.
Preparing to unpack .../ruby2.3-dev_2.3.1-2~16.04_amd64.deb ...
Unpacking ruby2.3-dev:amd64 (2.3.1-2~16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...
Setting up libgmpxx4ldbl:amd64 (2:6.1.0+dfsg-2) ...
Setting up libgmp-dev:amd64 (2:6.1.0+dfsg-2) ...
Setting up ruby2.3-dev:amd64 (2.3.1-2~16.04) ...
Processing triggers for libc-bin (2.23-0ubuntu5) ...

Then I attempted again to gem install sqlite3, and that didn't seem to go well:

# sudo gem install sqlite3
Building native extensions.  This could take a while...
ERROR:  Error installing sqlite3:
        ERROR: Failed to build gem native extension.

    current directory: /var/lib/gems/2.3.0/gems/sqlite3-1.3.13/ext/sqlite3
/usr/bin/ruby2.3 -r ./siteconf20170308-16984-tcxs0x.rb extconf.rb
checking for sqlite3.h... no
sqlite3.h is missing. Try 'brew install sqlite3',
'yum install sqlite-devel' or 'apt-get install libsqlite3-dev'
and check your shared library search path (the
location where your sqlite3 shared library is located).
*** 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.

Provided configuration options:
        --with-opt-dir
        --without-opt-dir
        --with-opt-include
        --without-opt-include=${opt-dir}/include
        --with-opt-lib
        --without-opt-lib=${opt-dir}/lib
        --with-make-prog
        --without-make-prog
        --srcdir=.
        --curdir
        --ruby=/usr/bin/$(RUBY_BASE_NAME)2.3
        --with-sqlite3-config
        --without-sqlite3-config
        --with-pkg-config
        --without-pkg-config
        --with-sqlite3-dir
        --without-sqlite3-dir
        --with-sqlite3-include
        --without-sqlite3-include=${sqlite3-dir}/include
        --with-sqlite3-lib
        --without-sqlite3-lib=${sqlite3-dir}/lib

To see why this extension failed to compile, please check the mkmf.log which can be found here:

  /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/mkmf.log

extconf failed, exit code 1

Gem files will remain installed in /var/lib/gems/2.3.0/gems/sqlite3-1.3.13 for inspection.
Results logged to /var/lib/gems/2.3.0/extensions/x86_64-linux/2.3.0/sqlite3-1.3.13/gem_make.out

The log file mkmf.log has this:

package configuration for sqlite3 is not found
find_header: checking for sqlite3.h... -------------------- no

"gcc -o conftest -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC conftest.c  -L. -L/usr/lib/x86_64-linux-gnu -L. -Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fstack-protector -rdynamic -Wl,-export-dynamic     -lruby-2.3  -lpthread -lgmp -ldl -lcrypt -lm   -lc"
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: int main(int argc, char **argv)
4: {
5:   return 0;
6: }
/* end */

"gcc -E -I/usr/include/x86_64-linux-gnu/ruby-2.3.0 -I/usr/include/ruby-2.3.0/ruby/backward -I/usr/include/ruby-2.3.0 -I. -Wdate-time -D_FORTIFY_SOURCE=2   -g -O2 -fstack-protector-strong -Wformat -Werror=format-security -fPIC  conftest.c -o conftest.i"
conftest.c:3:21: fatal error: sqlite3.h: No such file or directory
compilation terminated.
checked program was:
/* begin */
1: #include "ruby.h"
2:
3: #include <sqlite3.h>
/* end */

--------------------
Community
  • 1
  • 1
tscheingeld
  • 789
  • 7
  • 24
  • Have you installed it? `gem install sqlite3`? You have Ruby, you have SQLite3, but you don't seem to have the Ruby bindings for SQLite3, which is what `require 'sqlite3'` would load. – Amadan Mar 08 '17 at 23:20
  • See the updated above. Basically, I tried that and got more errors that I don't understand. – tscheingeld Mar 08 '17 at 23:35
  • As the error suggests, you're missing Ruby header files. We'd need to know which version of Ruby you're working with (I assume 2.3, from your error), how was it installed (preinstalled by OS?) and on which Linux distribution. – Amadan Mar 08 '17 at 23:39
  • Here's that info: Ubuntu Linux 16.04.1; ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu] – tscheingeld Mar 08 '17 at 23:41
  • run `sudo apt-get install ruby2.3-dev` to get the missing `ruby.h` file. Editing the gemspec of gems you install is practically never something you have to do – max pleaner Mar 08 '17 at 23:43
  • @maxpie: I did that and it didn't seem to help. See "another update" in my top post for the details. – tscheingeld Mar 08 '17 at 23:53
  • @Amadan: I installed Ruby through Webmin, which basically just uses apt-get – tscheingeld Mar 08 '17 at 23:54
  • Same deal, this time with sqlite3. The logs even tell you what to do: "sqlite3.h is missing. Try [...] 'apt-get install libsqlite3-dev'". :) – Amadan Mar 09 '17 at 00:08
  • @Amadan: That worked! Thanks so much! – tscheingeld Mar 09 '17 at 00:21

0 Answers0