Flash Sale:75% Off Hosting + Free DomainEnds in13h47m14sView Plans
Hostvento logoHostvento

Install and Use SQLite on Ubuntu 22.04

Install SQLite, create a database and table, add rows and read them back.

Databases2 min read8 screenshots

Install SQLite

Step 1: Update the package index

sudo apt update && sudo apt upgrade -y
Updating the system

Step 2: Install SQLite

sudo apt install sqlite3
Installing SQLite

Step 3: Check the installation

sqlite3 --version
The SQLite version

Use SQLite

Create a database

sqlite3 mydatabase.db
Opening a new database

If the file already exists, SQLite opens it instead of creating a new one.

Create a table

CREATE TABLE users (
    id INTEGER PRIMARY KEY,
    name TEXT NOT NULL,
    email TEXT NOT NULL
);
Creating the users table
  • CREATE TABLE makes a new table.
  • users is the table name.
  • id INTEGER PRIMARY KEY is a unique number for each row.
  • name TEXT NOT NULL and email TEXT NOT NULL are text columns that cannot be empty.

Insert data

INSERT INTO users (name, email) VALUES ('John Doe', 'john@example.com');
Inserting a row

Read data

SELECT * FROM users;
Selecting the rows of the table

SELECT reads data, * means all columns, and FROM users names the table.

Leave the shell

.quit
Leaving the SQLite shell

Main features of SQLite

  • No setup. There is nothing to configure.
  • Serverless. No separate server process runs.
  • One file. The whole database is a single file that is easy to copy.
  • ACID transactions. Updates are safe even after a crash.
  • Standard SQL. Most common SQL works.
  • Small and fast. It suits apps, tools and small sites.
  • Public domain. It is free to use.

Quick recap

  • Install with sudo apt install sqlite3.
  • Open or create a database with sqlite3 name.db.
  • Use normal SQL, and type .quit to leave.