|
1
|
import { Prerequisites, CodeTab, CodeTabs } from "docs-ui" |
|
2
|
|
|
3
|
export const metadata = { |
|
4
|
title: `${pageNumber} Install Medusa`, |
|
5
|
} |
|
6
|
|
|
7
|
# {metadata.title} |
|
8
|
|
|
9
|
In this chapter, you'll learn how to install and run a Medusa application. |
|
10
|
|
|
11
|
## Get Started with AI Agents |
|
12
|
|
|
13
|
If you're an AI agent, or a human that wants to get started quickly with an AI agent, run the following prompt in your agent: |
|
14
|
|
|
15
|
```bash title="Prompt" |
|
16
|
Fetch https://docs.medusajs.com/start and create an ecommerce store with Medusa Cloud |
|
17
|
``` |
|
18
|
|
|
19
|
The AI agent will set up Medusa locally, deploy it to [Cloud](!cloud!), and help you build your custom commerce features. |
|
20
|
|
|
21
|
--- |
|
22
|
|
|
23
|
## Get Started with Cloud |
|
24
|
|
|
25
|
[Cloud](!cloud!) is the quickest way to get started with Medusa. With Cloud, you can deploy your ecommerce applications in minutes. Benefit from features like: |
|
26
|
|
|
27
|
- Zero-configuration deployments |
|
28
|
- Automatic scaling |
|
29
|
- Storefront hosting |
|
30
|
- GitHub integration |
|
31
|
|
|
32
|
And [more features](!cloud!#features). |
|
33
|
|
|
34
|
[Sign up with Cloud](http://cloud.medusajs.com/signup?utm_source=docs&utm_medium=website&utm_campaign=cloud_signup_guide) to start a free trial and create your first Medusa project in minutes. You don't need to enter payment details to start the trial. |
|
35
|
|
|
36
|
--- |
|
37
|
|
|
38
|
## Create Medusa Application Locally |
|
39
|
|
|
40
|
Medusa is open-source, so you can also install and run it locally on your machine. This is a great option if you want to have more control over your development environment. |
|
41
|
|
|
42
|
A Medusa application is made up of a Node.js server and a Vite admin dashboard. You can optionally install the [Next.js Starter Storefront](!resources!/nextjs-starter) either while installing the Medusa application or at a later point. |
|
43
|
|
|
44
|
<Prerequisites items={[ |
|
45
|
{ |
|
46
|
text: "Node.js v20.19.0+ or v22.12.0+ (LTS versions only). If you choose to install the Next.js Starter Storefront, make sure to use Node v24 LTS or lower.", |
|
47
|
link: "https://nodejs.org/en/download" |
|
48
|
}, |
|
49
|
{ |
|
50
|
text: "Git CLI tool", |
|
51
|
link: "https://git-scm.com/downloads" |
|
52
|
}, |
|
53
|
{ |
|
54
|
text: "PostgreSQL installed and running", |
|
55
|
link: "https://www.postgresql.org/download/" |
|
56
|
} |
|
57
|
]} /> |
|
58
|
|
|
59
|
To create a Medusa application, use the `create-medusa-app` command: |
|
60
|
|
|
61
|
<Note title="Tip"> |
|
62
|
|
|
63
|
Consider using `yarn` or `pnpm` as your package manager for quicker installations and better performance. `npm` installations are generally slower. |
|
64
|
|
|
65
|
</Note> |
|
66
|
|
|
67
|
<CodeTabs group="npm2yarn"> |
|
68
|
<CodeTab label="yarn" value="yarn"> |
|
69
|
|
|
70
|
```bash |
|
71
|
yarn dlx create-medusa-app@latest my-medusa-store |
|
72
|
# npx create-medusa-app@latest my-medusa-store --use-yarn |
|
73
|
``` |
|
74
|
|
|
75
|
</CodeTab> |
|
76
|
<CodeTab label="pnpm" value="pnpm"> |
|
77
|
|
|
78
|
```bash |
|
79
|
pnpm dlx create-medusa-app@latest my-medusa-store |
|
80
|
# npx create-medusa-app@latest my-medusa-store --use-pnpm |
|
81
|
``` |
|
82
|
|
|
83
|
</CodeTab> |
|
84
|
<CodeTab label="npm" value="npm"> |
|
85
|
|
|
86
|
```bash |
|
87
|
npx create-medusa-app@latest my-medusa-store |
|
88
|
``` |
|
89
|
|
|
90
|
</CodeTab> |
|
91
|
</CodeTabs> |
|
92
|
|
|
93
|
Where `my-medusa-store` is the name of the project's directory, and the PostgreSQL database created for the project will be of the name `medusa-my-medusa-store`. When you run the command, you'll be asked whether you want to install the Next.js Starter Storefront. |
|
94
|
|
|
95
|
<Note> |
|
96
|
|
|
97
|
To customize the default installation behavior, such as specify a database URL, refer to the [create-medusa-app reference](!resources!/create-medusa-app). |
|
98
|
|
|
99
|
</Note> |
|
100
|
|
|
101
|
After answering the prompts, the command installs the Medusa application in a monorepository. The backend (with the admin dashboard) is installed in the `apps/backend` directory of the monorepository. |
|
102
|
|
|
103
|
If you chose to install the storefront with the Medusa application, the storefront is installed in the monorepository under the `apps/storefront` directory. |
|
104
|
|
|
105
|
 |
|
106
|
|
|
107
|
### Successful Installation Result |
|
108
|
|
|
109
|
Once the installation finishes successfully, the Medusa application will run at `http://localhost:9000`. |
|
110
|
|
|
111
|
The Medusa Admin dashboard also runs at `http://localhost:9000/app`. The installation process opens the Medusa Admin dashboard in your default browser to create a user. You can later log in with that user. |
|
112
|
|
|
113
|
If you also installed the Next.js Starter Storefront, it'll be running at `http://localhost:8000`. |
|
114
|
|
|
115
|
You can stop the servers for the Medusa application and Next.js Starter Storefront by exiting the installation command. To run the server for the Medusa application again, refer to the [Run Medusa Application in Development](#run-medusa-application-in-development) section. |
|
116
|
|
|
117
|
 |
|
118
|
|
|
119
|
### Troubleshooting Installation Errors |
|
120
|
|
|
121
|
If you ran into an error during your installation, refer to the following troubleshooting guides for help: |
|
122
|
|
|
123
|
1. [create-medusa-app troubleshooting guides](!resources!/troubleshooting/create-medusa-app-errors). |
|
124
|
2. [CORS errors](!resources!/troubleshooting/cors-errors). |
|
125
|
3. [Errors with pnpm](!resources!/troubleshooting/pnpm). |
|
126
|
4. [All troubleshooting guides](!resources!/troubleshooting). |
|
127
|
|
|
128
|
If you can't find your error reported anywhere, please open a [GitHub issue](https://github.com/medusajs/medusa/issues/new/choose). |
|
129
|
|
|
130
|
<Feedback |
|
131
|
question="Did you install Medusa successfully?" |
|
132
|
negativeQuestion="What errors or issues did you run into?" |
|
133
|
showDottedSeparator={false} |
|
134
|
positiveBtn="Yes" |
|
135
|
negativeBtn="No" |
|
136
|
/> |
|
137
|
|
|
138
|
--- |
|
139
|
|
|
140
|
## Run Medusa Application in Development |
|
141
|
|
|
142
|
To run the Medusa application in development, change to the `backend` application's directory and run the following command: |
|
143
|
|
|
144
|
```bash npm2yarn |
|
145
|
npm run dev |
|
146
|
``` |
|
147
|
|
|
148
|
This runs your Medusa server at `http://localhost:9000`, and the Medusa Admin dashboard `http://localhost:9000/app`. |
|
149
|
|
|
150
|
 |
|
151
|
|
|
152
|
<Note title="Tip"> |
|
153
|
|
|
154
|
For details on starting and configuring the Next.js Starter Storefront, refer to [the Next.js Starter Storefront documentation](!resources!/nextjs-starter). |
|
155
|
|
|
156
|
</Note> |
|
157
|
|
|
158
|
The application will restart if you make any changes to code under the `src` directory, except for admin customizations which are hot reloaded, providing you with a seamless developer experience without having to refresh your browser to see the changes. |
|
159
|
|
|
160
|
--- |
|
161
|
|
|
162
|
## Start Building with AI Agents |
|
163
|
|
|
164
|
Medusa provides [agentic skills](https://github.com/medusajs/medusa-agent-skills) to assist you in learning and building with Medusa using AI agents like Claude Code. |
|
165
|
|
|
166
|
{/* TODO add cloud related stuff? */} |
|
167
|
|
|
168
|
### Build Features with AI Agents |
|
169
|
|
|
170
|
Medusa provides a set of skills to help you build features with AI agents. You can build features like product reviews, wishlists, quote requests, and more with AI agents. |
|
171
|
|
|
172
|
This skill is ideal for all developers and non-technical users who want to build features with the help of AI agents. |
|
173
|
|
|
174
|
<CodeTabs group="agent-skills"> |
|
175
|
<CodeTab label="Claude Code" value="claude-code"> |
|
176
|
|
|
177
|
```bash |
|
178
|
claude # start claude code |
|
179
|
/plugin marketplace add medusajs/medusa-agent-skills |
|
180
|
/plugin install medusa-dev@medusa |
|
181
|
|
|
182
|
# Ask Claude Code to build features with the medusa-dev plugin. For example: |
|
183
|
Help me implement a product reviews feature. Authenticated customers can add reviews. Admin users can view and approve or reject reviews from the dashboard |
|
184
|
``` |
|
185
|
|
|
186
|
</CodeTab> |
|
187
|
<CodeTab label="Other AI Agents" value="other-agents"> |
|
188
|
|
|
189
|
```bash |
|
190
|
npx skills add medusajs/medusa-agent-skills |
|
191
|
# choose the following skills: |
|
192
|
# - building-with-medusa |
|
193
|
# - building-admin-dashboard-customizations |
|
194
|
# - building-storefronts |
|
195
|
# - db-generate |
|
196
|
# - db-migrate |
|
197
|
# - new-user |
|
198
|
|
|
199
|
# Ask your AI agent to build features with the installed skills. For example: |
|
200
|
Help me implement a product reviews feature. Authenticated customers can add reviews. Admin users can view and approve or reject reviews from the dashboard |
|
201
|
``` |
|
202
|
|
|
203
|
</CodeTab> |
|
204
|
</CodeTabs> |
|
205
|
|
|
206
|
By following this flow, you can quickly bring your business ideas to life with the help of AI agents, without having to worry about the underlying code or technical details. |
|
207
|
|
|
208
|
### Learn Medusa Development with AI Agents |
|
209
|
|
|
210
|
If you're a Medusa beginner and you want to learn Medusa development with the help of an AI agent, install and use the `learn-medusa` skills: |
|
211
|
|
|
212
|
<CodeTabs group="agent-skills"> |
|
213
|
<CodeTab label="Claude Code" value="claude-code"> |
|
214
|
|
|
215
|
```bash |
|
216
|
claude # start claude code |
|
217
|
/plugin marketplace add medusajs/medusa-agent-skills |
|
218
|
/plugin install learn-medusa@medusa |
|
219
|
|
|
220
|
# then use the following prompt to start learning: |
|
221
|
I want to learn Medusa. |
|
222
|
``` |
|
223
|
|
|
224
|
</CodeTab> |
|
225
|
<CodeTab label="Other AI Agents" value="other-agents"> |
|
226
|
|
|
227
|
```bash |
|
228
|
npx skills add medusajs/medusa-agent-skills |
|
229
|
# choose the following skill: |
|
230
|
# - learning-medusa |
|
231
|
|
|
232
|
# then use the following prompt in your AI agent to start learning: |
|
233
|
I want to learn Medusa. |
|
234
|
``` |
|
235
|
|
|
236
|
</CodeTab> |
|
237
|
</CodeTabs> |
|
238
|
|
|
239
|
This starts the interactive learning experience where you'll learn Medusa concepts step-by-step by building a brands feature, similar to the [Brands tutorial](../customization/custom-features/page.mdx). You will: |
|
240
|
|
|
241
|
1. Create a Brand Module with API routes to manage brands. |
|
242
|
2. Link brands to products to associate products with brands. |
|
243
|
3. Customize the Medusa Admin dashboard to allow admin users to manage brands. |
|
244
|
|
|
245
|
By the end, you'll have a solid understanding of Medusa's architecture and how to build custom features. |
|
246
|
|
|
247
|
--- |
|
248
|
|
|
249
|
## Create Medusa Admin User |
|
250
|
|
|
251
|
Aside from creating an admin user in the admin dashboard, you can create a user with Medusa's CLI tool. |
|
252
|
|
|
253
|
Run the following command in your Medusa application's directory (`apps/backend`) to create a new admin user: |
|
254
|
|
|
255
|
```bash npx2yarn |
|
256
|
npx medusa user -e admin@medusajs.com -p supersecret |
|
257
|
``` |
|
258
|
|
|
259
|
Replace `admin@medusajs.com` and `supersecret` with the user's email and password respectively. |
|
260
|
|
|
261
|
You can then use the user's credentials to log into the Medusa Admin application. |
|
262
|
|
|
263
|
--- |
|
264
|
|
|
265
|
## Project Files |
|
266
|
|
|
267
|
Your Medusa application's project (`apps/backend`) will have the following files and directories: |
|
268
|
|
|
269
|
 |
|
270
|
|
|
271
|
### src |
|
272
|
|
|
273
|
This directory is the central place for your custom development. It includes the following sub-directories: |
|
274
|
|
|
275
|
- `admin`: Holds your admin dashboard's custom [widgets](../fundamentals/admin/widgets/page.mdx) and [UI routes](../fundamentals/admin/ui-routes/page.mdx). |
|
276
|
- `api`: Holds your custom [API routes](../fundamentals/api-routes/page.mdx) that are added as endpoints in your Medusa application. |
|
277
|
- `jobs`: Holds your [scheduled jobs](../fundamentals/scheduled-jobs/page.mdx) that run at a specified interval during your Medusa application's runtime. |
|
278
|
- `links`: Holds your [module links](../fundamentals/module-links/page.mdx) that build associations between data models of different modules. |
|
279
|
- `modules`: Holds your custom [modules](../fundamentals/modules/page.mdx) that implement custom business logic. |
|
280
|
- `scripts`: Holds your custom [scripts](../fundamentals/custom-cli-scripts/page.mdx) to be executed using Medusa's CLI tool. |
|
281
|
- `subscribers`: Holds your [event listeners](../fundamentals/events-and-subscribers/page.mdx) that are executed asynchronously whenever an event is emitted. |
|
282
|
- `workflows`: Holds your custom [flows](../fundamentals/workflows/page.mdx) that can be executed from anywhere in your application. |
|
283
|
|
|
284
|
### medusa-config.ts |
|
285
|
|
|
286
|
This file holds your [Medusa configurations](../configurations/medusa-config/page.mdx), such as your PostgreSQL database configurations. |
|
287
|
|
|
288
|
### .medusa |
|
289
|
|
|
290
|
The `.medusa` directory holds types and other files that are generated by Medusa when you run the `build` command. Don't modify any files or commit them to your repository. |
|
291
|
|
|
292
|
See [Automatically Generated Types](../fundamentals/generated-types/page.mdx) for more information on generated types. |
|
293
|
|
|
294
|
--- |
|
295
|
|
|
296
|
## Configure Medusa Application |
|
297
|
|
|
298
|
By default, your Medusa application is equipped with the basic configuration to start your development. |
|
299
|
|
|
300
|
If you run into issues with configurations, such as CORS configurations, or need to make changes to the default configuration, refer to the [Medusa Configuration](../configurations/medusa-config/page.mdx) guide. |
|
301
|
|
|
302
|
--- |
|
303
|
|
|
304
|
## Update Medusa Application |
|
305
|
|
|
306
|
Refer to the [Update Medusa](../update/page.mdx) guide to learn how to update your Medusa project. |
|
307
|
|
|
308
|
--- |
|
309
|
|
|
310
|
## Next Steps |
|
311
|
|
|
312
|
In the next chapters, you'll learn about the architecture of your Medusa application, then learn how to customize your application to build custom features. |