This repository provides instructions to install and run n8n (workflow automation tool) on Termux using Node.js and SQLite.
- Android device with Termux installed
- Internet connection
pkg install root-repo
pkg update -y
pkg upgrade -Y
pkg install python3
pkg install nodejs-lts
pkg install clang libsqlite pkg-config python make binutils
export GYP_DEFINES="android_ndk_path=''"
pip install setuptools
npm install sqlite3 --build-from-source --sqlite=/data/data/com.termux/files/usr/bin/sqlite3 -g
npm install n8n -g --sqlite=/data/data/com.termux/files/usr/bin/sqlite3
npm install pm2 -g
pm2 start n8n
pm2 start n8n --tunnel
pm2 save
pm2 status
pkg install net-tools
ifconfig
http://<your-ip>:5678
Replace <your-ip> with the IP address from ifconfig.
If you get TLS or SSL errors please use Caddy
Expose n8n with internal IPs in internal Network with Self Signed Certificate, please use caddy as proxy server.
Please run below script for SSL, added endpoint in Caddyfile and start it
pkg install caddy -y
#!/bin/bash
# ------------------------------ # Configuration # ------------------------------
CERT_DIR="$HOME/caddy_certs"
CERT_FILE="$CERT_DIR/fullchain.pem"
KEY_FILE="$CERT_DIR/privkey.pem"
CONF_FILE="$CERT_DIR/openssl.cnf"
CADDYFILE="$HOME/Caddyfile"
CADDY_SERVICE="caddy" # Adjust if running differently
mkdir -p "$CERT_DIR" # ------------------------------
# Detect all internal IPv4 addresses # ------------------------------
IPS=$(ifconfig | grep -oP '\d+\.\d+\.\d+\.\d+' | grep -v '^127\.0\.0\.1$' | grep -v '^255\.' | grep -v '\.255$') if [ -z "$IPS" ]; then echo "No valid internal IPs found. Exiting."
exit 1 fi
echo "Detected IPs:"
echo "$IPS"
# ------------------------------
# Generate OpenSSL config with proper SANs
# ------------------------------
cat > "$CONF_FILE" <<EOL
[req]
distinguished_name = req_distinguished_name
req_extensions = v3_req
prompt = no
[req_distinguished_name]
CN = internal-server
[v3_req]
subjectAltName = @alt_names
[alt_names]
EOL
i=1
for ip in $IPS; do
echo "IP.$i = $ip" >> "$CONF_FILE"
((i++))
done
# ------------------------------
# Generate self-signed certificate
# ------------------------------
openssl req -x509 -nodes -days 365 -newkey rsa:2048 \
-keyout "$KEY_FILE" \
-out "$CERT_FILE" \
-config "$CONF_FILE" \
-extensions 'v3_req'
echo "Certificate generated:"
echo "Private Key: $KEY_FILE"
echo "Certificate: $CERT_FILE"
echo "Valid for IPs:"
echo "$IPS"
# ------------------------------
# Generate Caddyfile dynamically
# ------------------------------
cat > "$CADDYFILE" <<EOL
# Disable automatic HTTPS globally
{
auto_https off
}
EOL
for ip in $IPS; do
cat >> "$CADDYFILE" <<EOL
https://$ip:8080 {
reverse_proxy http://localhost:5678
tls $CERT_FILE $KEY_FILE
}
EOL
done
echo "Caddyfile updated with current IPs:"
echo "$IPS"
# ------------------------------
# Reload Caddy
# ------------------------------
if pgrep -x "$CADDY_SERVICE" > /dev/null; then
echo "Reloading Caddy to apply new certificate..."
pgrep -x caddy > /dev/null && kill $(pgrep -x caddy)
caddy run --config "$CADDYFILE" &
else
echo "Caddy is not running. Starting it..."
caddy run --config "$CADDYFILE" &
fi
#You can also use nginx with cerbot
apt install certbot python3-certbot-nginx
certbot --nginx -d yourdomain.com -d www.yourdomain.com
- Using
--tunnelis convenient for testing webhooks but not recommended for production. - Ensure SQLite is installed and built properly, otherwise n8n may fail to start.
- PM2 ensures n8n runs in the background even if Termux is closed.