Medusa CLI
The Medusa CLI is a command-line tool that provides essential commands for managing your Medusa commerce application. It handles development workflows, database operations, builds, and user management.Installation
The Medusa CLI is installed as part of the@medusajs/cli package:
Usage
Once installed, you can use themedusa command in your terminal:
Available Commands
The Medusa CLI provides the following commands:Development & Build
medusa develop- Start the development server with file watchingmedusa start- Start the production servermedusa build- Build your Medusa project for production
Database Operations
medusa db:setup- Create database, run migrations, and sync linksmedusa db:create- Create the databasemedusa db:migrate- Run pending migrationsmedusa db:migrate:scripts- Run migration scriptsmedusa db:rollback [modules...]- Rollback migrations for specified modulesmedusa db:generate [modules...]- Generate migration files for modulesmedusa db:sync-links- Sync database schema with defined links
Project Setup
medusa new [root] [starter]- Create a new Medusa project
User Management
medusa user- Create a new user or invitation
Plugin Development
medusa plugin:build- Build plugin for publishingmedusa plugin:develop- Start plugin development in watch modemedusa plugin:publish- Publish plugin to local registrymedusa plugin:add [plugin_names...]- Add plugins from local registrymedusa plugin:db:generate- Generate migrations for plugin modules
Utilities
medusa exec [file] [args..]- Run a function defined in a filemedusa codemod <codemod-name>- Run automated code transformationsmedusa telemetry- Enable or disable anonymous usage data collection
Global Options
The following options are available for all commands:--verbose- Turn on verbose output--no-color- Turn off colored output--json- Turn on JSON logger format-h,--help- Show help information-v,--version- Show CLI and Medusa version
Version Information
To check the CLI version and Medusa version in your project:Project Detection
Most commands (exceptmedusa new) must be run inside a Medusa project directory. The CLI detects a Medusa project by checking for @medusajs/medusa or @medusajs/cli in your package.json dependencies.
If you run a command outside of a Medusa project, you’ll see: