CentOS

How to Install SQLite on CentOS 8

We have often heard of MySQL, MariaDB, and PostgreSQL, but not about SQLite. SQLite is a small, lightweight, yet powerful SQL Database Manager. In this post, we will learn all about what SQLite is and how we can install SQLite on CentOS 8 operating system.

SQLite does not run as a system service like other DBMS. So, it is known as a self-contained database manager that does not work like other DBMS, such as MySQL, PostgreSQL, and MariaDB.

SQLite is built based on the C language to make it an efficient and fast database management system. Its binaries in all significant operating systems are available like Windows, Linux, and macOS, so it is a multi-platform and open-source application.

Installation of SQLite on CentOS 8

SQLite is available in the default package manager of the CentOS 8 operating system and easily downloadable and installable from there.

But before that, it is an excellent practice to make sure that your system is up-to-date. To upgrade the installed packages and dependencies, execute the command typed below:

$ sudo dnf upgrade

After upgrading, make sure that the epel-release is enabled as well on your CentOS 8 operating system. If it is not enabled, you can execute the command below to enable the epel-release:

$ sudo dnf install epel-release

Once the epel-release is enabled, execute the upgrade command once again to make the packages up-to-date:

$ sudo dnf upgrade

Once the system is up-to-date and ready, we can install SQLite on CentOS 8 by executing the single command.

For installing the latest and stable version of SQLite from the DNF package manager, execute the command:

$ sudo dnf install sqlite

SQLite will be downloaded and installed in a few moments.

Once the installation of SQLite on CentOS 8 is completed, you can confirm the installation by executing the command given below:

$ sqlite3 --version

It is verified that SQLite’s version 3.26 is successfully installed on CentOS 8 operating system. Now, let’s get started with SQLite in CentOS 8 and learn about its primary usage.

Getting Started With SQLite on CentOS 8

For getting started with SQLite on CentOS 8, simply execute the “sqlite3” command in the terminal of CentOS 8 to get into the shell of SQLite:

$ sqlite3

Once you are logged in the SQLite shell, it is recommended you first take a look at the Help page of SQLite to get know-how about the SQLite commands.

sqlite> .help

We will try to run some basic commands to create a database, a table and insert some data into a table in SQLite.

How to Create a Database in SQLite

Since the SQLite database is stored as a file, we can create an SQLite database using the “sqlite3” command.

While logging into the SQLite shell, we need to mention the name of the database we want to use. If there is no database with the provided name, a new database file will be created. If we do not provide any database name, a temporary in-memory database will be created. Note: the temporary in-memory database will be terminated when the SQLite session will be closed.

For example, to create “testdb” database in SQLite, the command would go like this:

$ sqlite3 testdb

After executing the above command, a new database with the name “testdb” will be created in the current working directory. You will be immediately logged into the SQLite session. You can execute the command “.databases” to know which database is connected:

sqlite> .databases

You can see in the screenshot above that the database file is created in the /home/user directory, and the SQLite session is connected to the “testdb”. So, you can also provide the path along with the database name to create and log in to the database session.

After building the database, the next step is to make a table.

How to Make a Table in SQLite

Since SQLite is an SQL-based database management system, the CREATE TABLE command is used for creating a table.

For example, to create a table with the name of “test_student” in the SQLite, the CREATE TABLE command would be like this:

sqlite> CREATE TABLE test_student(
   ...> name String,
   ...> age Int
   ...> );

A new “test_table” will be created, and you can verify the creation of the table in SQLite by executing the “.tables” command:

sqlite> .tables

You can see and witness in the output that the “test_student” table is listed as a result of the “.tables” command.

Now, let’s see how to put data in an SQLite table.

Inserting Data Into a Table in SQLite

Insertion of data in an SQLite table is as easy as doing it in any other SQL-based database management system. Insert data into the “test_student” table; the INSERT INTO command will be used.

For example, we want to add some new students into the “test_student” table so that the command would go like this:

sqlite> INSERT INTO test_student(name, age)
   ...> VALUES ('John', 16),
   ...> ('Bob', 18),
   ...> ('Ivan', 14);

How to View a Table Data in SQLite

Now, to view the current state of the table, use the SELECT * FROM table_name command:

sqlite> SELECT * FROM test_student;

You can see in the output that the three inserted rows are displayed.

Conclusion

In this post, we have learned to install SQLite database management system in the CentOS 8 operating system. Installing the SQLite engine on CentOS 8 is as easy as installing any other package from the DNF package repository on CentOS 8.

Moreover, in this simple starter’s guide, we have learned the primary usage and performed some beginner-level commands like creating a database in SQLite, creating a table, and inserting data into a table in the SQLite database management system.

About the author

Shehroz Azam

A Javascript Developer & Linux enthusiast with 4 years of industrial experience and proven know-how to combine creative and usability viewpoints resulting in world-class web applications. I have experience working with Vue, React & Node.js & currently working on article writing and video creation.