2022-05-26 23:06:25 +08:00
---
aliases:
2022-12-10 00:36:04 +08:00
- administration/cli/
2025-04-25 23:51:48 +08:00
description: Guide to using grafana server cli
2022-05-26 23:06:25 +08:00
keywords:
- grafana
- cli
2023-04-27 02:18:03 +08:00
- grafana cli
2022-05-26 23:06:25 +08:00
- command line interface
Explicitly set all front matter labels in the source files (#71548)
* Set every page to have defaults of 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration pages to have of 'Cloud', 'Enterprise', and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/enterprise-licensing pages to have 'Enterprise' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/organization-management pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/provisioning pages to have 'Enterprise' and 'Open source' labels
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/recorded-queries pages to have labels cloud,enterprise
* Set administration/roles-and-permissions/access-control pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set administration/stats-and-license pages to have labels cloud,enterprise
* Set alerting pages to have labels cloud,enterprise,oss
* Set breaking-changes pages to have labels cloud,enterprise,oss
* Set dashboards pages to have labels cloud,enterprise,oss
* Set datasources pages to have labels cloud,enterprise,oss
* Set explore pages to have labels cloud,enterprise,oss
* Set fundamentals pages to have labels cloud,enterprise,oss
* Set introduction/grafana-cloud pages to have labels cloud
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Fix introduction pages products
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set panels-visualizations pages to have labels cloud,enterprise,oss
* Set release-notes pages to have labels cloud,enterprise,oss
* Set search pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/audit-grafana pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-authentication pages to have labels cloud,enterprise,oss
* Set setup-grafana/configure-security/configure-authentication/enhanced-ldap pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-authentication/saml pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-database-encryption/encrypt-secrets-using-hashicorp-key-vault pages to have labels cloud,enterprise
* Set setup-grafana/configure-security/configure-request-security pages to have labels cloud,enterprise,oss
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/configure-team-sync pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set setup-grafana/configure-security/export-logs pages to have labels cloud,enterprise
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
* Set troubleshooting pages to have labels cloud,enterprise,oss
* Set whatsnew pages to have labels cloud,enterprise,oss
* Apply updated labels from review
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
---------
Signed-off-by: Jack Baldry <jack.baldry@grafana.com>
Co-authored-by: brendamuir <100768211+brendamuir@users.noreply.github.com>
Co-authored-by: Isabel <76437239+imatwawana@users.noreply.github.com>
2023-07-18 16:10:12 +08:00
labels:
products:
- enterprise
- oss
2025-04-25 23:51:48 +08:00
title: Grafana server CLI
2022-05-26 23:06:25 +08:00
weight: 400
---
2016-12-12 20:15:35 +08:00
2025-04-25 23:51:48 +08:00
# Grafana server CLI
2016-12-12 20:15:35 +08:00
2025-04-25 23:51:48 +08:00
Grafana server CLI is a small executable that's bundled with Grafana server.
2025-01-15 16:36:31 +08:00
You can run it on the same machine Grafana server is running on.
2025-04-25 23:51:48 +08:00
Grafana server CLI has `plugins` and `admin` commands, as well as global options.
2016-12-12 20:15:35 +08:00
2020-01-11 01:41:39 +08:00
To list all commands and options:
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```
2023-04-27 02:18:03 +08:00
grafana cli -h
2020-01-11 01:41:39 +08:00
```
2021-08-06 21:52:36 +08:00
2025-04-25 23:51:48 +08:00
## Run Grafana server CLI
2020-01-11 01:41:39 +08:00
2025-04-25 23:51:48 +08:00
To run Grafana server CLI, add the path to the Grafana binaries in your `PATH` environment variable.
2025-01-15 16:36:31 +08:00
Alternately, if your current directory is the `bin` directory, run `./grafana cli` .
Otherwise, you can specify full path to the binary.
For example, on Linux `/usr/share/grafana/bin/grafana` and on Windows `C:\Program Files\GrafanaLabs\grafana\bin\grafana.exe` , and run it with `grafana cli` .
2020-01-11 01:41:39 +08:00
2025-01-15 16:36:31 +08:00
{{< admonition type = "note" > }}
Some commands, such as installing or removing plugins, require `sudo` on Linux.
If you're on Windows, run Windows PowerShell as Administrator.
{{< / admonition > }}
2020-01-11 01:41:39 +08:00
## Grafana CLI command syntax
2025-04-25 23:51:48 +08:00
The general syntax for commands in Grafana server CLI is:
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli [global options] command [command options] [arguments...]
2020-01-11 01:41:39 +08:00
```
## Global options
2025-04-25 23:51:48 +08:00
Grafana server CLI allows you to temporarily override certain Grafana default settings. Except for `--help` and `--version` , most global options are only used by developers.
2020-01-11 01:41:39 +08:00
Each global option applies only to the command in which it is used. For example, `--pluginsDir value` does not permanently change where Grafana saves plugins. It only changes it for command in which you apply the option.
2025-04-25 23:51:48 +08:00
### Display Grafana server CLI help
2020-01-11 01:41:39 +08:00
`--help` or `-h` displays the help, including default paths and Docker configuration information.
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli -h
2020-01-11 01:41:39 +08:00
```
2025-04-25 23:51:48 +08:00
### Display Grafana server CLI version
2020-01-11 01:41:39 +08:00
2025-04-25 23:51:48 +08:00
`--version` or `-v` prints the version of Grafana server CLI currently running.
2020-01-11 01:41:39 +08:00
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli -v
2020-01-11 01:41:39 +08:00
```
### Override default plugin directory
`--pluginsDir value` overrides the path to where your local Grafana instance stores plugins. Use this option if you want to install, update, or remove a plugin somewhere other than the default directory ("/var/lib/grafana/plugins") [$GF_PLUGIN_DIR].
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --pluginsDir "/var/lib/grafana/devplugins" plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
### Override default plugin repo URL
`--repo value` allows you to download and install or update plugins from a repository other than the default Grafana repo.
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --repo "https://example.com/plugins" plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
### Override default plugin .zip URL
`--pluginUrl value` allows you to download a .zip file containing a plugin from a local URL instead of downloading it from the default Grafana source.
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --pluginUrl https://company.com/grafana/plugins/< plugin-id > -< plugin-version > .zip plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
### Override Transport Layer Security
**Warning:** Turning off TLS is a significant security risk. We do not recommend using this option.
`--insecure` allows you to turn off Transport Layer Security (TLS) verification (insecure). You might want to do this if you are downloading a plugin from a non-default source.
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --insecure --pluginUrl https://company.com/grafana/plugins/< plugin-id > -< plugin-version > .zip plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
### Enable debug logging
2020-05-18 16:23:12 +08:00
`--debug` or `-d` enables debug logging. Debug output is returned and shown in the terminal.
2020-01-11 01:41:39 +08:00
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --debug plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
2020-05-18 16:23:12 +08:00
### Override a configuration setting
2016-12-12 20:15:35 +08:00
2020-01-11 01:41:39 +08:00
`--configOverrides` is a command line argument that acts like an environmental variable override.
2016-12-12 20:15:35 +08:00
2020-11-03 19:09:49 +08:00
For example, you can use it to redirect logging to another file (maybe to log plugin installations in Grafana Cloud) or when resetting the admin password and you have non-default values for some important configuration value (like where the database is located).
2016-12-12 20:15:35 +08:00
2020-01-11 01:41:39 +08:00
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --configOverrides cfg:default.paths.log=/dev/null plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
2020-05-18 16:23:12 +08:00
### Override homepath value
2020-01-11 01:41:39 +08:00
Sets the path for the Grafana install/home path, defaults to working directory. You do not need to use this if you are in the Grafana installation directory when using the CLI.
2020-05-18 16:23:12 +08:00
2020-01-11 01:41:39 +08:00
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --homepath "/usr/share/grafana" admin reset-admin-password < new password >
2020-01-11 01:41:39 +08:00
```
2020-05-18 16:23:12 +08:00
### Override config file
2020-01-11 01:41:39 +08:00
2025-03-06 20:59:08 +08:00
`--config value` overrides the default location where Grafana expects the configuration file. Refer to [Configuration ](../setup-grafana/configure-grafana/ ) for more information about configuring Grafana and default configuration file locations.
2020-01-11 01:41:39 +08:00
**Example:**
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli --config "/etc/configuration/" admin reset-admin-password mynewpassword
2020-01-11 01:41:39 +08:00
```
## Plugins commands
2025-03-06 20:59:08 +08:00
Grafana CLI allows you to install, upgrade, and manage your Grafana plugins. For more information about installing plugins, refer to [plugins page ](../administration/plugin-management/ ).
2020-01-11 01:41:39 +08:00
All listed commands apply to the Grafana default repositories and directories. You can override the defaults with [Global Options ](#global-options ).
### List available plugins
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins list-remote
2020-01-11 01:41:39 +08:00
```
### Install the latest version of a plugin
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins install < plugin-id >
2020-01-11 01:41:39 +08:00
```
### Install a specific version of a plugin
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins install < plugin-id > < version >
2020-01-11 01:41:39 +08:00
```
### List installed plugins
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins ls
2020-01-11 01:41:39 +08:00
```
### Update all installed plugins
2021-08-06 21:52:36 +08:00
2020-01-11 01:41:39 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins update-all
2020-01-11 01:41:39 +08:00
```
### Update one plugin
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins update < plugin-id >
2020-01-11 01:41:39 +08:00
```
### Remove one plugin
```bash
2023-04-27 02:18:03 +08:00
grafana cli plugins remove < plugin-id >
2020-01-11 01:41:39 +08:00
```
## Admin commands
Admin commands are only available in Grafana 4.1 and later.
### Show all admin commands
```bash
2023-04-27 02:18:03 +08:00
grafana cli admin
2020-01-11 01:41:39 +08:00
```
2016-12-12 20:15:35 +08:00
### Reset admin password
2024-08-27 22:01:33 +08:00
`grafana cli admin reset-admin-password <new password>` resets the password for the admin user using the CLI. You might need to do this if you lose the admin password. By default, this command uses the default ID of the admin user, which is 1. If you know the ID of the admin user, you can use the `--user-id` flag to specify the user ID. If the `--user-id` flag is not specified and the command cannot find the admin user, it returns the list of current admin users' username and ID. From that list you can determine the ID of the admin user and run the command again with the `--user-id` flag.
2020-01-11 01:41:39 +08:00
If there are two flags being used to set the homepath and the config file path, then running the command returns this error:
2016-12-12 20:15:35 +08:00
2020-05-18 16:23:12 +08:00
> Could not find config defaults, make sure homepath command line parameter is set or working directory is homepath
2017-04-20 19:26:36 +08:00
2020-01-11 01:41:39 +08:00
To correct this, use the `--homepath` global option to specify the Grafana default homepath for this command:
```bash
2023-04-27 02:18:03 +08:00
grafana cli --homepath "/usr/share/grafana" admin reset-admin-password < new password >
2020-01-11 01:41:39 +08:00
```
2017-04-20 19:26:36 +08:00
2020-01-11 01:41:39 +08:00
If you have not lost the admin password, we recommend that you change the user password either in the User Preferences or in the Server Admin > User tab.
2017-04-20 19:26:36 +08:00
2025-03-06 20:59:08 +08:00
If you need to set the password in a script, then you can use the [Grafana User API ](../developers/http_api/user/#change-password ).
2020-01-13 23:38:52 +08:00
2024-08-27 22:01:33 +08:00
#### Reset admin password
If you installed Grafana using Homebrew, you can reset the admin password using the following command:
```bash
/opt/homebrew/opt/grafana/bin/grafana cli --config /opt/homebrew/etc/grafana/grafana.ini --homepath /opt/homebrew/opt/grafana/share/grafana --configOverrides cfg:default.paths.data=/opt/homebrew/var/lib/grafana admin reset-admin-password < new password >
```
2020-01-11 01:41:39 +08:00
### Migrate data and encrypt passwords
2017-04-20 19:26:36 +08:00
2020-01-11 01:41:39 +08:00
`data-migration` runs a script that migrates or cleans up data in your database.
2017-04-20 19:26:36 +08:00
2020-01-11 01:41:39 +08:00
`encrypt-datasource-passwords` migrates passwords from unsecured fields to secure_json_data field. Returns `ok` unless there is an error. Safe to execute multiple times.
2017-04-20 19:26:36 +08:00
2020-01-11 01:41:39 +08:00
**Example:**
2021-08-06 21:52:36 +08:00
2017-10-06 01:01:03 +08:00
```bash
2023-04-27 02:18:03 +08:00
grafana cli admin data-migration encrypt-datasource-passwords
2017-04-20 19:26:36 +08:00
```