﻿---
title: Get started with the Elastic CLI
description: Install and configure the Elastic CLI, connect to Elastic, and run your first command.
url: https://www.elastic.co/elastic/docs-builder/docs/4120/reference/elastic-cli/cli/quickstart
applies_to:
  - Elastic Cloud Serverless: Preview
  - Elastic Stack: Preview
---

# Get started with the Elastic CLI
The Elastic CLI lets you interact with Elastic services from the command line. Use it to explore APIs interactively, automate operations in scripts and CI/CD pipelines, or integrate Elastic operations into agent workflows.
By the end of this tutorial, you'll have installed and configured the CLI, connected it to an existing Elasticsearch deployment or Elastic Cloud Serverless project, and performed basic Elasticsearch operations.

## Before you begin

To install the CLI, you need to [install Node.js](https://nodejs.org/en/download) 22.12.0 or later. Node.js includes npm. Run `node --version` to check your installed version. The Elastic CLI is tested on Linux, macOS, and Windows, and the installation command is the same on every platform.
To follow the steps in this tutorial, you also need:
- The Elasticsearch endpoint for an existing cluster, regardless of deployment type, or an Elastic Cloud Serverless project. If you're not sure which endpoint to use, refer to [Find your Elasticsearch endpoint](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4120/solutions/elasticsearch-solution-project/search-connection-details).
- An API key with permission to view cluster information and list indices for the example operations in this tutorial. For your own use cases, grant only the permissions required by the APIs you plan to call.

<note>
  Elastic provides different API key types for different APIs. The Elastic CLI supports:
  - [Elasticsearch API keys](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4120/deploy-manage/api-keys/elasticsearch-api-keys) for accessing Elasticsearch and Kibana APIs in self-managed or Elastic Cloud on Kubernetes clusters and Elastic Cloud Enterprise or Elastic Cloud Hosted deployments.
  - [Serverless project API keys](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4120/deploy-manage/api-keys/serverless-project-api-keys) for accessing Elasticsearch and Kibana APIs within a specific Elastic Cloud Serverless project.
  - [Elastic Cloud API keys](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4120/deploy-manage/api-keys/elastic-cloud-api-keys) for managing organizations, Elastic Cloud Hosted deployments, and Elastic Cloud Serverless projects. In Serverless, a Cloud API key with **Cloud, Elasticsearch, and Kibana API** access and an appropriate role for each relevant project can also call project-level Elasticsearch and Kibana APIs. Elastic Cloud API keys can't authenticate against Elasticsearch or Kibana endpoints on Elastic Cloud Hosted.
  Refer to [Elastic API keys](https://docs-v3-preview.elastic.dev/elastic/docs-builder/docs/4120/deploy-manage/api-keys) to compare all available key types.
</note>


## Install the CLI

1. Install the CLI globally:
   ```bash
   npm install -g @elastic/cli
   ```
2. Verify that the `elastic` command is available:
   ```bash
   elastic --version
   ```
   The command prints the installed version. If it doesn't, follow the [installation guide](https://www.elastic.co/elastic/docs-builder/docs/4120/reference/elastic-cli/cli/installation) before continuing.


## Add a connection context

The following steps create a context named `quickstart` with the URL and credentials for your Elasticsearch connection.
If you use Bash or zsh, keep the API key out of your shell history by capturing it in a temporary variable:
```bash
read -rs ELASTIC_API_KEY
```

Paste your API key at the hidden prompt, press **Enter**, and create the context, replacing `<elasticsearch-url>` with your endpoint:
```bash
elastic config context add quickstart \
  --es-url "<elasticsearch-url>" \
  --es-api-key "$ELASTIC_API_KEY"
unset ELASTIC_API_KEY
```

The CLI stores the API key in your operating system's credential store when one is available. Otherwise, it stores the key in the configuration file and warns you.
API keys are sensitive credentials. The hidden prompt keeps the key out of your shell history, but its value might appear briefly in process listings when passed to `--es-api-key`. For other ways to provide and store secrets, refer to [external credentials](/elastic/docs-builder/docs/4120/reference/elastic-cli/cli/configuration#external-credentials).
Confirm that the context exists:
```bash
elastic config context list
```

The output includes `quickstart`. If this is your first context, the CLI also makes it the current context.

## Verify the connection

Check connectivity and authentication:
```bash
elastic --use-context quickstart status
```

A successful check displays a check mark next to the Elasticsearch endpoint, followed by its health status and node count. If the command reports an authentication or network error, verify the endpoint and API key in the [configuration guide](https://www.elastic.co/elastic/docs-builder/docs/4120/reference/elastic-cli/cli/configuration).

## Run your first command

Request information about Elasticsearch and return the response as JSON:
```bash
elastic --use-context quickstart --json es info
```

The response includes identifying information about the connected deployment or project, including its name and version.
List the indices that your API key can access:
```bash
elastic --use-context quickstart es cat indices
```

The output displays index health, status, document counts, and storage sizes in a table. You've now installed the CLI, configured a reusable connection, and run read-only Elasticsearch API operations.

## Next steps

- Explore available Elasticsearch commands with `elastic es --help`.
- Use the [Elastic CLI command reference](https://www.elastic.co/elastic/docs-builder/docs/4120/reference/elastic-cli/cli) to find commands, options, and input schemas.
- Use the [configuration guide](https://www.elastic.co/elastic/docs-builder/docs/4120/reference/elastic-cli/cli/configuration) to add Kibana to the context and learn about external credential resolvers.
- Follow [Connect to Elastic Cloud with the Elastic CLI](https://www.elastic.co/elastic/docs-builder/docs/4120/reference/elastic-cli/cli/manage-elastic-cloud) to configure a connection and run example operations against the Elastic Cloud API.