SQLite is a lightweight cross-platform relational database engine. It is widely known for its efficiency and its ability to be connected with various programming languages. SQLite is released under an OpenSource license, so it’s free to use. In this tutorial, I will show you how to install and use SQLite on Ubuntu 20.04, the same procedure will work on the upcoming Ubuntu 22.04 version too. Let’s start.
Update the OS
Before we proceed with the installation, it is always a recommended step to run the update to resolve any dependency issues and get the latest versions of all of the packages. Fire up the terminal and update your Ubuntu 20.04.
$sudo apt update
As soon as the update is completed, you will know when the prompt returns.
Installing SQLite
Now go ahead and install the SQLite3 package through the following:
$sudo apt install sqlite3
Once you get this output, this means that the installation has been successfully completed.
Installing the SQLite browser
Now that the database engine is installed on your machine, you need a management tool to operate on it. For this guide, we will install the de facto tool i.e., SQLite Browser. Go ahead and type this into the terminal to start the installation:
$sudo apt install sqlitebrowser
During the installation, the terminal will ask you that after installation additional 58.5 MB of disk space will be utilized, do you want to continue? If you don’t have enough disk space, feel free to abort the installation at this step otherwise proceed.
Depending on your Internet connection speed, this process will take some time.
Once you get the prompt back, the installation is complete.
With this output, the installations are complete. You are now ready to use SQLite on your Ubuntu 20.04 machine.
Using the SQLite Browser
Now when you open up the applications drawer, you will see the DB Browser listed there
If it is not showing up in the front, just type “DB Browser” in the search box above and it will show up.
Clicking on the icon will open up the DB Browser, which looks like this:
Creating a test database in SQLite
With the GUI, it is a pretty intuitive process for creating a database and the tables within. Click on the “New Database” button in the upper left, right below “File”.
A dialog will open asking you about your desired location for the database file. It will also ask you to select a unique name for the database file.
For the purposes of this tutorial let’s name it “test”. And click save.
Creating a table
Now you will be prompted to define your database table. You can create it either by SQL or viva the “Add Field” option in the GUI.
For the purposes of this training let’s name the table as “Students”. Let’s create a table where we store a student’s details such as their roll number, their first name, last name, phone number and address. The table definition and the SQL will look like as such:
When you click on “OK” the table will be created. And you will see it in the browser as well under the “Database Structure” tab.
Adding Data
You can add Data to this table via both the GUI and SQL. Let’s see how to do it via the GUI. Click on “Browse Data” and then hit “New Record” button
Since, there is currently no data in the table, you will see the view as in the screenshot above. Clicking on new record will insert a row below the “Filter” row and will allow you to enter data like Excel spreadsheets.
Querying data in SQlite
Now that we have some data in the table, let’s write an SQL Query to see what data is available. You can write queries in the text box in the “Execute SQL” tab. Navigate to it and type the following to see all of the data available in the “Students” table.
Select * From Students
What this query is doing, is it is pulling all of the data in the “Students” table for you. Type this and click on the highlighted button.
This will execute the query and return all of the data.
Congratulations, you have successfully installed SQLite on your Ubuntu 20.04 machine, created a test database with a sample table, entered some data, and learned how to query it. You are ready to use SQLite with your projects.
Uninstalling SQLite Browser
For whatever reason if you are done with your project and you don’t want SQLite on your machine anymore, you can easily uninstall it as well. Fire up the terminal and execute this to first remove the SQLite Browser:
$sudo apt-get remove sqlitebrowser
With this output, the browser has been uninstalled.
Uninstalling SQLite
In order to uninstall the SQLite database application itself, you need to run a similar command:
$sudo apt-get remove sqlite3
With this, you have removed SQLite, its browser, and all of its packages from your machine.
Conclusion
In this post, I have given you detailed steps and instructions to completely install, use and uninstall the SQLite database on your Ubuntu 20.04 machine. If you run into any issues while following these steps feel free to drop a comment below and I’ll gladly help you out.
If you are looking for detailed instructions for installing and using MySQL on Ubuntu 20.04. check out this post:
[How to set up the latest MySQL on Ubuntu 20.04]
If you have any other queries or concerns, feel free to initiate a conversation below. I always try to get back to people reaching out.