sodcalculator

10 Tech How-To

Install n8n on Ubuntu: Step-by-Step Guide

Guide 10-4947 · Updated · Step by step

To install n8n on Ubuntu, you can use Docker, npm, or a standalone installation script; the Docker method is the most reliable and recommended for production use. This guide covers all three approaches with exact commands, prerequisites, and troubleshooting tips so you can get your workflow automation platform running quickly and safely.

Prerequisites and System Requirements

Before installing n8n, ensure your Ubuntu system meets the minimum requirements and has the necessary tools. n8n is a Node.js application, so you need Node.js (version 18 or newer) and npm if you choose the npm method. For Docker, you need Docker Engine and Docker Compose installed. The official n8n documentation recommends at least 2 GB of RAM and 10 GB of free disk space for typical use, though larger workflows may require more. Your Ubuntu version should be 20.04 LTS or newer for best compatibility. Also, make sure your system is updated: sudo apt update && sudo apt upgrade -y.

Method 1: Install n8n with Docker (Recommended)

Docker is the simplest way to run n8n because it bundles all dependencies and isolates the application. Here are the steps:

  1. Install Docker if not already present: sudo apt install docker.io docker-compose -y
  2. Enable and start the Docker service: sudo systemctl enable docker && sudo systemctl start docker
  3. Add your user to the docker group to avoid using sudo for every command: sudo usermod -aG docker $USER (log out and back in for this to take effect)
  4. Run the n8n container with a persistent volume for data: docker run -d --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
  5. Access n8n at http://localhost:5678 in your browser.

For production, you should use Docker Compose with environment variables for encryption key, database configuration, and timezone. A basic docker-compose.yml file looks like this:

version: '3.8'
services:
  n8n:
    image: docker.n8n.io/n8nio/n8n
    ports:
      - "5678:5678"
    environment:
      - N8N_ENCRYPTION_KEY=your-strong-encryption-key
      - TZ=UTC
    volumes:
      - n8n_data:/home/node/.n8n
volumes:
  n8n_data:

Run it with docker-compose up -d. The encryption key is critical for security; generate one with openssl rand -hex 16.

Method 2: Install n8n with npm

If you prefer a native installation without Docker, use npm. First, install Node.js and npm:

  1. Install Node.js 18 or newer: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt install -y nodejs
  2. Verify versions: node --version and npm --version
  3. Install n8n globally: sudo npm install n8n -g
  4. Start n8n: n8n start

By default, n8n listens on port 5678. To run it as a background service, you can use pm2 or a systemd service file. For example, with pm2: sudo npm install pm2 -g && pm2 start n8n --name n8n && pm2 save. This method is more flexible but requires you to manage Node.js updates and dependencies yourself.

Method 3: Standalone Installation Script

n8n provides an official installation script for Linux that handles Node.js and n8n installation automatically. Run this command in your terminal:

curl -o- https://raw.githubusercontent.com/n8n-io/n8n/master/packages/cli/bin/install-n8n.sh | bash

This script installs Node.js (if needed) and n8n globally. After it finishes, you can start n8n with n8n start. The script is convenient but gives you less control over the installation details. It’s a good option for quick testing or if you don’t want to manually install Node.js.

Configuration and Environment Variables

n8n is highly configurable through environment variables. Key ones include:

  • N8N_ENCRYPTION_KEY: A secret key for encrypting credentials. Set this to a long random string.
  • N8N_PORT: The port n8n listens on (default 5678).
  • N8N_HOST: The hostname or IP address to bind to (default localhost).
  • N8N_PROTOCOL: Either http or https.
  • DB_TYPE: Database type (sqlite, postgresdb, mysql). Default is sqlite.
  • TZ: Timezone for scheduling, e.g., America/New_York.

For production, you should set N8N_ENCRYPTION_KEY and use PostgreSQL for better performance and reliability. To use PostgreSQL, you need to provide additional variables like DB_POSTGRESDB_HOST, DB_POSTGRESDB_DATABASE, DB_POSTGRESDB_USER, and DB_POSTGRESDB_PASSWORD. The Docker image automatically uses SQLite if no database variables are set.

Common Problems and Troubleshooting

