Automatically updating n8n

Hey,

Is there a way to automatically update n8n when running it via pm2?

Right now, I have to manually update it using the console every time, which is a hassle because I am just deploying it and not using it, so I don’t immediately notice when new updates are coming out.

Could I create a cron job for example, that runs a basic shell script that backs up the Workflows and then runs the npm update command for n8n?

1 Like

Hey @Felix,

In theory that should be possible, There is a CLI tool you can use to export workflows so your script may look something like…

#!/bin/bash
# Export n8n workflows to backups/latest/ folder
n8n export:workflow --all --output=backups/latest/
# Stop n8n
pm2 stop n8n
# Install the latest release
npm install -g n8n@latest
# Start n8n up
pm2 restart n8n

This has not been tested but may help you work out your process, If you wanted to you could also export the credentials. What I do with my n8n instance is have a workflow that exports the workflows and commits them to a Git repo on a schedule, Makes life a bit easier and it is one less script I need to maintain.

3 Likes

Thanks, that worked!

I’ve changed the --all Flag to --backup and also backed up my credentials, but apart from that its working like intended. Thank you so much!

1 Like