All Tech Guides

Tech Guide

Install SQLite and Create Your First Database

An introduction to SQLite, how to install the SQLite command-line tools on Windows, macOS, and Linux, and a beginner example creating and querying a database.

Databases Beginner Updated October 2026

Disclaimer & Important Cautions

These Tech Guides and instructions are provided in good faith as a general educational guide. Technology changes over time, and settings, software versions, installation steps, and security practices may vary by system.

I cannot guarantee that these steps will work in every environment, and I am not responsible for data loss, configuration problems, system errors, security issues, downtime, or other problems that may result from following this guide.

  • Download SQLite only from the official sqlite.org website or your operating system's package manager.
  • Be careful when editing system environment variables such as PATH.
  • An SQLite database is a single file. Back it up by copying the file, and don't copy it while a program is writing to it.
  • Don't store passwords or sensitive personal data in practice databases.
  • When in doubt, consult official documentation or a qualified technician.

Overview

SQLite is a small, fast, free relational database engine. Unlike MySQL or SQL Server, SQLite has no server: the whole database (tables, data, and indexes) is stored in a single ordinary file on your computer, and programs read and write that file directly. SQLite was created by D. Richard Hipp in 2000 and is in the public domain.

SQLite is the most widely deployed database in the world. It is built into every smartphone, web browsers, Python, PHP, and countless apps. It is ideal for learning SQL, prototypes, small websites, data analysis, and app storage. In this guide you will install the sqlite3 command-line tool and build a small database.

Main idea: SQLite needs no installation of a database server and no setup. Install the small sqlite3 program, point it at a file, and start writing SQL.

SQLite Compared with Server Databases

SQLiteMySQL / SQL Server
SetupNone; a database is just a fileInstall and run a database server
Users and passwordsNone; file permissions control accessUser accounts and permissions
Best forLearning, single-user apps, small sites, data filesMany simultaneous users, large applications
Data typesFlexible (TEXT, INTEGER, REAL, BLOB, NULL)Strict, with many types
SQLStandard SQL with a few differencesStandard SQL plus vendor extensions

Requirements

  • A Windows, macOS, or Linux computer.
  • Internet access to download SQLite.
  • A command line window: Command Prompt or PowerShell on Windows, Terminal on Mac and Linux.

Important Notes

  • Prefer a graphical tool instead of the command line? See the SQLiteStudio guide. It is still useful to learn the command line first.
  • The command-line program is named sqlite3 (with a 3) on every operating system.

SQLite Installation Instructions

Choose the tab for your operating system:

Installing the SQLite Command-Line Tools

Click the tab above for your operating system.

The guide covers these major tasks:

  1. Download the SQLite tools.
  2. Extract them to a folder (Windows).
  3. Add the folder to your PATH (Windows).
  4. Confirm with sqlite3 --version.

Confirm the installation

In a new command line window, enter:

sqlite3 --version

You should see a version number beginning with 3., followed by a date and a long code.

Check yourself: sqlite3 --version prints a 3.x version number.

Beginner Example: A Library Database

You will create a database file, add two related tables, insert data, and run queries.

Step 1: Create the database file

In your command line window, move to a folder where you want to keep your practice work (for example, Documents), then start sqlite3 with a file name:

cd Documents
sqlite3 library.db

The prompt changes to sqlite>. The file library.db is created as soon as you create a table.

Step 2: Turn on readable output

Commands that start with a period are dot commands for the sqlite3 tool itself, not SQL. They don't need a semicolon:

.headers on
.mode box

This shows column names and draws query results as neat tables.

Step 3: Create tables

SQL statements end with a semicolon. Type or paste:

PRAGMA foreign_keys = ON;

CREATE TABLE authors (
    author_id INTEGER PRIMARY KEY,
    name      TEXT NOT NULL,
    country   TEXT
);

CREATE TABLE books (
    book_id   INTEGER PRIMARY KEY,
    title     TEXT NOT NULL,
    year      INTEGER,
    author_id INTEGER REFERENCES authors(author_id)
);

An INTEGER PRIMARY KEY column numbers new rows automatically. PRAGMA foreign_keys = ON makes SQLite enforce the link between books and authors (it is off by default).

Step 4: Insert data

INSERT INTO authors (name, country) VALUES
    ('Jane Austen', 'England'),
    ('Gabriel Garcia Marquez', 'Colombia'),
    ('Toni Morrison', 'United States');

INSERT INTO books (title, year, author_id) VALUES
    ('Pride and Prejudice', 1813, 1),
    ('Emma', 1815, 1),
    ('One Hundred Years of Solitude', 1967, 2),
    ('Beloved', 1987, 3),
    ('Song of Solomon', 1977, 3);

Step 5: Query the data

-- Books published after 1900, newest first
SELECT title, year FROM books WHERE year > 1900 ORDER BY year DESC;

-- Join books to their authors
SELECT b.title, a.name, b.year
FROM books AS b
JOIN authors AS a ON a.author_id = b.author_id
ORDER BY a.name, b.year;

-- Count books per author
SELECT a.name, COUNT(b.book_id) AS book_count
FROM authors AS a
LEFT JOIN books AS b ON b.author_id = a.author_id
GROUP BY a.name
ORDER BY book_count DESC, a.name;

The first query returns three rows, newest first: Beloved (1987), Song of Solomon (1977), and One Hundred Years of Solitude (1967). The last query shows Jane Austen and Toni Morrison with 2 books each, and Gabriel Garcia Marquez with 1.

Step 6: Explore and exit

Try these dot commands. .tables lists the tables, .schema books shows how the books table was created, and .quit exits sqlite3:

.tables
.schema books
.quit

Your data is saved in library.db automatically. To open it again later, run sqlite3 library.db from the same folder.

Check yourself: After reopening library.db, SELECT COUNT(*) FROM books; returns 5.

Common Errors

  • The prompt shows ...>: SQLite is waiting for the rest of a statement. Type ; and press Enter.
  • no such table: you may have opened a different file. Run .databases to see which file is open.
  • 'sqlite3' is not recognized (Windows): the PATH wasn't set, or you didn't open a new Command Prompt afterward.

Next Steps

Final Notes:
  • SQLite stores an entire database in a single file, with no server to install or run.
  • Use sqlite3 filename.db to create or open a database.
  • Dot commands (such as .tables) control the tool; SQL statements end with a semicolon.
  • Turn on PRAGMA foreign_keys = ON; to enforce relationships between tables.
Explore more technology resources

Return to the complete collection of installation and configuration guides.

Browse All Tech Guides