UbuntuUbuntu Based

How To Install DuckDB on Ubuntu 24.04 LTS

Install DuckDB on Ubuntu 24.04

In this tutorial, we will show you how to install DuckDB on Ubuntu 24.04 LTS. DuckDB is a powerful, open-source, in-memory SQL database management system designed for fast analytical processing. It offers a unique combination of simplicity, performance, and flexibility, making it an attractive choice for data analysts and developers alike. DuckDB’s ability to process complex queries on large datasets efficiently has made it increasingly popular in the data analytics community.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of DuckDB on Ubuntu 24.04 (Noble Numbat). You can follow the same instructions for Ubuntu 22.04 and any other Debian-based distribution like Linux Mint, Elementary OS, Pop!_OS, and more as well.

Prerequisites

  • A server running one of the following operating systems: Ubuntu and any other Debian-based distribution like Linux Mint.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • At least 2 GB of RAM and 10 GB of free disk space.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • An active internet connection. You’ll need an internet connection to download the necessary packages and dependencies.
  • An Ubuntu 24.04 system with root access or a user with sudo privileges.

Install DuckDB on Ubuntu 24.04 LTS Noble Numbat

Step 1. Updating the Package Repository.

To ensure a smooth installation process, it is essential to update your system packages to their latest versions. Open a terminal and execute the following commands:

sudo apt update
sudo apt upgrade

The apt update command refreshes the package list, while apt upgrade installs the available updates. This step helps resolve any dependency issues and provides access to the latest security patches and bug fixes.

Step 2. Installing Dependencies.

DuckDB requires several dependencies to be installed on your system. To install them, run the following command:

sudo apt install git g++ cmake ninja-build libssl-dev

Step 3. Installing DuckDB on Ubuntu.

With the dependencies installed, you can now download the DuckDB source code from its official GitHub repository. Use the following command to clone the repository:

git clone https://github.com/duckdb/duckdb.git

Navigate to the DuckDB directory using the following command:

cd duckdb

Now, you can build DuckDB from the source code using CMake and Ninja. Execute the following commands:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release -G Ninja ..
ninja

These commands will create a new “build” directory, navigate into it, and generate the build files using CMake. The -DCMAKE_BUILD_TYPE=Release flag ensures that DuckDB is built with optimizations for better performance. Finally, the ninja command will compile the source code and create the DuckDB executable.

If you encounter any issues during the build process, ensure that you have installed all the required dependencies and have sufficient disk space and memory available.

After successfully building DuckDB, you can install the DuckDB Command-Line Interface (CLI) using the following command:

sudo ninja install

To verify the installation, run the following command:

duckdb --version

If the installation was successful, you should see the DuckDB version number displayed in the terminal.

Step 4. Using DuckDB with Python.

DuckDB seamlessly integrates with Python, allowing you to leverage its powerful analytical capabilities within your Python scripts. To use DuckDB with Python, you need to install the DuckDB Python client.

First, ensure that you have Python and pip installed on your system. Then, run the following command to install the DuckDB Python client:

pip install duckdb

Once installed, you can start using DuckDB in your Python scripts. Here’s a basic example:

import duckdb

con = duckdb.connect('example.db')
con.execute("CREATE TABLE users (id INTEGER, name VARCHAR)")
con.execute("INSERT INTO users VALUES (1, 'John'), (2, 'Alice')")
result = con.execute("SELECT * FROM users")

for row in result.fetchall():
    print(row)

This example demonstrates how to connect to a DuckDB database, create a table, insert data, and execute a SELECT query to retrieve the results.

Congratulations! You have successfully installed DuckDB. Thanks for using this tutorial for installing DuckDB on the Ubuntu 24.04 LTS system. For additional help or useful information, we recommend you check the DuckDB website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button