Here are typical issues you might encounter and how to fix them:

  • Port 5678 already in use: Change the port with N8N_PORT=5679 or stop the conflicting service.
  • Permission errors with Docker: Ensure your user is in the docker group and you’ve logged out/in.
  • n8n not accessible from other machines: Bind to 0.0.0.0 by setting N8N_HOST=0.0.0.0 and ensure your firewall allows the port.
  • Node.js version too old: n8n requires Node 18+. Use node -v to check, and upgrade via NodeSource if needed.
  • Encryption key missing: If you see an error about encryption key, set N8N_ENCRYPTION_KEY to a fixed value.
  • Database lock errors: If using SQLite and you see lock errors, switch to PostgreSQL for concurrent access.

Always check the logs with docker logs n8n or journalctl -u n8n (if using systemd) to see detailed error messages.

Security and Best Practices

Running n8n securely is crucial, especially if exposed to the internet. Follow these practices:

  • Set a strong N8N_ENCRYPTION_KEY and keep it secret.
  • Use HTTPS in production, either with a reverse proxy like Nginx or Caddy, or by setting N8N_PROTOCOL=https and providing SSL certificates.
  • Restrict access with basic authentication using N8N_BASIC_AUTH_ACTIVE=true, N8N_BASIC_AUTH_USER, and N8N_BASIC_AUTH_PASSWORD.
  • Keep n8n updated regularly: docker pull docker.n8n.io/n8nio/n8n and recreate the container.
  • Back up your ~/.n8n directory or the Docker volume regularly.
  • Do not expose the n8n editor to the public internet without authentication; use a VPN or firewall if possible.

Updating and Uninstalling

To update n8n, the method depends on how you installed it:

  • Docker: Pull the latest image and recreate the container: docker pull docker.n8n.io/n8nio/n8n && docker stop n8n && docker rm n8n && docker run -d --name n8n -p 5678:5678 -v n8n_data:/home/node/.n8n docker.n8n.io/n8nio/n8n
  • npm: Run sudo npm update -g n8n and restart the service.
  • Script: Re-run the installation script, which will overwrite the old version.

To uninstall, stop the service and remove the files. For Docker: docker stop n8n && docker rm n8n and optionally delete the volume with docker volume rm n8n_data. For npm: sudo npm uninstall -g n8n. Also remove any systemd or pm2 configuration files if you created them.

Frequently Asked Questions

Can I install n8n on Ubuntu without Docker?

Yes, you can install n8n using npm or the standalone script. The npm method requires Node.js 18+ and is straightforward. The standalone script automates the Node.js installation. Docker is recommended for production because it isolates dependencies and simplifies updates, but it’s not mandatory.

How do I access n8n after installation?

After starting n8n, open your web browser and go to http://localhost:5678 if you’re on the same machine. If you’re accessing from another computer, use the server’s IP address and ensure the port is open in your firewall. The first time you access, you’ll create an admin user account.

What is the default username and password for n8n?

There is no default username or password. On first access, n8n prompts you to create an admin account with your email and password. If you forget it, you can reset it by running n8n user-management:reset-password in the terminal where n8n is installed.

How do I run n8n as a service on Ubuntu?

You can use systemd or pm2. For systemd, create a service file at /etc/systemd/system/n8n.service with the appropriate ExecStart command, then enable it with sudo systemctl enable n8n. With pm2, run pm2 start n8n --name n8n and pm2 save to keep it running after reboot.

Can I use n8n with a different database like MySQL?

Yes, n8n supports SQLite (default), PostgreSQL, and MySQL. To use MySQL, set the environment variables DB_TYPE=mysql, DB_MYSQLDB_HOST, DB_MYSQLDB_DATABASE, DB_MYSQLDB_USER, and DB_MYSQLDB_PASSWORD. Ensure the database is created before starting n8n.

Why is n8n not starting and showing an error about Node.js version?

n8n requires Node.js version 18 or newer. Check your version with node -v. If it’s older, update it using NodeSource: curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - && sudo apt install -y nodejs. After updating, restart n8n.

Related

General steps for current mainstream versions; menus can differ by device and version. See the disclaimer or report an error.

More in this bed

The whole Tech How-To bed →