How to Install SQLite3 from Source on Linux (With a Sample Database)

by Ramesh Natarajan on July 6, 2011

SQLite3 is an extremely lightweight SQL database engine that is self-contained and serverless.

There is absolutely no configuration that you need to do to get it working. All you need to do is–install it, and start using it.

Since this is serverless, it is used in lot of the famous software that you are using, and you probably didn’t even know those software were using it. View this list to see all the big name companies who are using SQLite. PHP programming language has SQLite database built in.

If you’ve never used SQLite, follow the steps mentioned in this article to install it on Linux, and create a sample database.

Download SQLite3 Source

Go to the SQLite Download page, and click on “sqlite-autoconf-3070603.tar.gz” (Under Source Code section), and download it to your system. Or, use the wget to directly download it to your server as shown below.

wget http://www.sqlite.org/sqlite-autoconf-3070603.tar.gz

Install SQLite3 from Source

Uncompress the tar.gz file and install SQLite3 as shown below.

tar xvfz sqlite-autoconf-3070603.tar.gz
cd sqlite-autoconf-3070603
./configure
make
make install

make install command will displays the following output indicating that it is installing sqlite3 binaries under /usr/local/bin

test -z "/usr/local/bin" || mkdir -p -- "/usr/local/bin"
  ./libtool --mode=install /usr/bin/install -c sqlite3 /usr/local/bin/sqlite3
/usr/bin/install -c .libs/sqlite3 /usr/local/bin/sqlite3
test -z "/usr/local/include" || mkdir -p -- "/usr/local/include"
 /usr/bin/install -c -m 644 'sqlite3.h' '/usr/local/include/sqlite3.h'
 /usr/bin/install -c -m 644 'sqlite3ext.h' '/usr/local/include/sqlite3ext.h'
test -z "/usr/local/share/man/man1" || mkdir -p -- "/usr/local/share/man/man1"
 /usr/bin/install -c -m 644 './sqlite3.1' '/usr/local/share/man/man1/sqlite3.1'
test -z "/usr/local/lib/pkgconfig" || mkdir -p -- "/usr/local/lib/pkgconfig"
 /usr/bin/install -c -m 644 'sqlite3.pc' '/usr/local/lib/pkgconfig/sqlite3.pc'

Note: If you are interested in installing MySQL database on your system, you can either use yum groupinstall mysql, or install mysql from rpm.

Create a sample SQLite database

The example shown below does the following:

  • Create a new SQLite database called “company.db”.
  • Create “employee” table with three fields 1) Employee Id 2) Name and 3) Title
  • Insert 5 records into the employee tables.
  • Verify the records
  • Exit SQLite3
$ sqlite3 company.db
SQLite version 3.7.6.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

sqlite> create table employee(id integer,name varchar(20),title varchar(10));

sqlite> insert into employee values(101,'John Smith','CEO');
sqlite> insert into employee values(102,'Raj Reddy','Sysadmin');
sqlite> insert into employee values(103,'Jason Bourne','Developer');
sqlite> insert into employee values(104,'Jane Smith','Sale Manager');
sqlite> insert into employee values(104,'Rita Patel','DBA');

sqlite> select * from employee;
101|John Smith|CEO
102|Raj Reddy|Sysadmin
103|Jason Bourne|Developer
104|Jane Smith|Sale Manager
104|Rita Patel|DBA

sqlite>[Press Ctrl-D to exit]

Access the SQLite Database

When you create a database, it is nothing but a file. If you do “ls”, you’ll see the “company.db” file as shown below.

$ ls -l company.db
-rw-r--r--. 1 ramesh ramesh 2048 Jun 18 21:27 company.db

To access an existing database and query the records, do the following. i.e When you do “sqlite3 company.db”, if the database doesn’t exist it’ll create it. If it already exists, it’ll open it.

$ sqlite3 company.db
SQLite version 3.7.6.3
Enter ".help" for instructions
Enter SQL statements terminated with a ";"

sqlite> select * from employee;
101|John Smith|CEO
102|Raj Reddy|Sysadmin
103|Jason Bourne|Developer
104|Jane Smith|Sale Manager
104|Rita Patel|DBA

sqlite>[Press Ctrl-D to exit]

This is just a jumpstart guide for you to get started on SQLite3. In our future articles about SQLite3, we’ll be discussing about several SQLite3 commands, how to access the SQLite3 database from various programming languages, and several tips and tricks on SQLite3.


Linux Sysadmin Course Linux provides several powerful administrative tools and utilities which will help you to manage your systems effectively. If you don’t know what these tools are and how to use them, you could be spending lot of time trying to perform even the basic administrative tasks. The focus of this course is to help you understand system administration tools, which will help you to become an effective Linux system administrator.
Get the Linux Sysadmin Course Now!

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 5 comments… read them below or add one }

1 Allan Mullan July 6, 2011 at 2:14 am

Your tar command under ‘Install SQLite3 from Source’ is only going to list the files – you need to use ‘tar xvfz sqlite-autoconf-3070603.tar.gz’

Good article though.

2 shark巨菜 July 6, 2011 at 6:19 am

I use it for learning SQL language.

3 manoj September 21, 2012 at 7:41 am

For
make install
use
sudo make install

4 Prabhakaran S May 11, 2013 at 6:13 am

Good Work….
While using the command ‘make install’ – user needs to have root access so that folder /usr/local/lib will be created,

if anyone using ubuntu, use sudo -i before using ‘make install’ to achieve this.

thanks.

5 Sreejith.C.K September 24, 2013 at 1:24 am

Thanks.. It s working….

Leave a Comment

Previous post:

Next post: