docs/sources/as-code/observability-as-code/grafana-cli/grafanactl/_index.md
grafanactl CLI{{< admonition type="caution" >}}
grafanactl is being deprecated, and we're bringing all our learning and experience into the new, improved CLI tool gcx. The grafanactl repository in GitHub will be archived on June 1, 2026.
To migrate from grafanactl to gcx, search-and-replace grafanactl with gcx. For grafanactl resources serve, use gcx dev serve instead.
{{< /admonition >}}
The grafanactl command-line tool allows you to authenticate, manage multiple environments, and perform administrative tasks through the Grafana REST API, all from the terminal. It's available for Grafana OSS, Enterprise, and Cloud.
grafanactlYou can install the project using one of the following supported methods:
Download the latest binary for your platform from the Releases page.
Prebuilt binaries are available for a variety of operating systems and architectures. Visit the latest release page, and scroll down to the Assets section.
To install the binary, follow the instructions below:
To build grafanactl from source you must:
git installedgo v1.24 (or greater) installedgo install github.com/grafana/grafanactl/cmd/grafanactl@latest
grafanactlYou can configure grafanactl in two ways: using environment variables or through a configuration file.
{{< admonition type="note" >}}
Configuration items may change depending on your set-up. For example, use org-id for self-managed Grafana, but use stack-id for Grafana Cloud.
{{< /admonition >}}
Grafana CLI communicates with Grafana via the REST API, which requires authentication credentials.
At a minimum, set the URL of your Grafana instance and the organization ID:
GRAFANA_SERVER='http://localhost:3000' GRAFANA_ORG_ID='1' grafanactl config check
Depending on your authentication method, you may also need to set:
To persist your configuration, consider creating a context.
Contexts allow you to easily switch between multiple Grafana instances.
By default, the CLI uses a context named default. To configure it use:
grafanactl config set contexts.default.grafana.server http://localhost:3000
grafanactl config set contexts.default.grafana.org-id 1
Authenticate with a service account token:
grafanactl config set contexts.default.grafana.token service-account-token
Or use basic authentication:
grafanactl config set contexts.default.grafana.user admin
grafanactl config set contexts.default.grafana.password admin
You can define additional contexts in the same way:
grafanactl config set contexts.staging.grafana.server https://staging.grafana.example
grafanactl config set contexts.staging.grafana.org-id 1
{{< admonition type="note" >}}
In these examples, default and staging are the names of the contexts.
{{< /admonition >}}
Grafana CLI stores its configuration in a YAML file. The CLI determines the configuration file location in the following order:
--config flag is provided, the specified file is used.$XDG_CONFIG_HOME is set:
$XDG_CONFIG_HOME/grafanactl/config.yaml$HOME is set:
$HOME/.config/grafanactl/config.yaml$XDG_CONFIG_DIRS is set:
$XDG_CONFIG_DIRS/grafanactl/config.yaml{{< admonition type="note" >}}
Use grafanactl config check to display the configuration file currently in use.
{{< /admonition >}}
Check the current configuration:
grafanactl config check
{{< admonition type="note" >}} This command is useful to troubleshoot your configuration. {{< /admonition >}}
List all available contexts:
grafanactl config list-contexts
Switch to a specific context:
grafanactl config use-context staging
View the full configuration:
grafanactl config view