How to Install and Configure n8n: A Guide to Setting Up n8n with Docker and Local Node.js
n8n Automation Node.js Docker SQLite PostgreSQL MySQL
To install n8n, you can follow these steps, and yes, it requires a database for storing workflows, executions, and other data. By default, SQLite is used, but you can also configure it to use a PostgreSQL or MySQL database for production environments.
1. Install n8n with Docker (Recommended)
This is the easiest way to set up n8n as it includes everything you need in one container, including the database.
-
Step 1: Clone the n8n GitHub repository:
git clone https://github.com/n8n-io/n8n.git cd n8n -
Step 2: Make sure you have Docker and Docker Compose installed on your machine.
-
Step 3: Run the following command to start n8n with Docker:
docker-compose upThis will start n8n, and the app will be available on
http://localhost:5678. -
Step 4: Open your browser and navigate to
http://localhost:5678to start using n8n.
This setup automatically handles the database part. You can customize the database to use PostgreSQL or MySQL by adjusting the
docker-compose.yml
file.
2. Install n8n Locally (Node.js)
If you prefer not to use Docker, you can install n8n directly on your machine.
-
Step 1: Install Node.js (>=14.15.0) and npm if you don’t already have them. You can install them from nodejs.org.
-
Step 2: Install n8n globally via npm:
npm install n8n -g -
Step 3: Run n8n:
n8n -
Step 4: Open your browser and go to
http://localhost:5678to access the n8n interface.
3. Database Configuration
By default, n8n uses SQLite for local development, but you can change the database to PostgreSQL or MySQL for production environments.
To configure the database:
- Step 1: Create a
.envfile in your root directory and add the following environment variables:
For PostgreSQL:
DB_TYPE=postgresdb
DB_POSTGRESDB_HOST=localhost
DB_POSTGRESDB_PORT=5432
DB_POSTGRESDB_DATABASE=n8n
DB_POSTGRESDB_USER=postgres
DB_POSTGRESDB_PASSWORD=yourpassword
For MySQL:
DB_TYPE=mysql
DB_MYSQLDB_HOST=localhost
DB_MYSQLDB_PORT=3306
DB_MYSQLDB_DATABASE=n8n
DB_MYSQLDB_USER=root
DB_MYSQLDB_PASSWORD=yourpassword
- Step 2: Restart n8n after adding the configuration.
4. Accessing the n8n UI
Once n8n is running, you can access the web UI at:
http://localhost:5678
You can now start creating workflows and automating processes!