
DuckDB, an in-process SQL database, is widely appreciated for its efficiency and simplicity, making it ideal for data analysis and testing workflows. Installing DuckDB locally empowers developers and data engineers to test queries, perform offline analysis, and develop applications in a self-contained environment. This guide walks through the local installation of DuckDB using common methods like Docker and programming language-specific package managers.
Why Install DuckDB Locally?
Local installations provide flexibility for:
- Testing and debugging: Experiment with queries in a controlled, isolated setup.
- Development environments: Build and test integrations with your tools without relying on external databases.
- Offline capabilities: Analyze data in restricted network environments.
Installing DuckDB Using Docker
Docker offers a containerized approach for running DuckDB, ensuring consistent setups across environments.
Prerequisites: Ensure Docker is installed on your system.
To check, run: docker --version
Pull the DuckDB image
docker pull duckdb/duckdb
Run DuckDB in a container
docker run -it --rm duckdb/duckdb
This launches an interactive DuckDB shell.
Using volumes (optional): To access local files within the container, map a directory:
docker run -it --rm -v $(pwd):/data duckdb/duckdb
This method ensures isolation, eliminating compatibility issues with your host environment.
Installing DuckDB in Python (pip)
Python’s ecosystem makes it seamless to integrate DuckDB for analytical tasks.
Install DuckDB
pip install duckdb
Verify installation
Open a Python shell and run:
import duckdb
print(duckdb.__version__)
Basic usage example
import duckdb
con = duckdb.connect()
con.execute("CREATE TABLE test (id INTEGER, name STRING)")
con.execute("INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob')")
print(con.execute("SELECT * FROM test").fetchall())
Installing DuckDB in Node.js (npm)
If you are working with JavaScript, DuckDB’s npm package integrates smoothly into your applications.
Install DuckDB
npm install duckdb
Verify installation
Run the following script:
const duckdb = require('duckdb');
const db = new duckdb.Database(':memory:');
db.run("CREATE TABLE test (id INTEGER, name STRING)", function(err) {
if (err) throw err;
db.all("SELECT * FROM test", function(err, rows) {
if (err) throw err;
console.log(rows);
});
});
Installing DuckDB for Ruby (gem)
DuckDB’s Ruby gem is a convenient way to use it in Ruby applications.
Install the gem
gem install duckdb
Verify installation
Run this script to confirm:
require 'duckdb'
con = DuckDB::Database.open.connect
con.execute("CREATE TABLE test (id INTEGER, name STRING)")
con.execute("INSERT INTO test VALUES (1, 'Alice'), (2, 'Bob')")
puts con.execute("SELECT * FROM test").to_a
Installing DuckDB in Java (Maven or Gradle)
Java developers can integrate DuckDB using Maven or Gradle for embedded database functionality.
Maven
Add the dependency to your pom.xml
:
<dependency>
<groupId>org.duckdb</groupId>
<artifactId>duckdb_jdbc</artifactId>
<version>0.8.1</version>
</dependency>
Refresh dependencies and verify by running:
import org.duckdb.DuckDBConnection;
import java.sql.Connection;
import java.sql.DriverManager;
public class Main {
public static void main(String[] args) throws Exception {
Connection conn = DriverManager.getConnection("jdbc:duckdb:");
conn.createStatement().execute("CREATE TABLE test (id INTEGER, name STRING)");
System.out.println("DuckDB installed successfully");
}
}
Gradle
Add this to your build.gradle
:
implementation 'org.duckdb:duckdb_jdbc:0.8.1'
Verify as shown in the Maven example.
Managing and Verifying Installations
- Check versions: After installation, ensure compatibility by verifying the version:
- Python:
python -m pip show duckdb
- Node.js:
npm list duckdb
- Ruby:
gem list | grep duckdb
- Java: Ensure your IDE recognizes the dependency.
- Python:
- Documentation: Familiarize yourself with DuckDB’s official documentation.
- Error handling: Test with a basic query to confirm functionality across all integrations.
Summary
Installing DuckDB locally offers unmatched flexibility for data analysis and development tasks. This guide outlined various installation methods, from Dockerized setups to language-specific integrations like pip, npm, gem, Maven, and Gradle. With these approaches, you can seamlessly incorporate DuckDB into your workflows and enjoy its simplicity and power.
Last Releases
- v1.2.2 Bugfix ReleaseThis is a bug fix release for various issues discovered after we released 1.2.1. There are no new major features, just bug fixes. Database files created by DuckDB versions all… Read more: v1.2.2 Bugfix Release
- v1.2.1 Bugfix ReleaseThis is a bug fix release for various issues discovered after we released 1.2.0. There are no new major features, just bug fixes. Database files created by DuckDB versions all… Read more: v1.2.1 Bugfix Release
- DuckDB 1.2.0 “Histrionicus”This release of DuckDB is named “Histrionicus” after the good-looking Harlequin duck (Histrionicus Histrionicus) that inhabits “cold fast moving streams in North America, Greenland, Iceland and eastern Russia”. Please also… Read more: DuckDB 1.2.0 “Histrionicus”