---
sidebar_position: 3
title: "DuckDB CLI: Installation and Connecting to MotherDuck"
sidebar_label: DuckDB CLI
description: Learn to connect and query databases using MotherDuck from the DuckDB CLI
hide_title: true
---

import Tabs from '@theme/Tabs';
import TabItem from '@theme/TabItem';
import DownloadLink from '@site/src/components/DownloadLink';
import Versions from '@site/src/components/Versions';

# DuckDB CLI

## Installation

:::note
MotherDuck currently supports DuckDB <Versions region="us-east-1" bound="max" />. In **US East (N. Virginia) -** `us-east-1`, MotherDuck is compatible with client versions <Versions region="us-east-1" bound="min" /> through <Versions region="us-east-1" bound="max" />. In **Europe (Frankfurt) -** `eu-central-1`, MotherDuck supports client versions <Versions region="eu-central-1" bound="min" /> through <Versions region="eu-central-1" bound="max" />.
:::

Download and install the DuckDB binary, depending on your operating system.

<Tabs groupId="os">
<TabItem value="wd" label="Windows">

1. Download the 64-bit Windows binary <DownloadLink region="us-east-1" bound="max" os="windows-amd64" />
2. Extract the Zip File.

</TabItem>
<TabItem value="mac" label="macOS">

The best way to install the CLI is to use the MotherDuck install script:

### Install with bash

```bash
curl -s https://install.motherduck.com | sh
```

</TabItem>
<TabItem value="linux" label="Linux">

1. Download the Linux binary:
    - For 64-bit, download the binary <DownloadLink region="us-east-1" bound="max" os="linux-amd64" />
    - For arm64/aarch64, download the binary <DownloadLink region="us-east-1" bound="max" os="linux-aarch64" />
2. Extract the Zip File.

</TabItem>
</Tabs>

For more information, see the [DuckDB installation documentation](https://duckdb.org/docs/installation/).

## Run the DuckDB CLI
Run DuckDB using the command:

```sh
./duckdb
```

By default, DuckDB will start with an in-memory database and any changes will not be persisted. To create a persistent database in the DuckDB CLI, you can specify a new filename as the first argument to the `duckdb` command.

Example:

```sh
./duckdb mydatabase.ddb
```

## Connect to MotherDuck

You can connect to MotherDuck by executing the following in DuckDB CLI. DuckDB will automatically download and load the signed MotherDuck extension.

```bash
ATTACH 'md:';
```

DuckDB will prompt you to authenticate with MotherDuck using your default web browser. Follow the instructions displayed in the terminal.

Test your MotherDuck connection using the following command. It will run in the cloud to display a list of your MotherDuck databases.

```sql
show databases;
```

Congrats 🎉 You are connected!

Now you can create databases and switch between them. You can also connect to your local DuckDB databases alongside databases hosted in MotherDuck, and interact with both!

To know more about how to persist your authentication credentials, read [Authenticating to MotherDuck](/key-tasks/authenticating-and-connecting-to-motherduck/authenticating-to-motherduck/authenticating-to-motherduck.md)

:::info
Note you can also connect to MotherDuck directly when starting DuckDB CLI by running the following command:

```bash
duckdb "md:"
```

:::

## Accessing the MotherDuck UI from the CLI:

You can access the MotherDuck UI from the CLI by executing the following command in the terminal:

```bash
duckdb -ui
```

If you are already in a DuckDB session, you can instead use `CALL start_ui();`

## Upgrading MotherDuck via the DuckDB CLI:

If you have previously installed the extension, but we have upgraded the service, you may need to run the `FORCE INSTALL` command as shown in the following example.

```sh
FORCE INSTALL motherduck
```
