# Being confused about libraries

**URL:** <https://www.ruby-forum.com/t/being-confused-about-libraries/182393>\
**Category:** Ruby\
**Created:** [January 27, 2010, 1:21pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393 "2010-01-27T13:21:33Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 1:21pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/1 "2010-01-27T13:21:33Z")

</div>

Hello,

When running gem I always need to add this lib and that lib (I’m using  
an ubuntu desktop linux).

For example, for sqlite3, sometime I installed it:  
gem install sqlite3-ruby

While some other time I installed it:  
apt-get install sqlite3

So what’s the relation between the system “sqlite3” and (most likely)  
ruby’s “sqlite3-ruby”?

Thanks.  
Jenn.

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 1:31pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/2 "2010-01-27T13:31:30Z")

</div>

On 27.01.2010 13:20, Ruby N. wrote:

> So what’s the relation between the system “sqlite3” and (most likely)  
> ruby’s “sqlite3-ruby”?

Ubuntu (and other distros) package gems within their own package  
management system. The reasons are many, but for example this allows  
more fine-grained dependency tracking than RubyGems provides, and allows  
the distribution to make a gem fit into the distribution’s file system  
layout.

Another (side) benefit is that bugfixes are applied at the same time as  
the whole system updates. One step, instead of two.

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 1:41pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/3 "2010-01-27T13:41:10Z")

</div>

Phillip G. wrote:

> On 27.01.2010 13:20, Ruby N. wrote:
> 
> > So what’s the relation between the system “sqlite3” and (most likely)  
> > ruby’s “sqlite3-ruby”?
> 
> Ubuntu (and other distros) package gems within their own package  
> management system.

That’s true, but the sqlite3 package isn’t a Ruby one:  
"  
A command line interface for SQLite 3

SQLite is a C library that implements an SQL database engine.  
Programs that link with the SQLite library can have SQL database  
access without running a separate RDBMS process.  
"

The Ruby packages (for Ubuntu) are:  
libsqlite3-ruby1.8  
libsqlite3-ruby1.9

Marvin

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/4 "2010-01-27T14:43:14Z")

</div>

Roger B. wrote:

> Hi,
> 
> On Wed, Jan 27, 2010 at 1:20 PM, Ruby N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
> wrote:
> 
> > So what’s the relation between the system “sqlite3” and (most likely)  
> > ruby’s “sqlite3-ruby”?
> 
> Usually, the Ubuntu package is the library written in C (or some other  
> language) and the gem provides a ruby wrapper for these libraries.  
> That’s why you need both.

Not exactly.

If you “apt-get install libsqlite3-ruby”, then you get Ubuntu’s package  
containing the ruby library which talks to the C library (libsqlite3-0).  
The C library is automatically installed as a dependency. This is not a  
gem; the code is installed under ruby’s site library directory.

If you install the gem (“gem install sqlite3-ruby”) then rubygems  
fetches, builds and installs its own version of this ruby library. In  
order for this to work, not only does the C library have to be present,  
but also the C library’s header files (libsqlite3-dev), the Ruby header  
files (ruby-dev) and the C compiler (build-essential)

You only need one or other of these to access sqlite3 from ruby.

The advantage of the gem approach is you can easily update it if a new  
version of the sqlite3-ruby gem is released. Ubuntu won’t update their  
package unless there’s a security issue, or until you move to the next  
version of Ubuntu.

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 2:18pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/5 "2010-01-27T14:18:55Z")

</div>

Hi,

On Wed, Jan 27, 2010 at 1:20 PM, Ruby N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> So what’s the relation between the system “sqlite3” and (most likely)  
> ruby’s “sqlite3-ruby”?

Usually, the Ubuntu package is the library written in C (or some other  
language) and the gem provides a ruby wrapper for these libraries.  
That’s why you need both.

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 3:09pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/6 "2010-01-27T15:09:15Z")

</div>

On 27.01.2010 14:43, Brian C. wrote:

> If you “apt-get install libsqlite3-ruby”, then you get Ubuntu’s package  
> containing the ruby library which talks to the C library (libsqlite3-0).  
> The C library is automatically installed as a dependency. This is not a  
> gem; the code is installed under ruby’s site library directory.

While not the gem per se, it is the same code used as if you would do a  
sudo gem install sqlite3-ruby

> The advantage of the gem approach is you can easily update it if a new  
> version of the sqlite3-ruby gem is released. Ubuntu won’t update their  
> package unless there’s a security issue, or until you move to the next  
> version of Ubuntu.

The disadvantage of the gem approach is security:

For one, RubyGems pretty much requires root access to some directories,  
for another, it makes no distinction between compile- and install-time,  
so the compiler runs as root, allowing me to potentially exploit a  
vulnerability in the compiler to get a backdoor installed.

Or just do a “rm -rf /”, if I were unimaginative.

RubyGems will happily overwrite anything in /usr/bin/, so I can include  
a /usr/bin/less file that grants me root access:  
[https://bugs.gentoo.org/show\_bug.cgi?id=278566](https://bugs.gentoo.org/show_bug.cgi?id=278566)

And yes, the issue is known:  
[http://redmine.ruby-lang.org/issues/show/1800](http://redmine.ruby-lang.org/issues/show/1800)

And unless you check certificates (against what? Is there a default  
keystore, like a “rubyist-keyring”?), you cannot verify the integrity of  
a package.

So, trading convenience against security. Be aware of the risks that  
carries with it.

Oddly this is less of an issue on Windows, since Ruby is self-contained  
there, and happily so, and wreaking a Windows isntall is exceptionally  
difficult by now.

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 3:19pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/7 "2010-01-27T15:19:48Z")

</div>

I have the following sqite3 for ruby installed:

$ gem list _sqlite3_

\*\*\* LOCAL GEMS \*\*\*

dbd-sqlite3 (1.2.5)  
sqlite3 (0.0.6)  
sqlite3-ruby (1.2.5)

And these system libraries:

$ dpkg -l _sqlite3_

ii libsqlite3-0 3.6.16-1ubuntu1  
SQLite 3 shared library  
ii libsqlite3-dev 3.6.16-1ubuntu1  
SQLite 3 development files  
ii libsqlite3-ruby 1.2.4-2  
SQLite3 interface for Ruby  
ii libsqlite3-ruby1.8 1.2.4-2  
SQLite3 interface for Ruby 1.8  
ii sqlite3 3.6.16-1ubuntu1  
A command line interface for SQLite 3

So what’s the relations among them? Thanks again.

---

<div class="post-metadata">

**Author:** ![rubynut](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/8e8cbc/32.png) [@rubynut](https://www.ruby-forum.com/u/rubynut)\
**Post date:** [January 27, 2010, 3:20pm UTC](https://www.ruby-forum.com/t/being-confused-about-libraries/182393/8 "2010-01-27T15:20:23Z")

</div>

On 27.01.2010 14:37, Ruby N. wrote:

> ii libsqlite3-ruby1.8 1.2.4-2  
> SQLite3 interface for Ruby 1.8  
> ii sqlite3 3.6.16-1ubuntu1  
> A command line interface for SQLite 3

libsqlite3-ruby\* is the sqlite3-ruby gem (the first one seems to be a  
meta package, once Ubuntu switches to Ruby 1.9 by default, so that 1.9  
versions of gems get pulled by apt-get / synaptic).

libsqlite3-0 and libsqlite3-dev are the plain old C based SQLite3  
binaries and development packages, unrelated to Ruby, unless you build  
the native extension of the gem (which only needs the -dev package,  
technically speaking).
