How to Install SQLite and SQLite Browser on Ubuntu 20.04

Sqlite is a lightweight but feature-rich database management system that is widely used in embedded systems like mobile devices. It is basically a relative database management system used for storing structured data in large tables. Other Major Database Management Systems in this series include Microsoft’s SQL Server, MySQL, PostgreSQL, IBM’s DB2,  and Oracle Database. Being open-source, SQLite source code can be modified as per the requirement of developers. It is also available for free use in both commercial and non-commercial projects.

SQLite runs without the need for a separate server process. Since no server is required for setting up SQLite, an SQLite database instance can be created just like opening a file. It is a C library that has direct access to its stored files. The whole database system is contained in a single library. It is integrated directly into the host program. It is fully compliant with ACID. It uses minimum system resources.

With the SQLite browser, we can directly manipulate the files in the SQLite database. It is open source. DB Browser is an example of an SQLite browser. It can be used for creating and editing database files. With the visual interface of a DB browser, you do not need to remember SQL commands. This feature makes it more flexible for new users as well as for developers.

In this guide, we will see how to install SQLite and SQLite Browser on an Ubuntu 20.04 system. There are two ways to install SQLite browser. In the first method, we will use the Ubuntu default repository. In the second method, we will use Snap's pre-packaged application. Let us move on to the installation process.

Prerequisites

  1. Basic knowledge of running commands on Linux terminal.
  2. A user account with administrative (‘sudo’) access.
  3. Access to the internet for fetching various files.

Installing SQLite from the Ubuntu 20.04 Official Repository

Step 1. Before proceeding to install SQLite, update the repository list with the below command:

sudo apt update

Step 2. Now we can continue to install SQLite using the command:

sudo apt install sqlite3


SQLite

Once the SQLite is installed, you can check the installed version by:

sqlite --version

Check SQLite version


Installing SQLite Browser on Ubuntu 20.04 from official repository

Step 1. To install SQLite browser, use the command:

sudo apt install sqlitebrowser


Installing SQLite Browser

Step 2. Now launch the SQLite browser from the command line using:

$ sqlitebrowser 

SQLite Browser

Or use the start menu and search for SQLite browser as shown here:

Installing SQLite Browser from the Snap Store

Step 1. On the Ubuntu system(>16.04), Snap comes pre-installed. In case you have a minimal installation of Ubuntu, you can install Snap from the snapd package as here:

sudo apt install snapd

If snapd is already installed, the above command will upgrade it if a new version is available.

Step 2. For updating the Snap’s path, either log out and log in again or restart your computer.

Step 3. Now after the Step 2, open a new terminal and install SQLite from Snap :

sudo snap install sqlitebrowser

Install SQLite Browser from snap store

The SQLite browser or DB browser has controls and wizards for various operations such as creating database and tables, importing and exporting tables from and to CSV files, executing SQL queries, and so on.

Using The SQLite Command Line Interface

Let us create a database in SQLite and populate it with some data. To create a database named as ‘spare’, run the command:

sqlite3 spare.db

SQLite command line interface

Here ‘spare ‘is the name of the database. The terminal prompt will now change to the SQLite shell as:

sqlite>

Using the .help command on the sqlite3 prompt we can list all the SQLite commands:

SQLite shell

To create a table for storing data, we need to specify its name and column in the create table statement. Basic syntax for creating a table is:

CREATE TABLE [IF NOT EXISTS] [database_name].table_name( col_1 datatype PRIMARY KEY(one or more columns), col_2 datatype, col_3 datatype, ... ... ... );

Using the above syntax, we have created the below table named as ‘parts’:

CREATE TABLE parts ( part_id INTEGER PRIMARY KEY, part_name TEXT NOT NULL,brand_name TEXT NOT NULL UNIQUE );


SQLite - creating a table

The part_id field is the primary key of the parts table. The UNIQUE constraint is used to specify a unique field in the table. 

To insert data into this table, we need the INSERT INTO statement. The syntax for the INSERT query is :

INSERT INTO TABLE_NAME (col_1, col_2, col_3,...col_N)  VALUES (val_1, val_2, val_3,...val_N);  

Let’s insert some data in our ‘parts’ table:

INSERT INTO parts (part_id,part_name,brand_name) VALUES (111, ‘screw’, ‘thunder’);

Insert data into a SQLite database

To check if the data is properly inserted, we will use the SELECT query to display it on the terminal. The syntax for SELECT query is:

SELECT col_1, col_2, . . . . col_N FROM table_name;

In our case the SELECT query will be:

SELECT part_id,part_name,brand_name from parts;

Query SQLite database

If you want to exit the sqlite3 prompt, just enter the .quit command.

Conclusion

That’s all. In this guide, we have learned to install SQLite on Ubuntu 20.04 OS. SQLite is a lightweight and fast database application. Try to build a mobile application using different databases and compare their performance with SQLite.

Share this page:

Suggested articles

0 Comment(s)

Add comment