Compiling the latest sqlite3 on a Linux Ubuntu server
Table of contents:
Introduction
We want to use the latest version of the sqlite(3.38.0
at the time of writing) but we also want, for example, python and php to use the latest sqlite shared library as well. Since the linux ubuntu distribution doesn’t keep up with the latest releases from sqlite, we’ll have to compile from source and install the shared libraries in the system.
Downloading the source code
-
First we need to get the latest autoconf source code:
wget https://www.sqlite.org/2022/sqlite-autoconf-3380000.tar.gz
-
Let’s unpack it
tar xvf sqlite-autoconf-3380000.tar.gz
Compiling and installing sqlite3
-
Before compiling we need to install the required build dependencies:
sudo apt-get install build-essential
-
Let’s cd into the source code folder
cd sqlite-autoconf-3380000/
-
Configure to compilation
./configure
-
Compile
make
- Install it system-wide
sudo make install
-
After a successful compilation, by default, everything should be installed in
/usr/local
and the path for the shared libraries should be added automatically in ld.so.conf, as we can see below:cat /etc/ld.so.conf.d/libc.conf ───────┬──────────────────────────────────────────────────────── │ File: /etc/ld.so.conf.d/libc.conf ───────┼──────────────────────────────────────────────────────── 1 │ # libc default configuration 2 │ /usr/local/lib ───────┴────────────────────────────────────────────────────────
-
To finalize we just need to update the system with the shared libraries:
sudo ldconfig
- Although the recommended way to do it is to add a file with the paths inside
ld.so.conf.d
folder, we can also achieve the same by exporting theLD_LIBRARY_PATH
environment variable from our bash/zsell profiles, for eg:export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib
Verifying that our system is using the latest sqlite3
Finally, if everything went well, we should be using the latest sqlite3 system-wide.
-
Checking that we have the latest version of the sqlite cli:
sqlite3 --version # example output 3.38.0 2022-02-22 18:58:40 40fa792d359f84c3b9e9d6623743e1a59826274e221df1bde8f47086968a1bab
-
Checking the version of the shared library being used by python:
python3 -c "import sqlite3; print(sqlite3.sqlite_version)" # example output 3.38.0
-
Checking the version of the shared library being used by php:
php8.1 --ri sqlite3 # example output sqlite3 SQLite3 support => enabled SQLite Library => 3.38.0 Directive => Local Value => Master Value sqlite3.extension_dir => no value => no value sqlite3.defensive => On => On