DEV Community

Droid Ek
Droid Ek

Posted on

N8N Installation And Configuration

N8N Installation And Configuration

Setting Up a Self-Hosted n8n Automation Server on Ubuntu

This document outlines the end-to-end process of deploying the n8n automation platform on a fresh Ubuntu Server virtual machine using Docker. It also includes optional steps for adding a graphical user interface (GUI) for remote management.

Operating System: Ubuntu 24.04 LTS (Server Edition)

Part 1: Server and Prerequisite Setup

This section covers the initial server preparation, the optional installation of a desktop environment, and the mandatory installation of the Docker Engine.

Step 1.1: Virtual Machine (VM) Provisioning

An Ubuntu 24.04 LTS Server environment was chosen. This is a command-line-only operating system, which is lightweight and secure, making it ideal for server applications.
Enter fullscreen mode Exit fullscreen mode

Step 1.2: (Optional) Installing a Graphical Desktop Environment

The server operates via command line by default. For users who prefer a graphical interface for management, a desktop environment can be installed.

Note: This is generally not recommended for a production server as it consumes more system resources (RAM, CPU) and can increase the system's security attack surface.

Install the Ubuntu Desktop (GNOME): This command installs the standard graphical interface.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo apt update

sudo apt install ubuntu-desktop -y

Install a Remote Desktop Server (xrdp): To access the graphical desktop from another computer, a remote desktop protocol (RDP) server is required. xrdp is a common choice.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo apt install xrdp -y

Allow RDP through the firewall (if enabled): If you are using ufw (Uncomplicated Firewall), you must allow traffic on the RDP port.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo ufw allow 3389

After these steps, you can connect to your server's IP address using any standard Remote Desktop Client (like the one built into Windows).
Enter fullscreen mode Exit fullscreen mode

Step 1.3: System Update

Ensure all system packages are up to date.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo apt update && sudo apt upgrade -y

Step 1.4: Docker Engine Installation

Install prerequisite packages: These are needed to allow apt to use repositories over HTTPS.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo apt install ca-certificates curl gnupg

Add Docker's official GPG key: This verifies the authenticity of the Docker packages.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo install -m 0755 -d /etc/apt/keyrings

curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg

sudo chmod a+r /etc/apt/keyrings/docker.gpg

Set up the Docker repository: This tells the system where to download Docker from.
Enter fullscreen mode Exit fullscreen mode

Bash

echo \

"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \

$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \

sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

Install Docker Engine, CLI, and Compose:
Enter fullscreen mode Exit fullscreen mode

Bash

sudo apt update

sudo apt install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y

Allow non-root user to run Docker (Post-installation): Add your user to the docker group to avoid using sudo for every command.
Enter fullscreen mode Exit fullscreen mode

Bash

sudo usermod -aG docker $USER

IMPORTANT: You must log out and log back in for this change to take effect.

Part 2: n8n Application Deployment with Docker Compose

This section details the deployment of the n8n application container.

Step 2.1: Create a Project Directory

Create and enter a dedicated directory to store n8n configuration and data.
Enter fullscreen mode Exit fullscreen mode

Bash

mkdir n8n-selfhosted

cd n8n-selfhosted

Step 2.2: Create the docker-compose.yml File

Using a text editor like nano, create the configuration file that defines the n8n service.
Enter fullscreen mode Exit fullscreen mode

Bash

nano docker-compose.yml

Step 2.3: Define the n8n Service

Paste the following configuration into the docker-compose.yml file. This setup ensures data is persisted in a Docker volume.
Enter fullscreen mode Exit fullscreen mode

YAML

version: '3.7'

services:

n8n:

image: n8nio/n8n:latest

restart: always

ports:

  - "5678:5678"

environment:

  - GENERIC_TIMEZONE=Asia/Kolkata

  - N8N_ENCRYPTION_KEY='YOUR_SUPER_SECRET_KEY_HERE'

volumes:

  - n8n_data:/home/node/.n8n

# Wait for container to be stopped before killing it

stop_grace_period: 1m
Enter fullscreen mode Exit fullscreen mode

volumes:

n8n_data:

Step 2.4: Customize Configuration

Timezone: The GENERIC_TIMEZONE was set to Asia/Kolkata to ensure scheduled workflows run at the correct local time.
Encryption Key: A unique and persistent N8N_ENCRYPTION_KEY is critical for securing credentials. A key was generated using the command below and pasted into the 'YOUR_SUPER_SECRET_KEY_HERE' placeholder.
Enter fullscreen mode Exit fullscreen mode

Bash

Run this command to generate a key

openssl rand -base64 32

Step 2.5: Launch n8n

From within the n8n-selfhosted directory, start the n8n container in detached mode.
Enter fullscreen mode Exit fullscreen mode

Bash

docker compose up -d

Part 3: Final Setup and Verification

This section covers accessing the UI and completing the initial setup.

Step 3.1: Access the n8n Web Interface

The n8n instance is accessible via a web browser at:
Enter fullscreen mode Exit fullscreen mode

http://:5678

Step 3.2: Create the n8n Owner Account

Upon first access, the setup screen prompts for the creation of an owner (admin) account with a username, email, and password. This completes the installation.
Enter fullscreen mode Exit fullscreen mode

Part 4: First Workflow Creation (Beginner's Guide)

A simple workflow was created to learn the core concepts of n8n.

"Hello World" with the Set Node: A workflow was created with a Manual trigger and a Set node to create a static JSON object ({"message": "Hello..."}). This demonstrated the basic build-and-execute cycle.
Connecting to an API with the Weather Node:
    The Weather node was added to the workflow.
    A new credential was created for the OpenWeatherMap API by providing a free API key.
    The node was configured to fetch the current weather for "Bengaluru". This demonstrated connecting to external services and managing credentials.
Automating with the Cron Trigger:
    The Manual trigger was replaced with a Cron node.
    The schedule was set to run daily at a specific time (e.g., 9:00 AM).
    The workflow was activated using the toggle switch in the top-right, enabling it to run automatically in the background.
Enter fullscreen mode Exit fullscreen mode

Appendix: Common Management Commands

All commands should be run from the n8n-selfhosted directory.

Stop n8n: docker compose stop
Start n8n: docker compose start
View n8n logs: docker compose logs -f
Update n8n to the latest version:
Enter fullscreen mode Exit fullscreen mode

Bash

Pull the latest image from Docker Hub

docker compose pull

Recreate the container with the new image

docker compose up -d

Stop and remove the n8n container: docker compose down (Your data in the n8n_data volume will be p

reserved).
Enter fullscreen mode Exit fullscreen mode

Note: I am pretty new to the Ai, ML, Deep Learning stuff i am learning as i go.

Top comments (0)