How to Install and Use DuckDB on Ubuntu 26.04 and 24.04

Share

To install DuckDB on Ubuntu 26.04 or 24.04, run curl -fsSL https://install.duckdb.org | sh after installing the prerequisites below. This official installer sets up the DuckDB 2.0 LTS command-line client for your user account.

DuckDB lets you use SQL to analyze local files such as CSV and Parquet from your terminal without starting a database service. Try it with a small sales file, save the rows in a database, and export the totals. If a command fails, leave a comment with the error or contact us.

Before you begin
  • Use Ubuntu 26.04 LTS or 24.04 LTS, a Bash terminal, and an internet connection. The installer supports 64-bit Intel and AMD (x86_64) and 64-bit Arm (aarch64). Run uname -m to check.
  • The standard APT repositories for both releases lack a duckdb CLI package. The third-party DuckDB Snap is older than the current upstream LTS.
  • Use sudo for the Ubuntu prerequisites. Run the DuckDB installer and practice commands as your regular user.
Ubuntu terminal
sudo apt update && sudo apt install -y curl ca-certificates tar gzip

1. Install DuckDB on Ubuntu

Step 1. Run the official installer

Run this command to download DuckDB’s installer over HTTPS and pass it to sh. Use your regular account.

Ubuntu terminal
curl -fsSL https://install.duckdb.org | sh

The installer saves the binary at ~/.duckdb/cli/<version>/duckdb and makes the latest directory a symlink to that version. The command path you will use is ~/.duckdb/cli/latest/duckdb.

Step 2. Add DuckDB to your Bash PATH

The installer prints a PATH hint and leaves ~/.bashrc for you to edit. Open ~/.bashrc in a text editor and add this line once at the end. Bash expands $HOME inside double quotes.

~/.bashrc
export PATH="$HOME/.duckdb/cli/latest:$PATH"

Save the file, reload it in your Bash terminal, and verify which DuckDB you are running.

Ubuntu terminal
source ~/.bashrc
command -v duckdb
duckdb --version

Expect a path ending in .duckdb/cli/latest/duckdb and a version starting with v2.0. for this LTS series.

2. Query a CSV File with DuckDB

Step 1. Make a practice folder and CSV

Create a new folder under your home directory. Run the CSV block after pwd prints the new folder. Stay there for the rest of the exercise so all three files are easy to find.

Ubuntu terminal
demo_dir=$(mktemp -d "$HOME/duckdb-demo.XXXXXX") && cd "$demo_dir" && pwd
Ubuntu terminal
cat > sales.csv <<'CSV'
category,product,quantity,unit_price
Stationery,Notebook,3,4.50
Stationery,Pen,5,1.20
Kitchen,Mug,2,8.25
Kitchen,Towel,3,4.00
Kitchen,Mug,1,8.25
CSV

Each row records a product, the quantity sold and the price per unit. The new folder keeps the sample from replacing an existing sales.csv.

Step 2. Read the CSV in a temporary session

Start DuckDB without a database filename. This opens a temporary in-memory database.

Ubuntu terminal
duckdb

At the DuckDB prompt, read the CSV directly. read_csv detects the header and column types. Type .exit on its own line to return to Bash.

DuckDB prompt
SELECT * FROM read_csv('sales.csv');
.exit

You should see five rows. The CSV stays on disk. Any tables you create in this temporary database are discarded when the session ends.

3. Save the Sales Table and Reopen It

Step 1. Create a database file and import the rows

In Bash, pass a filename to the CLI. DuckDB opens it if it already exists or creates it in the practice folder.

Ubuntu terminal
duckdb sales.duckdb

At the DuckDB prompt, create a table from the CSV rows, then exit.

DuckDB prompt
CREATE TABLE sales AS
SELECT * FROM read_csv('sales.csv');
.exit

The database now holds its own copy of the sales rows. Later edits to sales.csv do not update this table.

Step 2. Reopen the file and check the totals

