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

1
wget https://www.sqlite.org/2022/sqlite-autoconf-3380000.tar.gz
  • Let’s unpack it
1
tar xvf sqlite-autoconf-3380000.tar.gz

Compiling and installing sqlite3

  • Before compiling we need to install the required build dependencies:
1
sudo apt-get install build-essential
  • Let’s cd into the source code folder
1
cd sqlite-autoconf-3380000/
  • Configure to compilation
1
./configure
  • Compile
1
make
  • Install it system-wide
1
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:
1
2
3
4
5
6
7
8
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:
1
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 the LD_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:
1
2
3
4
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:
1
2
3
4
	python3 -c "import sqlite3; print(sqlite3.sqlite_version)"

	# example output
	3.38.0
  • Checking the version of the shared library being used by php:
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
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