2025-12-06

MedusaJS Step by Step Setup Guide

Overview

  • A step-by-step guide to using medusa-setup.sh to install and configure a MedusaJS commerce server.
  • Covers prerequisites, usage examples, environment configuration, systemd setup, basic troubleshooting and verification.

Prerequisites

  • A supported Linux VM (Ubuntu 20.04/22.04 recommended).
  • A user with sudo privileges.
  • Port 9000 (Medusa server) available, and optionally ports 80/443 if you plan to use nginx + certbot.
  • A running database (Postgres recommended) or allow the script to install one if supported.
  • Optional: Redis for job queues, and a reverse proxy (nginx) + certbot for HTTPS.

Security warning

  • Review scripts before running them. Avoid piping unknown scripts directly into bash on production systems.
  • Keep credentials and secrets out of command lines and public logs; prefer .env files or secret managers.

Quick install (recommended: run from cloned repo)

  1. Clone the repo: git clone https://github.com/gijoe707/setup-automation-scripts.git cd setup-automation-scripts
  2. Make the script executable: chmod +x medusa-setup.sh
  3. Run interactively: sudo ./medusa-setup.sh The script will prompt for required values (db host, user, password, domain, etc.).
git clone https://github.com/gijoe707/setup-automation-scripts.git
cd setup-automation-scripts
chmod +x medusa-setup.sh
sudo ./medusa-setup.sh

One-line (less secure) example — run from remote:

  • Warning: piping remote scripts to bash is risky. Only do if you trust the source.
curl -fsSL https://raw.githubusercontent.com/gijoe707/setup-automation-scripts/main/medusa-setup.sh | sudo bash -s -- --non-interactive

Non-interactive usage (example)

Export or supply environment variables the script accepts (example variable names; adjust to actual script):

export MEDUSA_VERSION="latest"
export DB_TYPE="postgres"
export DB_HOST="127.0.0.1"
export DB_PORT="5432"
export DB_NAME="medusa"
export DB_USER="medusa"
export DB_PASS="secure_password"
export REDIS_URL="redis://127.0.0.1:6379"
export ADMIN_EMAIL="admin@example.com"
export ADMIN_PASSWORD="adminpassword"
sudo ./medusa-setup.sh --non-interactive

Common command-line flags

  • –help : show help
  • –non-interactive : run without prompts (requires environment variables)
  • –dir /path/to/install : install Medusa project into a specific directory (Notes: exact flags depend on medusa-setup.sh. If you want, I can inspect the script and list exact flags.)

What the script typically does (step-by-step)

  1. Update the package index and install system packages (curl, git, build-essential).
  2. Install Node.js (recommended LTS) and Yarn or npm.
  3. Install and/or use medusa-cli to create or initialize a Medusa project.
  4. Install project dependencies (yarn install / npm install).
  5. Create or configure a .env file with DB, Redis and JWT/SECRET values.
  6. Run database setup and migrations (Medusa commands or custom SQL).
  7. Create a first admin user (seed or medusa-admin create).
  8. Configure systemd service to run medusa as a service (example: /etc/systemd/system/medusa.service).
  9. Optionally install nginx reverse-proxy and configure certbot for HTTPS.
  10. Start and enable services (systemctl enable –now medusa).

Systemd unit example

  • Example unit file (adjust paths & user): [Unit] Description=Medusa server After=network.target[Service] Type=simple User=medusa Group=medusa WorkingDirectory=/opt/medusa ExecStart=/usr/bin/node ./src/index.js Restart=on-failure EnvironmentFile=/opt/medusa/.env[Install] WantedBy=multi-user.target

Verification & basic tests

Troubleshooting (common issues)

  • Node version mismatch: ensure Node LTS is installed (v16+ or as required).
  • DB connection refused: confirm DB host/port, firewall, and credentials.
  • Migration errors: check DB permissions; run migrations manually and inspect stack trace.
  • Permission issues with systemd: ensure WorkingDirectory, ExecStart and user/group exist and are correct.
  • Ports in use: swap port or stop conflicting services.

Customizing the install

  • Install into a specific directory: set –dir or change working directory before running script.
  • Use an external DB: set DB_HOST/DB_PORT/DB_USER/DB_PASS and skip DB install steps.
  • Use Docker instead: If you prefer containerized deployments, consider a Docker Compose variant of the script (not included by default).

Examples (end-to-end)