Table of Contents
In this article, we will see how to install sqlite3 on Ubuntu 22.04 LTS (Jammy Jellyfish). SQLite is a free and open source C-language library that implements a high reliable and fast SQL database engine. It is so small and lightweight that it easily gets built on almost all mobiles phones and computers. Since it gets easily embedded in apps, it is used by millions of devices on various platforms. It is very commonly used as containers to transfer rich contents between number of systems.
Due to its serverless architecture, it is a preferred database engine by many software developers. SQLite3 is the third version of SQLite. One can also easily download and install SQLite3 on almost all the famous platforms. Here we will see how to install sqlite3 on Ubuntu 22.04 LTS based systems.
Why to use SQLite3
- Lightweight and Serverless: SQLite3 is a lightweight, serverless database engine. It does not require a separate server process to operate, making it a simple and efficient solution for applications that don't need the full power of a large database management system (DBMS).
- Self-contained: SQLite3 is self-contained, meaning it requires minimal support from the operating system or external libraries. This makes it easy to deploy, as there's no need to install and configure a separate database server.
- Zero Configuration: No setup or administration is needed. This can significantly simplify the development and deployment process, especially for small to medium-sized applications.
- Cross-Platform: SQLite3 works across all major operating systems (Windows, macOS, Linux, iOS, Android), making it a versatile choice for cross-platform development.
- Embedded Database: SQLite3 is often used as an embedded database for mobile applications, desktop software, and other systems that need an internal database to manage data without the overhead of connecting to a standalone database server.
- Transactional: SQLite3 supports ACID-compliant transactions (Atomicity, Consistency, Isolation, Durability), which is a crucial feature for maintaining data integrity.
- Readily Accessible: The entire database, which includes both the schema and the data, is stored in a single standard file. This simplicity facilitates easy backup, transfer, and analysis.
- Language Support: It offers bindings for a multitude of programming languages, making it accessible from various development environments.
- Suitable for Prototyping and Testing: Its ease of use and simplicity make SQLite3 an excellent choice for prototyping, testing, and small to medium-sized projects.
- Reliable and Mature: SQLite3 is a mature product with a focus on reliability and robustness. It’s widely used in the industry and has a proven track record.
- Open Source: It is open-source, which means it's free to use, even for commercial applications.
How to Install sqlite3 on Ubuntu 22.04 LTS (Jammy Jellyfish)
Also Read: 15 Best Steps to Simplify Your SSH configuration in Linux
Step 1: Prerequisites
a) You should have a running Ubuntu 22.04 LTS
Server.
b) You should have sudo
or root
access to run privileged commands.
c) You should have apt
or apt-get
utility available in your Server.
Step 2: Update Your Server
To ensure system security and stability, it is always important to first check for all latest available updates from default Ubuntu repo and install them by using sudo apt update && sudo apt upgrade
command as shown below.
cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade Hit:1 http://in.archive.ubuntu.com/ubuntu jammy InRelease Get:2 http://in.archive.ubuntu.com/ubuntu jammy-updates InRelease [119 kB] Hit:3 http://in.archive.ubuntu.com/ubuntu jammy-backports InRelease Get:4 http://security.ubuntu.com/ubuntu jammy-security InRelease [110 kB] Fetched 229 kB in 4s (60.4 kB/s) Reading package lists... Done Building dependency tree... Done Reading state information... Done 2 packages can be upgraded. Run 'apt list --upgradable' to see them. Reading package lists... Done Building dependency tree... Done Reading state information... Done Calculating upgrade... Done The following packages have been kept back: gjs libgjs0g 0 upgraded, 0 newly installed, 0 to remove and 2 not upgraded.
Step 3: Install sqlite3
In the next step, you can install sqlite3 from default Ubuntu repo by running sudo apt install sqlite3
command as shown below. This will download and install the package from repo along with all its required dependencies.
cyberithub@ubuntu:~$ sudo apt install sqlite3 Reading package lists... Done Building dependency tree... Done Reading state information... Done Suggested packages: sqlite3-doc The following NEW packages will be installed: sqlite3 0 upgraded, 1 newly installed, 0 to remove and 2 not upgraded. Need to get 768 kB of archives. After this operation, 1,873 kB of additional disk space will be used. Get:1 http://in.archive.ubuntu.com/ubuntu jammy-updates/main amd64 sqlite3 amd64 3.37.2-2ubuntu0.3 [768 kB] Fetched 768 kB in 3s (292 kB/s) Selecting previously unselected package sqlite3. (Reading database ... 209908 files and directories currently installed.) Preparing to unpack .../sqlite3_3.37.2-2ubuntu0.3_amd64.deb ... Unpacking sqlite3 (3.37.2-2ubuntu0.3) ... Setting up sqlite3 (3.37.2-2ubuntu0.3) ... Processing triggers for man-db (2.10.2-1) ...
Step 4: Check Version
You can check the installed version by using sqlite3 --version
command as shown below.
cyberithub@ubuntu:~$ sqlite3 --version 3.37.2 2022-01-06 13:25:41 872ba256cbf61d9290b571c0e6d82a20c224ca3ad82971edc46b29818d5dalt1
Step 5: Verify Installation
You can also verify the installation status by running dpkg -s sqlite3
command as shown below. To know more about dpkg
command, check 21+ Practical dpkg Command Examples for Linux Beginners.
cyberithub@ubuntu:~$ dpkg -s sqlite3 Package: sqlite3 Status: install ok installed Priority: optional Section: database Installed-Size: 1829 Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com> Architecture: amd64 Multi-Arch: foreign Version: 3.37.2-2ubuntu0.3 Depends: libc6 (>= 2.34), libreadline8 (>= 6.0), zlib1g (>= 1:1.2.0), libsqlite3-0 (= 3.37.2-2ubuntu0.3) Suggests: sqlite3-doc ........................................................
Step 6: Create a Database
To create a database, you can simply run sqlite3 <database_name>
command. For example, here we are creating a database called cyberithub.db
using sqlite3 cyberithub.db
query as shown below.
cyberithub@ubuntu:~$ sqlite3 cyberithub.db SQLite version 3.37.2 2022-01-06 13:25:41 Enter ".help" for usage hints. sqlite>
Step 7: Create a Table
To create a table, you can use create table
query. For our demo purpose, we are going to create a table called department
with two columns in it - dept_id
and dept_name
. We are also going to set all column as not null
to make sure it always contains a value.
sqlite> create table department(dept_id not null, dept_name not null);
Step 8: Insert Values
Now that table is created, let's insert some values in it. We are going to insert information of two departments as mentioned below:-
a) Department 1:-
Department ID - 103
Department Name - Accounts
b) Department 2:-
Department ID - 104
Department Name - Security
sqlite> insert into department values(103, "Accounts"); sqlite> insert into department values(104, "Security");
After entering records, let's verify it by running select * from department;
query as shown below.
sqlite> select * from department; 103|Accounts 104|Security
Step 9: Update a Value
You can also update a value in table. For example, we are updating department name of ID 104
from Security
to Infosec
using update department set dept_name="Infosec" where dept_id=104;
query as shown below.
sqlite> update department set dept_name="Infosec" where dept_id=104;
Then verify the changes by running select * from department;
query as shown below.
sqlite> select * from department; 103|Accounts 104|Infosec
Step 10: Delete a Table
If you are looking to delete a table then you can delete it by using drop table <table_name>
syntax. For example, here we are deleting table department
by using drop table department
command as shown below.
sqlite> drop table department;
Step 11: Uninstall sqlite3
Once you are done using sqlite3, you can also choose to uninstall sqlite3
from your system by using sudo apt remove sqlite3
command as shown below.
cyberithub@ubuntu:~$ sudo apt remove sqlite3 Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages will be REMOVED: sqlite3 0 upgraded, 0 newly installed, 1 to remove and 2 not upgraded. After this operation, 1,873 kB disk space will be freed. Do you want to continue? [Y/n] Y (Reading database ... 209914 files and directories currently installed.) Removing sqlite3 (3.37.2-2ubuntu0.3) ... Processing triggers for man-db (2.10.2-1) ...