Upgrading your n8n instance is essential to access new features, security patches, and performance improvements. However, many users are concerned about losing data or facing errors during the update process.
In this guide, you will learn:
- How to safely upgrade
n8nusingnpm - How to handle the ENOTEMPTY error
- The difference between
npm install -gandnpm update -g - How to upgrade when using either PM2 or a system service
- How to ensure your workflows and credentials are preserved
Where n8n Stores Your Data
Before any upgrade, it’s important to understand where your n8n instance stores its data. All important data (including workflows, credentials, and execution history) is saved in the .n8n folder, typically located at:
/home/your-username/.n8n
As long as this folder is not deleted or overwritten, your data will remain intact after the update.
Recommended Step: Backup Your Data
Even though the update process is safe, it’s a good practice to take a backup of the .n8n folder:
cp -r ~/.n8n ~/.n8n-backup-$(date +%Y%m%d)
Step-by-Step Guide to Upgrade n8n
Step 1: Stop n8n Before Updating
If You’re Using PM2:
pm2 stop n8n
If You’re Using systemd:
sudo systemctl stop n8n
Step 2: Update n8n Using npmThere are two commands people often consider:Option A: Use npm install -g (Recommended)
This will always fetch the latest version from the registry:
sudo npm install -g n8n --unsafe-perm=true
Option B: Use npm update -g (Not Always Reliable)
This attempts to update globally installed packages only if they’re outdated according to the lockfile, but may not work consistently for CLI tools like n8n.
sudo npm update -g n8n
Recommendation: Always prefer npm install -g n8n for version upgrades to ensure it pulls the latest.
Step 3: Handle Common Installation Errors
Problem: ENOTEMPTY Error
You might encounter the following error:
npm ERR! ENOTEMPTY: directory not empty, rename '/usr/lib/node_modules/n8n' -> '/usr/lib/node_modules/.n8n-xxxx'
Cause: A previous install left behind a temporary or partial folder.
Solution:
- Delete the temporary directory:
sudo rm -rf /usr/lib/node_modules/.n8n-*
- Retry the installation:
sudo npm install -g n8n --unsafe-perm=true
- If permission issues persist, you may run:
sudo chown -R $(whoami) /usr/lib/node_modules
Or:
sudo npm install -g n8n --unsafe-perm=true --force
Step 4: Verify the Installation
Once the install completes:
n8n --version
Confirm the version is updated to the latest release.
Step 5: Restart n8n
If You’re Using PM2:
pm2 restart n8n
pm2 status
If You’re Using systemd:
sudo systemctl start n8n
sudo systemctl status n8n
Optional: Auto-Start on Boot
To ensure n8n starts automatically on reboot:
For PM2:
pm2 startup
pm2 save
For systemd:
sudo systemctl enable n8n
Summary: Best Practices for Updating n8n
- Always stop the running instance before upgrading.
- Prefer
npm install -g n8n --unsafe-perm=trueovernpm update. - Back up your
.n8ndirectory before making any changes. - Resolve any
ENOTEMPTYerrors by removing.n8n-*temp directories. - Use the appropriate restart method depending on your deployment type.
Final Thoughts
Updating n8n is straightforward and safe when done properly. By understanding where your data is stored and following the proper update procedure, you can ensure that your automation workflows remain secure and uninterrupted.
Would you like an automation script to handle updates weekly or monthly? Or need help migrating to Docker or a cloud deployment? Get in touch and we’ll help optimize your setup.