Installing SQLite#

Installation on Linux#

Installing SQLite on a Linux system is straightforward and can be accomplished using various package managers depending on your distribution. Below are the steps for installing SQLite on some of the most popular Linux distributions:

1. Installation on Ubuntu/Debian#

For Ubuntu and Debian-based distributions, you can install SQLite using the apt package manager. Follow these steps:

  1. Update Package List:

    • Before installing any new package, it's a good practice to update the package list to ensure you get the latest version available in the repositories.
sudo apt update
  1. Install SQLite:

    • Use the following command to install SQLite.
sudo apt install sqlite3
  1. Verify Installation:

    • Once the installation is complete, verify it by checking the SQLite version.
sqlite3 --version
  1. Install SQLite Development Libraries (Optional):

    • If you plan to develop applications that use SQLite, you might also want to install the SQLite development libraries.
sudo apt install libsqlite3-dev

2. Installation on Fedora#

For Fedora users, the dnf package manager can be used to install SQLite. Follow these steps:

  1. Update Package List:

    • Update your system's package list to ensure you get the latest version of packages.
sudo dnf check-update
  1. Install SQLite:

    • Use the following command to install SQLite.
sudo dnf install sqlite
  1. Verify Installation:

    • After the installation, check the SQLite version to verify it.
sqlite3 --version
  1. Install SQLite Development Libraries (Optional):

    • To develop applications using SQLite, install the development libraries.
sudo dnf install sqlite-devel

3. Installation on CentOS/RHEL#

For CentOS and RHEL distributions, the yum package manager is used. Here are the steps:

  1. Update Package List:

    • Update the package list to get the latest version of available packages.
sudo yum check-update
  1. Install SQLite:

    • Install SQLite using the following command.
sudo yum install sqlite
  1. Verify Installation:

    • Check the installed version of SQLite to ensure it is installed correctly.
sqlite3 --version
  1. Install SQLite Development Libraries (Optional):

    • If you need to develop SQLite applications, install the development libraries.
sudo yum install sqlite-devel

4. Building SQLite from Source#

In some cases, you might want to build SQLite from source to get the latest features or specific optimizations. Here are the steps to build SQLite from source:

  1. Install Build Tools:

    • Ensure you have the necessary build tools installed on your system.
sudo apt update
sudo apt install build-essential
  1. Download SQLite Source Code:

wget https://www.sqlite.org/2024/sqlite-autoconf-3390400.tar.gz
  1. Extract the Tarball:

    • Extract the downloaded tarball.
tar xvf sqlite-autoconf-3390400.tar.gz
  1. Compile and Install:

    • Navigate to the extracted directory, configure, compile, and install SQLite.
cd sqlite-autoconf-3390400
./configure
make
sudo make install
  1. Verify Installation:

    • Finally, verify the installation by checking the SQLite version.
sqlite3 --version

Post-Installation Steps#

  1. Creating a Database:

    • To create a new SQLite database, simply run the sqlite3 command followed by the desired database name. For example:
sqlite3 mydatabase.db
- This command creates a new database file named `mydatabase.db` and opens the SQLite shell.
  1. Opening the SQLite Shell:

    • If you want to open the SQLite shell without creating a new database, simply run:
sqlite3
  1. Basic SQLite Commands:

    • Within the SQLite shell, you can execute basic SQL commands to create tables, insert data, and query the database. Here are a few examples:
CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT, email TEXT);
INSERT INTO users (name, email) VALUES ('John Doe', 'john.doe@example.com');
SELECT * FROM users;

By following these steps, you will have SQLite installed and ready to use on your Linux system. Whether you're using it for local development, data analysis, or as an embedded database in your applications, SQLite provides a robust and easy-to-use solution.