How to Install SQLite on Android Using Termux (Tested)

A terminal app is the first thing you need to run the sqlite3 shell on an Android phone. Termux is one, and it installs SQLite with a single command, no root needed. In this article I’ll walk you through installing it with pkg install sqlite and getting your first database running.

TLDR

  • Install Termux from F-Droid or GitHub, not the experimental Google Play build.
  • Run pkg update, then pkg install sqlite.
  • Check it with sqlite3 --version, then open a database with sqlite3 tasks.db.
  • Run termux-setup-storage once if you want to keep databases in your phone’s shared storage.

What are you installing?

You’re installing two things. Termux is an Android app that gives you a Linux terminal and a package manager, without root. SQLite is a database engine that keeps a whole database in one file. Its sqlite3 package gives you the command-line shell, where you type SQL and see the results.

Prerequisites

RequirementDetail
Android versionAndroid 7 or newer for the current Termux builds (Termux README)
Termux appFrom F-Droid or GitHub. The Google Play build is an experimental branch with “missing functionality and bugs” (Termux README)
StorageAbout 180 MB for the Termux APK and bootstrap (Termux README)
NetworkNeeded for pkg to download packages

Install all Termux apps and plugins from the same source. The README warns that APKs from different sources are signed with different keys and won’t work together.

How to install SQLite in Termux

To show you each step, I ran them in a Termux container (the official termux/termux-docker image), so the outputs below are real Termux output.

Step 1: Update the package lists

Open Termux and run:

pkg update

Answer y if it asks to upgrade packages. pkg is Termux’s wrapper around apt (Termux wiki: Package Management).

Step 2: Install the sqlite package

$ pkg install -y sqlite 2>&1 | grep -E '^(Setting up|sqlite is already)'
Setting up sqlite (3.53.4) ...

That’s the whole install. The package is called sqlite, and it gives you the sqlite3 command.

Check that it works

Print the version and the path of the command:

$ sqlite3 --version | cut -d' ' -f1
3.53.4
$ command -v sqlite3
/data/data/com.termux/files/usr/bin/sqlite3

If you see sqlite3: command not found, the install didn’t finish. Run pkg install sqlite again and read the last lines of its output for the error.

Create your first database

To show you SQLite working on the phone, I will use a small to-do list database. Save these statements as setup.sql (nano setup.sql opens an editor in Termux):

CREATE TABLE tasks (
  id INTEGER PRIMARY KEY,
  title TEXT NOT NULL,
  done INTEGER NOT NULL DEFAULT 0,
  created_at TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP
);
INSERT INTO tasks (title) VALUES ('Learn SQLite basics'), ('Practise joins');
INSERT INTO tasks (title, done) VALUES ('Install Termux', 1);

Run the file against a database that doesn’t exist yet. SQLite creates tasks.db and fills it:

$ sqlite3 tasks.db < setup.sql
$ sqlite3 tasks.db "SELECT id, title, done FROM tasks;"
1|Learn SQLite basics|0
2|Practise joins|0
3|Install Termux|1

Typing long statements on a phone keyboard is slow, so a script file like this is worth the extra step. Inside the shell, .read setup.sql does the same thing.

Make the output readable on a small screen

By default the shell prints rows separated by |, with no column names:

$ sqlite3 tasks.db "SELECT id, title, done FROM tasks WHERE done = 0;"
1|Learn SQLite basics|0
2|Practise joins|0

The shell reads ~/.sqliterc every time it starts. Save these lines in it:

.headers on
.mode column
.nullvalue NULL

The same query now prints headers and aligned columns:

$ sqlite3 tasks.db "SELECT id, title, done FROM tasks WHERE done = 0;"
id         title         done
--  -------------------  ----
 1  Learn SQLite basics     0
 2  Practise joins          0

Use SQLite from Python in Termux

Python’s sqlite3 module is part of the standard library, so installing Python is enough:

$ pkg install -y python 2>&1 | grep -E '^Setting up python '
Setting up python (3.14.6-1) ...

This script reads the open tasks from the same tasks.db:

import sqlite3

con = sqlite3.connect("tasks.db")
for task_id, title in con.execute("SELECT id, title FROM tasks WHERE done = 0"):
    print(f"Task {task_id}: {title}")
print("SQLite library version:", sqlite3.sqlite_version)
con.close()
$ python query_tasks.py
Task 1: Learn SQLite basics
Task 2: Practise joins
SQLite library version: 3.53.4

Keep databases in your phone’s shared storage

Termux’s home folder is private to the app. To reach shared storage (/sdcard), run this once and grant the permission Android asks for (not executed here, because it needs a real Android device):

termux-setup-storage

The Termux wiki says it creates ~/storage, with links such as ~/storage/shared for shared storage and ~/storage/downloads for Downloads. It also notes that the permission “will not enable write access to the external sdcard” (Termux wiki: termux-setup-storage). Until you run it, the folder doesn’t exist:

$ ls ~/storage
ls: cannot access '/data/data/com.termux/files/home/storage': No such file or directory

Then sqlite3 ~/storage/shared/Documents/tasks.db opens a database that other apps can see (not executed here).

Back up and restore a database

A database is one file, so copying it is a full backup when nothing is writing to it. On a phone, cp tasks.db ~/storage/shared/ puts the copy in shared storage (not executed here, because it needs termux-setup-storage). A dump is a text file of SQL statements that rebuilds the database anywhere:

$ sqlite3 tasks.db .dump > tasks_dump.sql
$ head -n 4 tasks_dump.sql
PRAGMA foreign_keys=OFF;
BEGIN TRANSACTION;
CREATE TABLE tasks (
  id INTEGER PRIMARY KEY,
$ sqlite3 restored.db < tasks_dump.sql
$ sqlite3 restored.db "SELECT count(*) AS tasks FROM tasks;"
tasks
-----
    3

Troubleshooting

  • sqlite3: command not found: the package isn’t installed. Run pkg install sqlite.
  • Permission denied under ~/storage: run termux-setup-storage and grant the permission. If it still fails on Android 11, the Termux wiki’s workaround is to revoke the storage permission in Android Settings > Apps > Termux > Permissions, then grant it again.
  • A new, empty database instead of your data: SQLite creates a file when the path doesn’t exist. Check the folder with pwd and ls before you open it. See SQLite create database if not exists.
  • database is locked: another connection is writing to the file. See database is locked.

Conclusion

Getting SQLite onto Android takes pkg update and pkg install sqlite. From there, it’s the same sqlite3 shell you’d use on a laptop, which makes Termux a handy place to practise SQL on your phone.

Further reading

Tested with SQLite 3.53.4 and Python 3.14.6 in the termux/termux-docker (aarch64) image on 7 October 2026.