Knowledgebase > Application Installs > How to Install n8n on Ubuntu 24.04
How to Install n8n on Ubuntu 24.04 / 22.04
n8n is a powerful, free, and source-available workflow automation tool that allows you to interconnect different applications and services to automate tasks. This guide provides a comprehensive walkthrough for installing n8n directly on a clean Ubuntu 24.04 server, using PM2 to keep it running and Nginx as a reverse proxy for secure access.
Prerequisites
Before you begin the installation, make sure you have the following:
- A server running a fresh, minimal installation of Ubuntu 24.04.
- root access or a user with
sudo
privileges. - A registered domain name (e.g.,
n8n.yourdomain.com
) pointed to your server's public IP address.
Don't have a server yet? Get a powerful NVMe VPS from VPS Server to get started. Our high-performance virtual private servers are perfect for hosting your automation workflows.
Hardware Requirements
Ensure your server meets these minimum hardware requirements for n8n to run smoothly:
- CPU: 1 vCore
- RAM: 2 GB
- Disk Space: 20 GB
Step 1: Prepare Your Server
First, connect to your server via SSH. Once logged in, it's crucial to update your system's package lists and upgrade any existing packages to their latest versions.
sudo apt-get update && sudo apt-get upgrade -y
Next, install Nginx, curl, and other necessary packages.
sudo apt-get install -y nginx curl
Step 2: Install Node.js
n8n is a Node.js application, so you'll need the Node.js runtime. We will use the NodeSource PPA to install the latest Long-Term Support (LTS) version.
Download and run the NodeSource setup script:
curl -fsSL https://deb.nodesource.com/setup_lts.x | sudo -E bash -
Now, install Node.js and the npm package manager:
sudo apt-get install -y nodejs
Step 3: Install n8n and PM2
With Node.js ready, you can install n8n and PM2. PM2 is a powerful process manager for Node.js applications that will keep n8n running in the background and restart it automatically if it crashes or the server reboots.
Install both packages globally using npm:
sudo npm install -g n8n pm2
Step 4: Start n8n with PM2
Use PM2 to start the n8n process. This command tells PM2 to run n8n and give the process the name "n8n".
pm2 start n8n
Next, generate a PM2 startup script. This will ensure that PM2, along with your n8n process, starts automatically when the server boots.
pm2 startup
The command will output another command that you must copy and run. It will look similar to this:
sudo env PATH=$PATH:/usr/bin /usr/lib/node_modules/pm2/bin/pm2 startup systemd -u your_user --hp /home/your_user
After running the command suggested by PM2, save the current process list so it can be resurrected on startup:
pm2 save
Step 5: Configure Nginx as a Reverse Proxy
Running n8n behind a reverse proxy is the best way to expose it to the internet. This allows you to use a standard domain name and secure it with SSL.
Create a new Nginx server block configuration file for your n8n domain:
sudo nano /etc/nginx/sites-available/n8n.yourdomain.com
Paste the following configuration into the file. Be sure to replace n8n.yourdomain.com
with your actual domain name.
server {
listen 80;
server_name n8n.yourdomain.com;
location / {
proxy_pass http://localhost:5678;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
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;
}
}
Enable this new site by creating a symbolic link to the sites-enabled
directory:
sudo ln -s /etc/nginx/sites-available/n8n.yourdomain.com /etc/nginx/sites-enabled/
Test the Nginx configuration for syntax errors:
sudo nginx -t
If the test is successful, restart Nginx to apply the changes:
sudo systemctl restart nginx
Step 6: Secure Your Domain with Let's Encrypt SSL
To secure your n8n installation with a free SSL certificate from Let's Encrypt, we will use Certbot.
Install Certbot and the Nginx plugin:
sudo apt-get install -y certbot python3-certbot-nginx
Run Certbot to obtain and install the SSL certificate. It will automatically detect your domain from the Nginx configuration and guide you through the process.
sudo certbot --nginx -d n8n.yourdomain.com
Follow the on-screen prompts. When asked, choose the option to redirect HTTP traffic to HTTPS.
You can now access your secure n8n instance at https://n8n.yourdomain.com
. The first time you visit, you will be prompted to set up an owner account. Congratulations, you're ready to start automating!
Complete Installation Script
For a fully automated setup, you can use the following bash script. Note that you will still need to run the Certbot command manually as it requires user input.
#!/bin/bash
#
# n8n Installer for a clean Ubuntu 24.04 server.
#
# This script will install Node.js, Nginx, PM2, and n8n.
# You must provide your domain name as an argument.
#
# Usage: ./install_n8n_direct.sh your-n8n-domain.com
#
# --- CONFIGURATION ---
DOMAIN_NAME=$1
# --- SCRIPT ---
if [ -z "$DOMAIN_NAME" ]; then
echo "Usage: $0 your-n8n-domain.com"
exit 1
fi
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root. Please use sudo." >&2
exit 1
fi
export DEBIAN_FRONTEND=noninteractive
echo "--> Updating and upgrading the system..."
apt-get update && apt-get upgrade -y
echo "--> Installing Nginx, Curl, and Certbot prerequisites..."
apt-get install -y nginx curl certbot python3-certbot-nginx
echo "--> Installing Node.js LTS from NodeSource..."
curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
apt-get install -y nodejs
echo "--> Installing n8n and PM2 globally..."
npm install -g n8n pm2
echo "--> Starting n8n with PM2..."
pm2 start n8n --name n8n
pm2 save
echo "--> Setting up PM2 to start on boot..."
pm2 startup systemd -u root --hp /root
echo "--> Configuring Nginx reverse proxy..."
cat < /etc/nginx/sites-available/$DOMAIN_NAME
server {
listen 80;
server_name $DOMAIN_NAME;
location / {
proxy_pass http://localhost:5678;
proxy_set_header Connection '';
proxy_http_version 1.1;
chunked_transfer_encoding off;
proxy_buffering off;
proxy_cache off;
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;
}
}
EOF
ln -s /etc/nginx/sites-available/$DOMAIN_NAME /etc/nginx/sites-enabled/
echo "--> Restarting Nginx..."
nginx -t && systemctl restart nginx
echo "---"
echo "--> n8n installation script has finished."
echo "--> The final step is to secure your site with Let's Encrypt."
echo "--> Run the following command and follow the prompts:"
echo ""
echo " sudo certbot --nginx -d $DOMAIN_NAME"
echo ""
echo "After that, your n8n instance will be available at https://$DOMAIN_NAME"
To use this script:
- Save the code to a file named
install_n8n_direct.sh
. - Make the script executable:
chmod +x install_n8n_direct.sh
. - Run the script with sudo, providing your domain as an argument:
sudo ./install_n8n_direct.sh n8n.yourdomain.com
. - Follow the final instruction to run Certbot manually.
Ready to start automating? Create a new server on VPS Server and get your n8n instance running today!