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.
- 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). Rununame -mto check. - The standard APT repositories for both releases lack a
duckdbCLI package. The third-party DuckDB Snap is older than the current upstream LTS. - Use
sudofor the Ubuntu prerequisites. Run the DuckDB installer and practice commands as your regular user.
sudo apt update && sudo apt install -y curl ca-certificates tar gzip
On this page
Toggle1. Install DuckDB on Ubuntu
Run this command to download DuckDB’s installer over HTTPS and pass it to sh. Use your regular account.
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.
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.
export PATH="$HOME/.duckdb/cli/latest:$PATH"
Save the file, reload it in your Bash terminal, and verify which DuckDB you are running.
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
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.
demo_dir=$(mktemp -d "$HOME/duckdb-demo.XXXXXX") && cd "$demo_dir" && pwd
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.
Start DuckDB without a database filename. This opens a temporary in-memory database.
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.
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
In Bash, pass a filename to the CLI. DuckDB opens it if it already exists or creates it in the practice folder.
duckdb sales.duckdb
At the DuckDB prompt, create a table from the CSV rows, then exit.
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.
From Bash, reopen the same file.
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.
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
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.
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
Run a one-off query against the file you just exported.
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.
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
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.
"$HOME/.duckdb/cli/latest/duckdb" --version
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.
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
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.
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.
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.
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.
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.
Related Ubuntu Guides
- How to check your Ubuntu version
- How to install and use curl on Ubuntu
- How to install and use ClickHouse on Ubuntu
Source: DuckDB’s official installer documentation
