Set Up Medusa Locally
In this guide, you'll learn how to set up your Cloud project on your machine to build features locally and publish them to Cloud.
How Local Development Works with Cloud#
A Cloud project is connected to a GitHub repository that holds your Medusa application's code. When you create a project from a starter, Cloud clones the starter's code into a repository in the GitHub account or organization you chose.
To customize your store, add features, or debug issues:
- Clone the project's repository to your machine.
- Run the Medusa application locally against resources on your machine, such as a local PostgreSQL database.
- Push your changes to the repository. Cloud then deploys them.
1. Clone the Repository#
Requires one of the roles:AdminDeveloperIf you imported your own GitHub repository and already have its code on your machine, skip to the next step.
- If you're in a different organization, switch to the organization that the project belongs to.
- Click Projects in the sidebar, then select your project to open its dashboard.
- Click the Repository button at the top right to open the GitHub repository in a new tab.
- On GitHub, click the Code button and copy the repository's URL.
- In your terminal, clone the repository and change into its directory:
Replace <repository-url> with the URL you copied, and <repository-name> with the name of the created directory.
2. Install Dependencies#
Starters are monorepos with the Medusa application in apps/backend and the storefront in apps/storefront. Install all packages' dependencies from the repository's root directory:
Starters use pnpm as their package manager by default. If you imported your own repository, use its package manager instead.
Use Yarn or npm instead of pnpm

3. Set Up Medusa Application's Environment Variables#
On Cloud, you manage an environment's variables from its dashboard, and Medusa sets its resources' variables, such as the database's, for you. Learn more in the Environment Variables guide.
Those variables hold secrets, so they aren't in your repository. For local development, copy the .env.template file or create a .env file in apps/backend that points to resources on your machine:
DATABASE_URL=postgres://localhost/medusa-local
REDIS_URL=redis://localhost:6379
JWT_SECRET=supersecret
COOKIE_SECRET=supersecret
STORE_CORS=http://localhost:8000
ADMIN_CORS=http://localhost:9000
AUTH_CORS=http://localhost:9000,http://localhost:8000
Replace the values to match your setup:
DATABASE_URL: The connection string of a local PostgreSQL database. Create the database first if it doesn't exist.REDIS_URL: The connection string of a local Redis instance. If you don't run Redis locally, remove this variable and Medusa falls back to in-memory modules.JWT_SECRETandCOOKIE_SECRET: Any random strings, different from your Cloud environments' values.STORE_CORS,ADMIN_CORS, andAUTH_CORS: The local URLs that can send requests to the Medusa application. Changehttp://localhost:8000if your storefront runs on another port.
Local resources isolate your development work, so you can seed and change data without affecting a deployed store.
To mirror a deployed environment locally, reuse its variables instead. Either export the variables from the environment's dashboard and rename the downloaded env.txt file to .env, or run the following command with the Cloud CLI:
Learn more in the variables command reference.
These variables point to the environment's database, Redis instance, and other resources, so local changes affect the deployed environment. Only reuse them for debugging.
4. Run the Medusa Application#
In apps/backend, run the migrations to prepare your local database. In starters, the migrations also seed initial store data, such as regions:
Then, start the Medusa application:
This runs the Medusa server at http://localhost:9000 and the Medusa Admin at http://localhost:9000/app.

The application restarts when you change code under the src directory. Admin customizations hot-reload without a browser refresh.
5. Create Medusa Admin User#
Your local database doesn't have your Cloud environments' users. To log in to the Medusa Admin locally, create an admin user in apps/backend:
Replace admin@medusajs.com and supersecret with the user's email and password, then use them to log in at http://localhost:9000/app.
6. Set Up Storefront's Environment Variables#
If your project doesn't have a storefront, skip to Publish Local Changes to Cloud.
The storefront needs a publishable API key, which you retrieve from the Medusa Admin, to send requests to the Medusa application. To set up the storefront's environment variables:
- In the repository's root directory, copy the storefront's
.env.templatefile to a.envfile. - Open the Medusa Admin at
http://localhost:9000/appand log in with the admin user you created. - Go to Settings -> Publishable API Keys, then copy the key of a publishable API key. Learn more in the Publishable API Keys Merchant Guide.
- Set the key and the Medusa application's URL in
apps/storefront/.env:
NEXT_PUBLIC_MEDUSA_PUBLISHABLE_KEY=pk_123...
NEXT_PUBLIC_MEDUSA_BACKEND_URL=http://localhost:9000
Use the variable names in the .env.template file, since the above are examples. Set the file's other variables based on your setup, such as your payment provider's keys.
mcloud variables list --reveal --dotenv --type storefront > .env in the storefront's directory, then change the Medusa application's URL and publishable API key to your local ones.7. Run the Storefront#
While the Medusa application runs, open a new terminal and start the storefront in apps/storefront:
Open the storefront at http://localhost:8000 to browse products and place orders.
Publish Local Changes to Cloud#
Cloud deploys your changes when you push them to the GitHub repository linked to your project:
- Push to the branch of a long-lived environment, such as the production environment, to deploy to that environment.
- Open a pull request to create a preview environment, where you can test your changes before merging them.
If your changes use new environment variables, add them to the Cloud environment before you push. Otherwise, the deployment runs without them.
Learn more in the Deployments guide.
Project Files#
Your Medusa application's project (apps/backend) has the following files and directories:

src#
This directory holds your customizations in the following subdirectories:
admin: Holds your admin dashboard's custom widgets and UI routes.api: Holds your custom API routes.jobs: Holds your scheduled jobs that run at a specified interval.links: Holds your module links that build associations between data models of different modules.modules: Holds your custom modules that implement custom business logic.scripts: Holds your custom scripts that you run with Medusa's CLI tool.subscribers: Holds your event listeners that run asynchronously when an event is emitted.workflows: Holds your custom workflows that you can run from anywhere in your application.
medusa-config.ts#
This file holds your Medusa configurations, such as your PostgreSQL database configurations.
.medusa#
The .medusa directory holds types and other files that Medusa generates when you run the build command. Don't modify or commit its files. Learn more in the Automatically Generated Types guide.
Configure Medusa Application#
Your Medusa application comes with a basic configuration for development. To fix configuration issues, such as CORS, or change the defaults, refer to the Medusa Configuration guide.
Troubleshooting#
If you run into an error while setting up or running the Medusa application, refer to these guides:
If you can't find your error, open a GitHub issue.
Next Steps#
After setting up your project locally, you can:
- Build features with your AI agent. Learn how to set it up in the Setting Up AI Agents guide.
- Find guides for backend, admin, and storefront development in the Development Resources.
- Update Medusa to benefit from the latest features and fixes.