How to Install ClickHouse on Debian 12 or 11 Linux

ClickHouse is an open-source columnar database management system that allows for real-time data analysis and uses SQL queries. Installing it on Debian can enhance your data processing capabilities. It is developed by Yandex, a popular technology company for online analytical processing (OLAP).

This DBMS is used to generate analytic reports in real-time for non-aggregated data and can generate reports from petabytes of raw data without any significant latency.

Prerequisites

  • Debian server or desktop
  • User with sudo privileges.
  • Basic knowledge of Linux terminal.
  • Internet Connection

Step 1: Update Debian Packages

Open your Debian 11 or 12 terminal screen and then run the system update command given below to update the package list.

sudo apt update

However, if you want, can upgrade the packages by running :

sudo apt upgrade

Step 2: Import the GPG key

Well, the ClickHouse is already available through the default repository of both Debian 12 and 11 but the version we get to install will be the older one. Therefore, we add the official repository of ClickHouse manually but before that let’s add the GPG key used to sign the packages of ClickHouse by its developers. We need it because then only our system could verify the packages we are getting, are from the source as they were released by its developers and have not been modified by anyone in between.

GNUPGHOME=$(mktemp -d)
sudo GNUPGHOME="$GNUPGHOME" gpg --no-default-keyring --keyring /usr/share/keyrings/clickhouse-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 8919F6BD2B48D754
sudo rm -rf "$GNUPGHOME"
sudo chmod +r /usr/share/keyrings/clickhouse-keyring.gpg

Step 3: Add ClickHouse Repository

In this step, we add the officially issued repository of ClickHouse by its developers for Debian-based Linux. We are doing this because the packages to install this DBMS are not the latest through the system repo of Debian. Hence, in your command terminal run the given command:

echo "deb [arch=amd64 signed-by=/usr/share/keyrings/clickhouse-keyring.gpg] https://packages.clickhouse.com/deb stable main" | sudo tee \
/etc/apt/sources.list.d/clickhouse.list

After adding the repository, it is important to run the system update command again to rebuild the APT cache.

sudo apt update

Add Clickhouse repository on Debian 11 or 12

Step 3: Installing ClickHouse on Debian 11 or 12

Now, we can install the latest version of ClickHouse on our Debian operating system using the APT package manager. Here is the command to get it.

Install ClickHouse server, client, and common files:

sudo apt install clickhouse-server clickhouse-client clickhouse-common-static
Install Clickhouse on Debian 11 or 12

Step 4: Start and Enable ClickHouse Service

Once the installation is completed, let’s start the ClickHouse service and also enable it to make sure it starts automatically with system boot or in case of a service crash.

Start ClickHouse service:

sudo systemctl start clickhouse-server

Enable the service to start on boot:

sudo systemctl enable clickhouse-server

Check the service status:

sudo systemctl start clickhouse-server
Check clickhouse service status

Step 5: Verify Installation

To verify the ClickHouse is working let’s connect to its client which by default uses localhost.

clickhouse-client

You should now be connected to the ClickHouse interactive shell.

Connect Clickhouse client

Step 6. Create a database and table

After logging into the server using the client, let’s have an example on- how to create a database and table in the ClickHouse Database server.

Create Database:

CREATE DATABASE IF NOT EXISTS myfirstdb

To create a Table.

Let’s say you want to create a Table name – myfirsttable in Database myfirstdb, the command will be:

CREATE TABLE myfirstdb.myfirsttable
(
 user_id UInt32,
 message String,
 timestamp DateTime,
 metric Float32
)
ENGINE = MergeTree()
PRIMARY KEY (user_id, timestamp)

The above command will create a MergeTree table with four columns:

user_id: it is used to assign a 32-bit unsigned integer
message: a String data type, which replaces types like VARCHAR, BLOB, CLOB, and others from other database systems
timestamp: a DateTime value to represent time
metric: a 32-bit floating point number

Let’s Insert some data into our created Table:

INSERT INTO myfirstdb.myfirsttable (user_id, message, timestamp, metric) VALUES
(101, 'Hello, MyFirst Database!', now(), -1.0 ),
(102, 'Yesterday the database was not here', yesterday(), 1.41421 ),
(102, 'I have installed it today', today(), 2.718 ),
(101, 'smallest chunks of data read', now() + 5, 3.14159 )

To see if the data has been inserted into the table successfully or not.

SELECT * FROM myfirstdb.myfirsttable

Uninstall ClikHouse from Debian 12 or 11 (optional)

Run the given command to completely remove the Database system from your Debian system along with all its data.

sudo apt autoremove --purge clickhouse-server clickhouse-client

Conclusion

You have successfully installed ClickHouse on Debian. This setup enables you to manage large volumes of data efficiently. To know more about this Database system, follow the official documentation.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.