---
title: Installation and authentication
description: >-
  Install mcms-cli and connect it to microCMS with environment variables or
  named profiles, then verify the active service before running commands.
sidebar:
  order: 2
noindex: false
---
## Requirements

- Node.js 20 or later
- a microCMS service to operate
- an API key with the permissions needed for your task

## Install mcms-cli

Install the package globally when you want the command to stay available on your machine.

```bash
npm install -g @mrmtsu/mcms-cli
microcms --help
```

To try it without a global install, use `npx`.

```bash
npx @mrmtsu/mcms-cli --help
```

## Use environment variables in CI

For CI and other non-interactive environments, provide the service domain and API key as environment variables.

```bash
export MICROCMS_SERVICE_DOMAIN=<service-domain>
export MICROCMS_API_KEY=<api-key>

microcms auth status --json
microcms config doctor --json
```

Avoid putting an API key directly in a command argument because it may remain in shell history or appear in the process list. Use environment variables, standard input, or the operating system keychain.

## Use a named profile

Named profiles make it easier to switch between microCMS services.

```bash
microcms auth profile add staging \
  --service-domain <service-domain> \
  --set-default \
  --json

printf '%s' '<api-key>' | \
  microcms auth login \
  --profile staging \
  --api-key-stdin \
  --json
```

`profile add` stores the service domain. Store the API key separately with `auth login`, which writes it to the operating system keychain.

You can also choose a profile through an environment variable.

```bash
export MICROCMS_PROFILE=staging
microcms auth status --json
```

## Verify the resolved configuration

Before a write, run both checks below. They show the selected profile, service domain, and credential source without printing the API key itself.

```bash
microcms auth status --json
microcms config doctor --json
```

## Related pages

- [mcms-cli overview](/en)
- [Safe content operations](/en/content-operations)
- [Command reference](/en/command-reference)
- [FAQ and troubleshooting](/en/faq)
