SQLite is a self-contained, serverless database engine that stores entire databases in a single file. Unlike client-server databases like MariaDB or PostgreSQL, SQLite requires no separate database process, making it ideal for mobile app development, embedded systems, local application data storage, and prototyping database schemas before deploying to production servers. By the end of this guide, you will have a working SQLite 3 installation ready for development, testing, or integration with applications like Python, PHP, and Android projects.
This guide covers two installation methods: the Ubuntu default repository for stable, distro-maintained packages, and source compilation for users who need the absolute latest features. For most users, the APT method is recommended because it provides automatic security updates and requires no manual maintenance.
Choose Your SQLite 3 Installation Method
Before installing, review the available methods and select one that matches your requirements. Each approach has trade-offs between convenience and version currency.
| Method | Channel | Version | Updates | Best For |
|---|---|---|---|---|
| APT (Recommended) | Ubuntu Repos | Distribution default | Automatic via apt upgrade | Most users; stable, tested packages |
| Source Compilation | Upstream | Latest stable | Manual recompilation | Developers needing newest features |
This guide supports Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS installations. The APT method provides different SQLite versions depending on your Ubuntu release, while source compilation gives you the latest upstream version regardless of your distribution. Commands shown work identically on all supported LTS releases.
For most users, the APT method is recommended because it integrates with Ubuntuโs package management system, receives security updates automatically, and requires no manual maintenance. Only compile from source if you specifically need features unavailable in the repository version or require custom compilation flags.
Method 1: Install SQLite 3 via APT
Update Ubuntu Before SQLite 3 Installation
Before installing new packages, refresh your package index and upgrade existing packages. This ensures you install the latest available version and avoids potential dependency conflicts:
sudo apt update && sudo apt upgrade
The apt update command refreshes your local package index from Ubuntuโs repositories, while apt upgrade installs newer versions of packages you already have. Running both before a new installation is a standard best practice.
Install SQLite 3 via APT Command
Install SQLite 3 using the APT package manager. The package name is sqlite3, which includes both the command-line interface and the shared library:
sudo apt install sqlite3
This command installs the SQLite 3 command-line shell along with libsqlite3-0, the shared library that applications use to interact with SQLite databases. APT handles all dependencies automatically.
Verify the SQLite 3 Installation
After installation completes, verify that SQLite 3 is accessible and check the installed version. This confirms the installation succeeded and shows which version your Ubuntu release provides:
sqlite3 --version
The output varies by Ubuntu release:
| Ubuntu Release | SQLite Version |
|---|---|
| 22.04 LTS | 3.37.2 2022-01-06 13:25:41 ... |
| 24.04 LTS | 3.45.1 2024-01-30 16:01:20 ... |
| 26.04 LTS | 3.46.1 2024-08-13 09:16:08 ... |
If you see a version number in the output, SQLite 3 is installed correctly and ready to use. The version differences between Ubuntu releases reflect each distributionโs package freeze policy; newer Ubuntu releases include more recent SQLite versions.
Method 2: Install SQLite 3 via Source Compilation
Compiling SQLite from source gives you access to the absolute latest version with all upstream features. As of this writing, the latest stable release is SQLite 3.51.1, which may include features not yet available in Ubuntuโs repository packages. However, source-compiled software requires manual updates and does not receive automatic security patches through APT. Additionally, you will need basic build tools like GCC and make, which the next section covers.
Install Build Dependencies
First, install the essential build tools before compiling. The build-essential package includes GCC, make, and other utilities required for compilation. If you frequently compile software from source, consider our CMake installation guide on Ubuntu for more advanced build system options:
sudo apt install build-essential wget
This command installs the C compiler, linker, and make utility along with wget for downloading files. Notably, SQLite has minimal dependencies. It compiles using only standard C libraries already present on Ubuntu systems.
Download the Latest SQLite 3 Source Archive
Next, download the autoconf source archive from the official SQLite website. The following commands automatically detect the latest stable version from the SQLite GitHub repository and download it:
# Get latest version from GitHub API
SQLITE_VERSION=$(curl -s "https://api.github.com/repos/sqlite/sqlite/tags?per_page=10" | \
grep -oP '"name": "version-\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
# Convert version to SQLite format (3.51.1 -> 3510100)
VERSION_NUM=$(echo "$SQLITE_VERSION" | awk -F. '{printf "%d%02d%02d00", $1, $2, $3}')
# Download the source archive
YEAR=$(date +%Y)
wget "https://www.sqlite.org/${YEAR}/sqlite-autoconf-${VERSION_NUM}.tar.gz" || \
wget "https://www.sqlite.org/$((YEAR-1))/sqlite-autoconf-${VERSION_NUM}.tar.gz"
This approach queries the official SQLite GitHub mirror to find the latest stable release. The version number conversion (for example, 3.51.1 becomes 3510100) matches SQLiteโs download URL format. The fallback to the previous year handles releases made late in the calendar year.
Extract the SQLite 3 Archive
After the download completes, extract the tarball to access the source files:
tar xzf sqlite-autoconf-*.tar.gz
This creates a directory named sqlite-autoconf-3510100 (or similar, depending on the version) containing the source code and build scripts.
Configure the Build
Navigate into the extracted directory and run the configure script. The --prefix=/usr option installs SQLite to the standard system location, replacing or supplementing the APT-installed version:
cd sqlite-autoconf-*/
./configure --prefix=/usr
The configure script checks your system for required tools and generates a Makefile tailored to your environment. A successful run ends with messages showing the created configuration files:
Created Makefile from Makefile.in Created sqlite3.pc from sqlite3.pc.in Created sqlite_cfg.h
Compile SQLite with make
With the configuration complete, start the compilation process using make. The -j$(nproc) option tells make to use all available CPU cores for faster compilation:
make -j$(nproc)
The nproc command returns the number of processor cores on your system. Using parallel compilation significantly reduces build time on multi-core systems. SQLite is a small project, so compilation typically completes in under a minute on modern hardware.
Install the Compiled SQLite 3 Binary
Once compilation succeeds, install the binaries and libraries to your system:
sudo make install
This copies the sqlite3 binary to /usr/bin/, the shared library to /usr/lib/, and header files to /usr/include/. The installation output shows the files being copied:
/usr/bin/install sqlite3 "/usr/bin" /usr/bin/install -m 0644 libsqlite3.a "/usr/lib" /usr/bin/install -m 0644 sqlite3.h sqlite3ext.h "/usr/include"
Verify the Source-Compiled Installation
Confirm that the newly compiled version is active by checking the version number:
sqlite3 --version
The output should show the latest version you compiled:
3.51.1 2025-11-28 17:28:25 ...
If the version matches what you downloaded, the source compilation was successful. The compiled version takes precedence over any APT-installed version because /usr/bin typically appears early in your PATH.
Update SQLite 3 from Source
Source-compiled software does not receive automatic updates through APT. The following script automates the update process by fetching the latest version from the official SQLite GitHub repository:
#!/bin/bash
set -e
# Check for required tools
for cmd in curl wget make gcc; do
if ! command -v $cmd &> /dev/null; then
echo "Error: $cmd is required but not installed."
echo "Run: sudo apt install build-essential wget curl"
exit 1
fi
done
# Get latest version from GitHub API
LATEST_VERSION=$(curl -s "https://api.github.com/repos/sqlite/sqlite/tags?per_page=10" | \
grep -oP '"name": "version-\K[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ -z "$LATEST_VERSION" ]; then
echo "Error: Could not fetch latest version from GitHub API."
echo "Check your internet connection or try again later."
exit 1
fi
# Convert version to SQLite format (3.51.1 -> 3510100)
VERSION_NUM=$(echo "$LATEST_VERSION" | awk -F. '{printf "%d%02d%02d00", $1, $2, $3}')
# Get current year for download URL
YEAR=$(date +%Y)
echo "Latest SQLite version: $LATEST_VERSION (${VERSION_NUM})"
echo "Downloading and compiling..."
# Clean previous builds
rm -rf ~/sqlite-autoconf-*/
# Download and compile
cd ~
wget -q "https://www.sqlite.org/${YEAR}/sqlite-autoconf-${VERSION_NUM}.tar.gz" || \
wget -q "https://www.sqlite.org/$((YEAR-1))/sqlite-autoconf-${VERSION_NUM}.tar.gz"
tar xzf sqlite-autoconf-*.tar.gz
cd sqlite-autoconf-*/
./configure --prefix=/usr
make -j$(nproc)
sudo make install
# Verify
echo "Update complete. Installed version:"
sqlite3 --version
Save this script as update-sqlite.sh, make it executable with chmod +x update-sqlite.sh, and run it with ./update-sqlite.sh when you want to update SQLite. The script automatically detects the latest stable version from GitHub and handles the download URL year detection.
Avoid automating this script with cron. Source compilation can fail due to missing dependencies, network issues, or API changes. Always run the script manually so you can monitor the output and address problems before they affect your system.
Basic SQLite 3 Usage
Once installed, you can start using SQLite immediately. The following examples demonstrate common operations to verify your installation works correctly.
Create and Open a Database
Create a new database file by specifying its name when launching sqlite3:
sqlite3 test.db
This opens the SQLite shell with test.db as the active database. If the file does not exist, SQLite creates it when you first write data. You will see the SQLite prompt:
SQLite version 3.51.1 2025-11-28 17:28:25 Enter ".help" for usage hints. sqlite>
Create a Table and Insert Data
At the sqlite prompt, create a simple table and insert a test record:
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT);
INSERT INTO users (name) VALUES ('Test User');
SELECT * FROM users;
Expected output:
1|Test User
Type .quit to exit the SQLite shell. Your database file test.db now contains the table and data you created.
Remove SQLite 3
If you no longer need SQLite, the removal process depends on how you installed it.
Remove APT-Installed SQLite 3
To remove the APT-installed version, use the remove command followed by autoremove to clean up orphaned dependencies:
sudo apt remove sqlite3
sudo apt autoremove
This removes the sqlite3 package and any automatically installed dependencies that are no longer required. The libsqlite3-0 library may remain if other installed applications depend on it.
Remove Source-Compiled SQLite 3
Source-compiled installations require manual removal of the installed files:
sudo rm /usr/bin/sqlite3
sudo rm /usr/lib/libsqlite3.* /usr/lib/pkgconfig/sqlite3.pc
sudo rm /usr/include/sqlite3.h /usr/include/sqlite3ext.h
sudo rm /usr/share/man/man1/sqlite3.1
After removing the compiled version, if you had previously installed SQLite via APT, that version becomes active again. You can also clean up the source directory:
rm -rf ~/sqlite-autoconf-*
Verify removal by checking that sqlite3 is no longer accessible (or shows the APT version if still installed):
sqlite3 --version
Troubleshoot Common SQLite Issues
If you encounter problems with your SQLite installation, the following solutions address the most common issues.
sqlite3: command not found
This error typically means the package is not installed or the binary is not in your PATH. First, verify the package is installed:
dpkg -l | grep sqlite3
If the package is installed, you will see output similar to:
ii libsqlite3-0:amd64 3.45.1-1ubuntu2 amd64 SQLite 3 shared library ii sqlite3 3.45.1-1ubuntu2 amd64 Command line interface for SQLite 3
If no output appears, the package is not installed. Run sudo apt install sqlite3 to install it. For source-compiled installations, ensure /usr/bin or the installation prefix you used is in your PATH.
Library Version Conflicts After Source Compilation
If applications report library errors after source compilation, the system may be loading the old APT-installed library instead of your compiled version. Update the library cache:
sudo ldconfig
Then verify which library applications will use:
ldconfig -p | grep sqlite3
Expected output showing the library location:
libsqlite3.so.0 (libc6,x86-64) => /lib/x86_64-linux-gnu/libsqlite3.so.0
If both APT and source-compiled versions appear with different paths, applications may load whichever comes first in the library search path. The /usr/lib path typically takes precedence for source-compiled versions.
Permission Denied When Opening Database
SQLite stores databases as regular files, so file permissions affect access. If you receive permission errors, check the database file ownership:
ls -la database.db
Ensure your user has read and write permissions. For databases in web server directories, the web server user (typically www-data) needs appropriate permissions.
Conclusion
You now have SQLite 3 installed on Ubuntu, ready for application development, database prototyping, or embedded use. The APT method provides stable, automatically updated packages, while source compilation offers the latest features for users with specific requirements. For most development and production scenarios, the distribution-provided version is sufficient and recommended.
Useful Links
These resources provide additional information for working with SQLite:
- SQLite GitHub Repository: The official source code mirror with build instructions and issue tracking.
- SQLite Official Website: Comprehensive documentation, release notes, and download links.
- SQLite Quickstart Guide: A five-minute introduction to using SQLite from the command line and in applications.
- When to Use SQLite: Official guidance on appropriate use cases and when a client-server database might be better.
- SQLite Documentation: Complete reference covering SQL syntax, C API, and advanced features.