From Bash, reopen the same file.

Ubuntu terminal
duckdb sales.duckdb

At the DuckDB prompt, list the saved tables and sum quantity times unit price for each category. The decimal cast keeps the calculation in fixed-point arithmetic.

DuckDB prompt
SHOW TABLES;

SELECT category,
       SUM(quantity * CAST(unit_price AS DECIMAL(10, 2))) AS revenue
FROM sales
GROUP BY category
ORDER BY revenue DESC, category;

SHOW TABLES should list sales. The query should produce these two totals. Keep this session open for the export.

category     revenue
Kitchen        36.75
Stationery     19.50

4. Export the Summary to Parquet

Step 1. Write the query results to a file

Run the export in the open sales.duckdb session. Parquet is a column-oriented file format that preserves the result’s column types. Pick a different filename if you already have an export you want to keep.

DuckDB prompt
COPY (
    SELECT category,
           SUM(quantity * CAST(unit_price AS DECIMAL(10, 2))) AS revenue
    FROM sales
    GROUP BY category
    ORDER BY revenue DESC, category
) TO 'sales_summary.parquet' (FORMAT parquet);
.exit
Step 2. Read the Parquet file from Bash

Run a one-off query against the file you just exported.

Ubuntu terminal
duckdb -c "SELECT * FROM 'sales_summary.parquet';"

Expect the same two category totals. This command reads the Parquet file directly and exits without opening sales.duckdb.

Using DuckDB from Python

If you already use uv for Python projects, run uv add duckdb from the project folder. It adds the Python library so your code can use import duckdb.

5. Fix Common DuckDB Problems

Issue 1. Bash says duckdb: command not found

Check whether the executable runs by its full path. If it prints a version, check the PATH line in ~/.bashrc and reload that file in Bash. If the executable is missing, check the installer output for a download or extraction error.

Ubuntu terminal
"$HOME/.duckdb/cli/latest/duckdb" --version
Issue 2. DuckDB cannot find sales.csv or the sales table

Start DuckDB from the practice folder. Relative file paths are resolved from there. If SHOW TABLES; is empty, check whether you opened bare duckdb or created a different sales.duckdb in another directory.

Issue 3. A second terminal cannot acquire a lock

An open read-write CLI session holds a lock on sales.duckdb. If you try to open it for writing from a second terminal, exit the first session with .exit, then retry from the second.

6. Update or Uninstall DuckDB

Update with the same installer

Save your work and exit DuckDB before updating. If another tool reads your database file, check its DuckDB version before creating files with a new major release. DuckDB releases before 2.0 cannot read database files created with the 2.0 default storage format.

Ubuntu terminal
curl -fsSL https://install.duckdb.org | sh
duckdb --version

A newer download goes into its own version directory under ~/.duckdb/cli/. The installer retargets the latest symlink, so the same PATH line picks up the new binary. The installer follows the current stable release.

Uninstall the CLI and keep your data

Exit DuckDB and check what is in ~/.duckdb. Move any project files you saved there to a different folder before deleting it. With the default layout, deleting this directory removes the CLI, previous versions and downloaded DuckDB extensions stored there. Your .duckdb and .parquet files in project folders outside it are kept.

Ubuntu terminal
ls -la "$HOME/.duckdb"

The installer may also have created a link in ~/.local/bin. This command removes it only if it points to the installer’s default executable. The final line permanently deletes the DuckDB directory.

Ubuntu terminal
duckdb_link="$HOME/.local/bin/duckdb"
if [ -L "$duckdb_link" ] && [ "$(readlink -- "$duckdb_link")" = "$HOME/.duckdb/cli/latest/duckdb" ]; then
    rm -- "$duckdb_link"
fi
rm -r -- "$HOME/.duckdb"

Remove the PATH line you added to ~/.bashrc. Close the terminal and open a new one so it starts with the updated PATH.

Source: DuckDB’s official installer documentation