In today’s digital landscape, workflow automation has become essential for businesses and developers looking to streamline their operations. n8n stands out as a powerful, open-source workflow automation tool that enables seamless integration between various applications and APIs. Unlike many commercial alternatives, n8n offers the flexibility of self-hosting, providing enhanced data privacy, customization options, and significant cost savings.
This comprehensive guide will walk you through two different methods to install n8n on your Ubuntu VPS: using a one-click template for quick setup and manual installation for those who prefer complete control over their environment.
Table of Contents
Why Choose n8n for Workflow Automation?
n8n (pronounced “n-eight-n”) is a node-based workflow automation tool that allows you to connect different services and applications without extensive coding knowledge. Here’s why it’s becoming increasingly popular:
- Visual Workflow Builder: Create complex automation using an intuitive drag-and-drop interface
- Extensive Integrations: Connect to hundreds of popular services including Slack, Google Sheets, Salesforce, and more
- Self-Hosted Freedom: Maintain complete control over your data and workflows
- Cost-Effective: No per-execution fees or user limits when self-hosted
- Open Source: Benefit from community contributions and transparency
Prerequisites and System Requirements
Before diving into the installation process, ensure your hosting environment meets these requirements:
Hardware Requirements
- Minimum: 1 vCPU, 1GB RAM (suitable for basic workflows)
- Recommended: 2 vCPU, 2GB RAM (better for complex automation)
- Storage: At least 10GB of free space for the system and workflow data
Software Requirements
- Ubuntu 18.04 or later (Ubuntu 20.04 LTS or 22.04 LTS recommended)
- Root or sudo access to your VPS
- Internet connection for downloading packages and dependencies
Optional but Recommended
- Custom Domain: For easier access and professional setup
- SSL Certificate: For secure HTTPS connections
- Basic Linux Knowledge: Helpful for troubleshooting and customization
Method 1: One-Click Installation with Hostinger Template
If you’re using HeroXHost’s VPS services, the one-click template method is the fastest way to get n8n running. This approach automates the entire setup process, including Ubuntu server configuration and n8n installation.
Step 1: Access Your VPS Dashboard
Navigate to your HeroXHost control panel and locate your VPS management section. From there, you’ll be able to access the template installation options.
Step 2: Deploy the n8n Template
- Look for the “Operating System” or “Templates” section in your VPS dashboard
- Search for “n8n” in the available templates
- Select the n8n template and confirm the installation
- Important: This process will overwrite your existing OS and delete all current files
- Set a strong root password when prompted
The template installation typically takes 5-10 minutes to complete. You’ll see a progress indicator showing the setup status.
Step 3: Initial Configuration
Once the template installation is complete:
- Access the n8n interface through your VPS IP address on port 5678
- Create your first admin account with a secure password
- Complete the initial setup wizard
Step 4: Secure Your Installation
After the basic setup, implement these security measures:
Enable Authentication: Configure basic authentication to prevent unauthorized access to your npm instance.
Set Up Environment Variables: Customize your npm installation by modifying the configuration file. Common variables include:
NPM_REGISTRY: Your private registry URL NPM_PORT: Port number (default 8080) NPM_PROTOCOL: HTTP or HTTPS NPM_CONFIG_REGISTRY: Registry configuration URL NPM_CONFIG_CACHE: Cache directory path NPM_CONFIG_PREFIX: Global installation prefix NPM_CONFIG_USERCONFIG: User configuration file path NPM_CONFIG_GLOBALCONFIG: Global configuration file path NPM_TOKEN: Authentication token for private registries NODE_ENV: Environment setting (development/production)
Additional Security Configurations:
NPM_CONFIG_AUDIT_LEVEL: Set vulnerability audit threshold (low, moderate, high, critical) NPM_CONFIG_FUND: Enable/disable funding messages NPM_CONFIG_SCRIPT_SHELL: Configure shell for npm scripts NPM_CONFIG_UNSAFE_PERM: Control permission settings for global installations
Configure SSL (Recommended) For production use, set up SSL certificates using Let’s Encrypt and NGINX as a reverse proxy. This ensures encrypted connections and professional presentation.
Method 2: Manual Installation on Ubuntu
Manual installation gives you complete control over the setup process and is necessary when using VPS providers without n8n templates.
Step 1: System Preparation
Connect to your VPS via SSH and update your system:
sudo apt-get update && sudo apt-get upgrade -y
This ensures you have the latest security patches and software versions.
Step 2: Choose Your Installation Method
You have two options for running n8n:
Option A: Direct Installation (Node.js)
Install Node.js and run n8n directly on your system:
# Install Node.js setup script curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash - # Install Node.js and npm sudo apt-get install -y nodejs # Verify installations node -v && npm -v # Install n8n globally npm install -g n8n
Option B: Containerized Installation (Docker)
Install Docker and run n8n in a container (recommended for production):
# Install Docker dependencies sudo apt-get install -y apt-transport-https ca-certificates curl software-properties-common # Add Docker's official GPG key curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg # Add Docker repository echo "deb [arch=amd64 signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null # Install Docker sudo apt-get update sudo apt-get install -y docker-ce docker-ce-cli containerd.io # Verify Docker installation docker --version
Step 3: Deploy n8n
For Direct Installation:
# Start n8n in a screen session screen -S n8n n8n # Detach from screen: Ctrl+A then D # Reattach later: screen -R n8n
For Docker Installation:
# Pull n8n Docker image docker pull n8nio/n8n # Run with persistent storage docker run -d --name n8n -p 5678:5678 -v ~/.n8n:/home/node/.n8n n8nio/n8n
Step 4: Configure Security and Access
Set Up Authentication
Configure environment variables to secure your n8n instance:
For Direct Installation:
export N8N_BASIC_AUTH_ACTIVE=true export N8N_BASIC_AUTH_USER=your_username export N8N_BASIC_AUTH_PASSWORD=your_secure_password export N8N_HOST=yourdomain.com export WEBHOOK_URL=https://yourdomain.com/
For Docker Installation:
docker stop n8n && docker rm n8n docker run -d --name n8n \ -p 5678:5678 \ -e N8N_BASIC_AUTH_ACTIVE=true \ -e N8N_BASIC_AUTH_USER=your_username \ -e N8N_BASIC_AUTH_PASSWORD=your_secure_password \ -e N8N_HOST=yourdomain.com \ -e WEBHOOK_URL=https://yourdomain.com/ \ -v ~/.n8n:/home/node/.n8n \ n8nio/n8n
docker stop n8n && docker rm n8n docker run -d --name n8n \ -p 5678:5678 \ -e N8N_BASIC_AUTH_ACTIVE=true \ -e N8N_BASIC_AUTH_USER=your_username \ -e N8N_BASIC_AUTH_PASSWORD=your_secure_password \ -e N8N_HOST=yourdomain.com \ -e WEBHOOK_URL=https://yourdomain.com/ \ -v ~/.n8n:/home/node/.n8n \ n8nio/n8n
Configure NGINX and SSL
Set up NGINX as a reverse proxy and secure your installation with Let’s Encrypt:
# Install NGINX and Certbot sudo apt update && sudo apt install nginx certbot python3-certbot-nginx -y # Enable and start NGINX sudo systemctl enable nginx sudo systemctl start nginx # Create NGINX configuration sudo nano /etc/nginx/sites-available/n8n
Add the following configuration:
server { server_name yourdomain.com; location / { proxy_pass http://localhost:5678; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } listen 80; }
Enable the configuration and obtain SSL certificate:
# Enable the site sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/ sudo systemctl restart nginx # Get SSL certificate sudo certbot --nginx -d yourdomain.com
# Enable the site sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/ sudo systemctl restart nginx # Get SSL certificate sudo certbot --nginx -d yourdomain.com
Post-Installation Configuration
Setting Up Automatic Updates
Create a cron job to automatically renew SSL certificates:
sudo crontab -e # Add this line: 0 2 * * * certbot renew --quiet --post-hook "systemctl restart nginx"
Backup Strategy
Implement a backup strategy for your n8n data:
For Docker installations:
# Create backup script #!/bin/bash tar -czf n8n-backup-$(date +%Y%m%d).tar.gz ~/.n8n/
For direct installations:
# Backup n8n data directory cp -r ~/.n8n/ /path/to/backup/location/
Monitoring and Maintenance
Set up basic monitoring to ensure your n8n instance remains healthy:
- Resource Monitoring: Use tools like htop or Grafana to monitor CPU and memory usage
- Log Monitoring: Regularly check n8n logs for errors or warnings
- Update Schedule: Plan regular updates for both n8n and your Ubuntu system
Troubleshooting Common Issues
Port Access Issues
If you can’t access n8n on port 5678:
- Check if the port is open in your firewall
- Verify that n8n is running and listening on the correct port
- Ensure your VPS provider isn’t blocking the port
SSL Certificate Problems
For SSL-related issues:
- Verify your domain is properly pointed to your VPS IP
- Check NGINX configuration for syntax errors
- Ensure Certbot has proper permissions
Performance Issues
If n8n is running slowly:
- Increase your VPS resources (CPU and RAM)
- Optimize your workflows to reduce complexity
- Consider using a dedicated database for better performance
Best Practices for Production Use
Security Hardening
- Use Strong Authentication: Implement strong passwords and consider two-factor authentication
- Regular Updates: Keep n8n, Docker, and Ubuntu updated
- Network Security: Use firewalls and VPN access where appropriate
- Monitor Access: Regularly review access logs for suspicious activity
Performance Optimization
- Resource Allocation: Ensure adequate CPU and RAM for your workload
- Database Optimization: Consider using PostgreSQL for better performance
- Workflow Optimization: Design efficient workflows to minimize resource usage
- Caching: Implement caching strategies for frequently accessed data
Backup and Recovery
- Regular Backups: Automate daily backups of your n8n data
- Test Restores: Regularly test your backup restoration process
- Documentation: Maintain documentation of your setup and configurations
- Disaster Recovery: Have a plan for quickly restoring service if needed
Advanced Configuration Options
Using External Databases
For production environments, consider using PostgreSQL:
# Install PostgreSQL sudo apt install postgresql postgresql-contrib # Create database and user sudo -u postgres createdb n8n sudo -u postgres createuser n8n_user # Configure n8n to use PostgreSQL export DB_TYPE=postgresdb export DB_POSTGRESDB_HOST=localhost export DB_POSTGRESDB_DATABASE=n8n export DB_POSTGRESDB_USER=n8n_user export DB_POSTGRESDB_PASSWORD=your_password
Scaling for High Availability
For enterprise use, consider:
- Load balancing across multiple n8n instances
- Using managed databases (RDS, Cloud SQL)
- Implementing monitoring and alerting systems
- Setting up automated failover mechanisms
Conclusion
Installing n8n on an Ubuntu VPS opens up a world of workflow automation possibilities. Whether you choose the convenient one-click template method or the more flexible manual installation approach, you now have the knowledge to deploy and configure a robust n8n instance.
Remember these key points for success:
- Security First: Always implement proper authentication and SSL certificates
- Regular Maintenance: Keep your system updated and monitor performance
- Backup Strategy: Implement and test regular backups
- Start Simple: Begin with basic workflows and gradually increase complexity
- Community Resources: Leverage the n8n community for support and inspiration
With n8n properly installed and configured, you can now start building powerful automation workflows that will save time and reduce manual tasks. From simple data synchronization to complex business process automation, n8n provides the flexibility and power to handle workflows of any complexity.
The journey into workflow automation is just beginning. Explore the extensive library of n8n integrations, experiment with different automation scenarios, and don’t hesitate to engage with the vibrant n8n community for support and inspiration. Your automated future starts now!