Configure gcx
You can configure gcx with a configuration file or using environment variables.
- A configuration file can store multiple contexts, which makes it easier to switch between Grafana instances. Check the configuration file reference documentation for details on all available configuration options.
- Environment variables describe a single context, so they work best in CI environments. Refer to Configure
gcxwith environment variables for more information.
Understand the gcx configuration file in use
Run gcx config check to display the configuration file currently in use.
gcx stores its configuration in a YAML file. Configuration is prioritized in this order:
- If the
--configflag is set, then that file will be loaded. No other location will be considered. - If the
$XDG_CONFIG_HOMEenvironment variable is set, then it will be used:$XDG_CONFIG_HOME/gcx/config.yaml - If the
$HOMEenvironment variable is set, then it will be used:$HOME/.config/gcx/config.yaml - If the
$XDG_CONFIG_DIRSenvironment variable is set, then it will be used:$XDG_CONFIG_DIRS/gcx/config.yaml
Define contexts
gcx supports multiple contexts so you can switch between instances. By default, it uses the default context.
To configure the default context:
gcx config set contexts.default.grafana.server http://localhost:3000
# Set org-id when using OSS/Enterprise - skip when targeting Grafana Cloud
gcx config set contexts.default.grafana.org-id 1
# Authenticate with a service account token
gcx config set contexts.default.grafana.token service-account-token
# Or alternatively, use basic authentication
gcx config set contexts.default.grafana.user admin
gcx config set contexts.default.grafana.password adminTo create another context, use the same pattern:
gcx config set contexts.staging.grafana.server https://staging.grafana.example
gcx config set contexts.staging.grafana.org-id 1Note that in these examples, default and staging are the context names.
Useful commands
Use these commands to check the configuration:
gcx config checkList existing contexts:
gcx config list-contextsSwitch to a different context:
gcx config use-context stagingSee the entire configuration:
gcx config viewConfigure gcx with environment variables
Every supported environment variable is listed in our reference documentation.
Since gcx connects to Grafana through the REST API, you must configure authentication credentials. At minimum, set the Grafana URL and organization ID:
GRAFANA_SERVER='http://localhost:3000' GRAFANA_ORG_ID='1' gcx config checkDepending on your authentication method, also set one of the following:
- If you use a Grafana service account (recommended), set a token.
- If you use basic authentication, set a username and a password.
After you configure authentication, you can start using gcx.
If you want to persist this configuration, create a context.


