Bringing n8n to FreeBSD: A Step-by-Step Guide Using PM2
Why this setup
n8n is a powerful workflow automation server—self-hostable, extensible, and open-source. The official docs cover installation on many systems. (n8n Docs)
FreeBSD is less common for n8n but entirely feasible, and using PM2 gives you process-supervision, restart-on-crash, and boot-startup behaviour.
PM2 supports FreeBSD’s startup system (rc.d) via its “startup script” mechanism. (pm2.keymetrics.io)
Assumptions & prerequisites
Before proceeding:
- You’re running FreeBSD (e.g., 13.x or 14.x) with root or sudo access.
- You have installed Node.js (an LTS version) and npm via
pkg install node16 npm(or whichever version is appropriate). For example someone reports:pkg install node16on FreeBSD. (n8n Community) - You’re comfortable working on command-line and editing config files.
- You’ve picked or will pick a non-root user for running the service (recommended for security).
- You have network access, firewall settings, and optionally a domain/SSL if exposing externally.
Installation steps
Here’s a step-by-step tailored for FreeBSD + n8n + PM2.
1. Install Node.js & npm
Log in, update packages, then install. Example:
sudo pkg update
sudo pkg upgrade
sudo pkg install node16 npm
Verify:
node --version
npm --version
Note: some users flagged compatibility issues of certain bcrypt bindings on FreeBSD for n8n older versions. (n8n Community) So ensure you’re using a supported version of n8n (or test it) when running on FreeBSD.
2. Create a dedicated user (optional but recommended)
sudo adduser n8nusr
sudo passwd n8nusr
Log in (or use su - n8nusr) when installing/operating n8n so it does not run as root.
3. Install n8n globally (or locally)
As the n8n user (or root if you choose), install via npm:
npm install -g n8n
This will place the n8n binary in your PATH (globally) or you may choose to install it in a project folder.
From community feedback: “I decided to challenge myself, to see if I could get n8n working on FreeBSD … it was surprisingly easy”. (n8n Community)
However be aware of the bcrypt compatibility issues (see above).
4. Test a manual start
Still as the n8n user, try:
n8n
or for tunnel mode (if you need to expose via tunnel) for quick test:
n8n start --tunnel
If it launches and you can access the UI (default port 5678 unless changed), then you’re good.
5. Install PM2
Now you’ll install PM2 so you can manage n8n as a service. As the n8n user (or root if needed, though user is better):
npm install -g pm2
PM2 documentation shows this method. (PM2.io)
6. Use PM2 to start n8n
Switch to the n8n user (if not already). Then:
pm2 start n8n --name "n8n-server" -- # the `--` passes args to n8n if any
You may want to specify environment variables, e.g.:
export N8N_BASIC_AUTH_ACTIVE=true
export N8N_BASIC_AUTH_USER=admin
export N8N_BASIC_AUTH_PASSWORD=yourpassword
# etc.
pm2 start n8n --name "n8n-server" --tunnel
Then save the PM2 process list:
pm2 save
This will allow PM2 to resurrect the process list after reboot.
7. Configure PM2 startup on FreeBSD
Because FreeBSD uses the traditional rc.d system (not systemd), you’ll create a startup script for PM2. There’s a gist/script already prepared for FreeBSD. (Gist)
Here’s an outline:
- Create a file
/usr/local/etc/rc.d/pm2with contents (modify user, paths as appropriate):
#!/bin/sh
# PROVIDE: pm2
# REQUIRE: NETWORK
# KEYWORD: shutdown
. /etc/rc.subr
name="pm2"
rcvar=pm2_enable
: ${pm2_user="n8nusr"} # the user who runs PM2 and n8n
: ${pm2_enable="NO"}
pm2_start() {
su -l ${pm2_user} -c "/usr/local/lib/node_modules/pm2/bin/pm2 resurrect"
}
pm2_stop() {
su -l ${pm2_user} -c "/usr/local/lib/node_modules/pm2/bin/pm2 dump && \
/usr/local/lib/node_modules/pm2/bin/pm2 delete all && \
/usr/local/lib/node_modules/pm2/bin/pm2 kill"
}
load_rc_config $name
run_rc_command "$1"
- Make it executable:
chmod +x /usr/local/etc/rc.d/pm2
- Enable it in
/etc/rc.conf:
pm2_enable="YES"
pm2_user="n8nusr"
- Then you can test:
service pm2 start
service pm2 status
Now on reboot, FreeBSD will run this rc script, PM2 will resurrect the previously saved process list (which includes n8n), and your n8n service should start automatically.
8. Reverse proxy / SSL (optional but recommended)
If you’re exposing your n8n server to the internet, you probably want to front it with a web server (e.g., nginx or caddy) to handle SSL/TLS, domain name, maybe basic auth. The n8n docs emphasise securing your instance. (Hostinger)
Example: Nginx listening on 443, forwarding to 127.0.0.1:5678, with proxy_set_header Host $host etc. And use Let’s Encrypt for SSL certificate.
9. Maintenance & updates
- To update n8n: stop via PM2 (
pm2 stop n8n-server), update the npm package (npm update -g n8nor whichever method you used), thenpm2 restart n8n-server. - Monitor logs:
pm2 logs n8n-server - Regular backups: n8n stores data under the home directory (
~/.n8nby default) or depending on configuration—ensure you backup workflows, credentials, etc. - Security: ensure basic auth is enabled, strong password, firewall only allowing needed ports, SSL encrypted if exposed.
Troubleshooting / caveats
- As noted above, there are known issues with n8n + FreeBSD regarding bcrypt native bindings (example: “Cannot run n8n on FreeBSD” thread). (n8n Community) If you hit a
TypeError: Can not find node binding files … @node-rs/bcrypt-freebsd-x64error, you may need to revert to a version of n8n that usesbcryptjsor patch the binding. - Ensure you run as a non-root user wherever feasible.
- Ensure the node version is compatible with n8n version you select.
- If using a jail or container environment on FreeBSD, ensure networking allows access to ports and that listen addresses are set appropriately (e.g.,
N8N_LISTEN_ADDRESS=0.0.0.0) as noted in forum posts. (The FreeBSD Forums) - Because FreeBSD uses rc.d scripts, ensure permissions and ownership of the script are correct and user environment (PATH, NODE_PATH) is set so that PM2 can find the binaries.
Example summary of commands
Here’s a condensed version you can adapt:
# as root
pkg update && pkg upgrade
pkg install node16 npm
adduser n8nusr
passwd n8nusr
# switch to n8nusr
su - n8nusr
npm install -g n8n pm2
# set env vars (in ~/.profile or separate file)
export N8N_BASIC_AUTH_ACTIVE=true
export N8N_BASIC_AUTH_USER=admin
export N8N_BASIC_AUTH_PASSWORD=StrongPasswordHere
# start n8n via PM2
pm2 start n8n --name "n8n-server"
pm2 save
exit
# as root again
# Create /usr/local/etc/rc.d/pm2 script (see above)
chmod +x /usr/local/etc/rc.d/pm2
echo 'pm2_enable="YES"' >> /etc/rc.conf
echo 'pm2_user="n8nusr"' >> /etc/rc.conf
# test
service pm2 start
service pm2 status
# Now reboot to test persistence
Conclusion
With this setup, you’ll have n8n running on FreeBSD as a background, daemonised service, managed by PM2. It will automatically restart on crashes, and be resurrected after server reboots. The use of a dedicated user and optional reverse proxy/SSL adds production-readiness.