n8n is a powerful tool that automates workflows, connecting apps and APIs with a simple drag-and-drop interface.
The flexibility of self-hosting means you have complete control over your data and customization options.
We'll cover everything from logging into your server using SSH, updating Ubuntu, installing necessary packages, through setting up Node.js using NVM (Node Version Manager), to configuring PM2 to ensure your n8n service runs continuously.
Lastly, we secure our deployment by setting up NGINX as a reverse proxy and enabling SSL via Certbot.
Let's dive into the world of automation and take control of your processes with n8n!
System Preparation and Setup Before we dive into n8n installation, the first thing you need is access to a server.
For this tutorial, I recommend using Oracle Cloud's free tier.
Oracle Cloud provides sufficient resources to run a self-hosted n8n, and best of all—it's free for life under certain limits.
1.
Login to Your Server Log into your server from your local machine using an SSH command.
Open your Terminal or PowerShell and run: bash ssh -i ~/Downloads/n8n-demo-key/ssh-key-2025-07-03.key ubuntu@80.225.122.46 Make sure to replace the path to your SSH key and the IP address with your actual details if they differ.
Once you've connected, you're ready to swim in the world of self-hosting.
2.
File Permissions After logging in, secure your SSH key by setting the correct file permissions: bash chmod 400 ~/Downloads/n8n-demo-key/ssh-key-2025-07-03.key This command ensures that no unauthorized users have access to your SSH key.
Keeping your keys safe is essential for server security.
3.
Update Ubuntu and Install Essential Packages Keeping your system updated is vital.
Run the following commands to update Ubuntu and install essential packages: bash sudo apt update && sudo apt upgrade -y && sudo apt install -y \ build-essential \ curl \ wget \ git \ ufw \ ca-certificates \ gnupg \ lsb-release \ software-properties-common This command does a couple of things: It updates the list of available packages.
It upgrades the installed packages to their latest versions.
It installs packages that will be useful baseline tools as you set up n8n.
4.
System Overview: What You've Installed Let's take a quick look at what these packages do: Package Description build-essential A package that installs the essentials for building software. curl & wget Tools used to transfer data with URLs, handy for downloading. git Version control system for code management. ufw Simplified firewall to secure your server. ca-certificates Ensures your system verifies SSL certificates properly. gnupg Supports encryption and signing data to ensure authenticity. lsb-release Displays Linux Standard Base and distribution information. software-properties-common Allows managing PPAs and software repositories.
Understanding what each package does helps you troubleshoot and scale your setup later if required.
Installing Node.js using NVM n8n is a Node.js-based workflow automation tool.
This step will guide you through installing Node.js using NVM, which is a convenient tool for managing Node versions on your machine.
1.
Install NVM (Node Version Manager) Execute this command to download and execute the NVM installation script: bash curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash After running the script, reload your shell to start using NVM by adding the following commands: bash export NVM_DIR="$HOME/.nvm" source "$NVM_DIR/nvm.sh" These commands ensure that the current shell recognizes NVM and allows you to manage Node.js installations.
2.
Install Node.js v22 Why Node.js version 22?
Newer versions often include performance improvements and security updates.
Installing Node.js version 22 is as simple as: shell nvm install 22 nvm use 22 nvm alias default 22 After these commands, verify the installation by checking the Node.js version: bash node -v You should see a version number printed to your console.
This indicates that Node is properly set up.
3.
Why Use NVM?
Using NVM allows you to switch between different versions of Node.js with ease.
This flexibility is key when using various Node-based applications that might have differing compatibility requirements.
You can always revert or try a new version if needed.
Setting up PM2 and the n8n Startup Script Once Node.js is installed, we need to make sure that n8n runs continuously.
Instead of just starting n8n and leaving it hanging on your terminal, we use PM2, a process manager for Node.js applications.
PM2 ensures that n8n restarts if it crashes or if your server reboots.
1.
Install PM2 Globally Install PM2 using npm: bash npm install -g pm2 After installation, verify PM2 by checking its version: bash pm2 -v Having PM2 in place means you don't have to worry about downtime due to unexpected crashes.
2.
Create the n8n Startup Script For an organized setup, we recommend creating a startup script that loads necessary environment variables and starts n8n.
First, install Nano in case it isn't present: bash sudo apt install -y nano Then create a new shell script: bash nano ~/start-n8n.sh Paste the following content into the file: bash #!/bin/sh # Load environment variables from .env file located in ~/.n8n set -a . ~/.n8n/.env set +a # Run n8n npx n8n Make the script executable: bash chmod +x ~/start-n8n.sh This script helps ensure that every time n8n starts, it has access to the required environment variables located in your .env file.
3.
Use PM2 to Manage n8n Now, run the script using PM2: bash pm2 start ~/start-n8n.sh --name n8n pm2 startup pm2 save pm2 start: Launches the script and assigns it a process name "n8n". pm2 startup: Configures PM2 to launch at boot. pm2 save: Saves the list of processes so they restart automatically after reboot.
4.
PM2 and Process Management Here's a quick table illustrating the main PM2 commands used: Command Description pm2 start Start a process and assign it a name. pm2 stop Stop a running process. pm2 restart Restart a process; handy after making updates. pm2 status List running and stopped processes. pm2 save Save the current process list for restarts.
This systematic approach lets you debug and manage your n8n process with confidence.
Configuring and Securing NGINX While n8n runs on its own port (5678 by default), it's wise to set up a reverse proxy.
NGINX is a great web server option that sits in front of your n8n installation, handling traffic, security, and SSL encryption.
1.
Installing NGINX First, update your package list and install NGINX: bash sudo apt update && sudo apt install -y nginx Then, enable and start NGINX: bash sudo systemctl enable nginx sudo systemctl start nginx Check the status to confirm it's running: bash sudo systemctl status nginx 2.
Creating an NGINX Config for n8n Create a new configuration file for your n8n server: bash sudo nano /etc/nginx/sites-available/n8n Paste the following configuration into the file: conf server { listen 80; server_name your-domain.com; # Replace with your actual domain location / { proxy_pass http://localhost:5678; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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; proxy_buffering off; proxy_cache off; chunked_transfer_encoding off; } } Replace " your-domain.com " with your actual domain name if you have one.
Otherwise, you might use your server IP address, but note that SSL configuration might require a domain name.
3.
Enabling the NGINX Site Link the new configuration file to the NGINX sites-enabled directory: bash sudo ln -s /etc/nginx/sites-available/n8n /etc/nginx/sites-enabled/ Test the configuration for any syntax errors: bash sudo nginx -t If the test is successful, reload NGINX: bash sudo systemctl reload nginx 4.
SSL Setup with Certbot for Security Securing traffic to your workflow automation tool is critical.
Use Certbot, which is a client for Let's Encrypt, to automatically obtain and install an SSL certificate.
Install Certbot and NGINX Plugin bash sudo apt install -y certbot python3-certbot-nginx Obtain an SSL Certificate Run Certbot to obtain a certificate: bash sudo certbot --nginx -d your-domain.com Follow the prompts.
Replace " your-domain.com " with your verified domain name.
Certbot rewrites your NGINX configuration to handle HTTPS requests.
Enabling Auto-renewal Certbot sets up a timer for certificate renewal: bash sudo systemctl enable certbot.timer This ensures that your certificate is always renewed before it expires.
Finalizing the Setup and Best Practices Congratulations on setting up n8n in a self-hosted environment on Oracle Cloud!
Let's review some final configurations and best practices to maintain your server securely and efficiently.
1.
Configuring IP Tables for Extra Security Configuring your server firewall is crucial.
If you decide to customize IP tables, you may use: bash sudo nano /etc/iptables/rules.v4 Within the file, you can set rules to restrict access to crucial ports.
For instance, you might allow only certain IP addresses to connect to SSH.
After editing, restore the rules: bash sudo iptables-restore 2.
Environment Variables and Security Make sure your environment variables in the .env file (referenced in your startup script) are secure.
Only include necessary parameters, and avoid exposing sensitive information unnecessarily.
You might create the file at: bash ~/.n8n/.env Here's an example structure: env N8N_BASIC_AUTH_ACTIVE=true N8N_BASIC_AUTH_USER=yourusername N8N_BASIC_AUTH_PASSWORD=yourpassword WEBHOOK_TUNNEL_URL=https://your-domain.com/ Ensure you restrict file permissions: bash chmod 600 ~/.n8n/.env 3.
Logging and Monitoring It pays to keep track of your server processes.
PM2 offers logging mechanisms that allow you to check the output of your n8n process: bash pm2 logs n8n Regularly check your logs for any unexpected errors.
Setting up external monitoring dashboards is a good idea if your n8n workflows become mission-critical.
4.
Handling Updates and Changes As with any self-hosted solution, keep an eye on updates to n8n, Node.js, PM2, and NGINX.
When a new version is available, review the change logs and perform updates on a test server first if possible.