Course/Chapter 2/2. Local Installation (npm & Docker)
    beginner
    Chapter 2: Hosting n8n — Self-Hosted vs Cloud

    2. Local Installation (npm & Docker)

    Step-by-step guide to installing n8n locally.

    12m Lesson 2 of 5

    Setting up n8n locally is essential for learning, testing, and development. You have two main options: npm (Node.js) or Docker.

    Option 1: npm

    Requires Node.js 18+ installed on your machine. This is the simplest approach for quick experimentation.

    Option 2: Docker

    Docker provides isolation and easier cleanup. Recommended if you already use Docker in your development workflow.

    Data Persistence

    By default, n8n stores data in an SQLite database in the `~/.n8n` directory. This includes your workflows, credentials, and execution history.

    Code Examples

    Install with npm
    bash
    # Prerequisites: Node.js 18+
    node --version  # Should be 18.x or higher
    
    # Install n8n globally
    npm install n8n -g
    
    # Start n8n
    n8n start
    
    # Access at http://localhost:5678
    Install with Docker
    bash
    # Pull and run n8n
    docker run -it --rm \
      --name n8n \
      -p 5678:5678 \
      -v n8n_data:/home/node/.n8n \
      n8nio/n8n
    
    # With environment variables
    docker run -it --rm \
      --name n8n \
      -p 5678:5678 \
      -e N8N_BASIC_AUTH_ACTIVE=true \
      -e N8N_BASIC_AUTH_USER=admin \
      -e N8N_BASIC_AUTH_PASSWORD=securepassword \
      -v n8n_data:/home/node/.n8n \
      n8nio/n8n

    Pro Tips

    • 💡Always use a named Docker volume (-v n8n_data:...) to persist your data between container restarts
    • 💡Set N8N_BASIC_AUTH to protect your local instance if it's accessible on your network

    Comprehension Quiz

    Answer 2 of 2 correctly to unlock lesson completion.

    1. What is the minimum Node.js version required for n8n?

    2. Why should you use a named Docker volume when running n8n?

    Pass the quiz above to unlock lesson completion