How to Install Svelte: Quick Setup Guide
To install
Svelte, first ensure you have Node.js installed, then run npm create svelte@latest my-app in your terminal to create a new project. After that, navigate into your project folder and run npm install to install dependencies, then npm run dev to start the development server.Syntax
Use the following commands to install and start a Svelte project:
npm create svelte@latest my-app: Creates a new Svelte project namedmy-app.cd my-app: Moves into the project folder.npm install: Installs all project dependencies.npm run dev: Starts the development server to preview your app.
bash
npm create svelte@latest my-app cd my-app npm install npm run dev
Example
This example shows how to create a new Svelte project and start the development server to see your app in the browser.
bash
npm create svelte@latest my-app cd my-app npm install npm run dev
Output
VITE v4.3.9 ready in 300 ms
➜ Local: http://localhost:5173/
➜ Network: use --host to expose
Common Pitfalls
Missing Node.js: Svelte requires Node.js; install it from nodejs.org before running commands.
Wrong directory: Always cd into your project folder before installing dependencies or running the dev server.
Old npm version: Use npm version 7 or higher for best compatibility.
Skipping npm install: This step is necessary to download all packages your project needs.
bash
npm create svelte@latest my-app # Wrong: running npm run dev outside project folder npm run dev # Correct: cd my-app npm install npm run dev
Quick Reference
| Command | Purpose |
|---|---|
| npm create svelte@latest my-app | Create new Svelte project |
| cd my-app | Enter project folder |
| npm install | Install dependencies |
| npm run dev | Start development server |
Key Takeaways
Install Node.js before starting with Svelte.
Use npm create svelte@latest to generate a new project.
Always run npm install inside your project folder before starting.
Use npm run dev to launch the development server and preview your app.
Check your terminal output for the local URL to open your app in a browser.