Can not install n8n on Centos over npm

I am trying to install n8n over npx or npm on Centos (over IspManager shell), using this instruction: Installation | Docs

I get following error:

[root@freud ~]# npx n8n
Error: Cannot find module ‘lodash’
Require stack:
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-workflow/dist/src/NodeHelpers.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-workflow/dist/src/index.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-core/dist/src/NodeExecuteFunctions.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/n8n-core/dist/src/index.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/n8n/dist/commands/start.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/@oclif/command/node_modules/@oclif/config/lib/plugin.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/@oclif/command/node_modules/@oclif/config/lib/config.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/@oclif/command/node_modules/@oclif/config/lib/index.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/@oclif/command/lib/command.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/@oclif/command/lib/index.js
- /root/.npm/_npx/a8a7eec953f1f314/node_modules/n8n/bin/n8n
Code: MODULE_NOT_FOUND

Hi @Dimitri_Korenev, I am really sorry to hear this.

I have just tried this on a fresh version of CentOS 8 using the latest available Node.js version coming with CentOS.

To be precise, I have only entered these commands after my test VM has been provisioned:

sudo su -
dnf module list nodejs
dnf module enable nodejs:16
dnf install nodejs
npx n8n

I then had to confirm the prompt:

Need to install the following packages:
  n8n
Ok to proceed? (y) y

Afterwards, n8n would start up as expected:

Initializing n8n process
UserSettings were generated and saved to: /root/.n8n/config


INFO: Started with migration for wait functionality.
      Depending on the number of saved executions, that may take a little bit.


Start migration UpdateWorkflowCredentials1630330987096
UpdateWorkflowCredentials1630330987096: 1.713ms
n8n ready on 0.0.0.0, port 5678
Version: 0.157.1

Editor is now accessible via:
http://localhost:5678/

Press "o" to open in Browser.

So I am wondering if the problem might be specific to your Node.js installation. Are you by any chance using a version that didn’t come with the operating system? Or have different versions of Node.js installed (and might face a situation where modules would be stored in a different location than where the Node.js version used by your npx command is looking)?

1 Like

Thank you very much for support. I did not recognize the issue, but tried to reinstall node.js and followed your steps. Functioning!))))

2 Likes

Awesome, glad to hear this works and thanks so much for confirming!

The “Beginners”-question. Next day after installing with “npx n8n” I try to open http://localhost:5678/ (where "localhost is my server IP). Not functining.

When I type n8n in shell, response is "-bash: n8n: command not found ". And when I start “npx n8n”, it runs again.

How to let n8n run continiously?

Best, Dimtiri

Hi @Dimitri_Korenev, as you have noticed npx is not a permanent solution but a “package runner”. It’s great for quickly testing stuff, but it will not set anything up permanently.

The suggested approach for a server installation would be using Docker (which means you also wouldn’t have to worry about configuring Node.js on your machine) and is documented here:

Note that the example commands to install Docker and Docker Compose would be for Ubuntu, so you would need to adjust them for CentOS. Installation instructions for Docker on CentOS can be found at Install Docker Engine on CentOS | Docker Documentation, Docker Compose instructions are available at Install Docker Compose | Docker Documentation.

The restart: always policy will ensure n8n is running whenever your server runs.

Thank you for support! I installed docker and managed to start instance in http://194.67.105.122:5678/

I created configuration files according to Server Setup | Docs. But when I start step 8, I get "command not found (see below). What is the issue?

[root@freud ~]# docker run -it --rm \                                                                                            
> --name n8n \                                                                                                                   
> -p 5678:5678 \                                                                                                                 
> -v ~/.n8n:/home/node/.n8n \n8nio/n8n                                                                                           
Unable to find image 'n8nio/n8n:latest' locally                                                                                  
latest: Pulling from n8nio/n8n                                                                                                   
0a6724ff3fcd: Pull complete 
3b3c21ce1f8c: Pull complete 
560ed84bbbcc: Pull complete 
281a19a6c438: Pull complete 
18da4224859f: Pull complete 
db37dddcd8a5: Pull complete 
f28e0cb1c396: Pull complete 
36198d43a034: Pull complete 
ab62db7cb331: Pull complete 
Digest: sha256:88f24f03179a2f7b77303b45f1e711d239552af6d64b6e2db461e9b9e46d2077                                                  
Status: Downloaded newer image for n8nio/n8n:latest                                                                              
Initializing n8n process                                                                                                         
n8n ready on 0.0.0.0, port 5678                                                                                                  
Version: 0.157.1                                                                                                                 
                                                                                                                                 
Editor is now accessible via:                                                                                                    
http://localhost:5678/    

[root@freud ~]# docker-compose --version                                                                                         
docker-compose version 1.29.2, build 5becea4c       
                                                                             
[root@freud ~]# sudo docker-compose up -d                                                                                        
sudo: docsudo: command not found

Looks like you are using a root user account, so you might not need sudo here.

Could you try running docker-compose up -d on its own?

1 Like

Thank you; slowly moving forward. When I enter “docker-compose up -d”, I get error message
Can’t find a suitable configuration file in this directory or any
parent. Are you in the right directory?

    Supported filenames: docker-compose.yml, docker-compose.yaml, compose.yml, compose.yaml 

I executed set-up instructions above, created /root/.n8n/.env file and folders like this:
env

Can you please assist further, what is wrong?

Hey @Dimitri_Korenev,

So I wouldn’t have the .env file and docker-compose.yml in that directory I would probably make a /root/docker/ folder or something like that and put the files in there as the container itself has access to that directory.

To actually answer your issue though I suspect you are running the command from a different folder so you would first need to change into the directory that contains the file and run the command from there. Based on your current setup it would be something like…

cd /root/.n8n
docker-compose up -d

Thank you! Done according to instruction. Now getting following error (what it do?):

[root@freud .n8n]# docker-compose up -d
Creating network “n8n_default” with the default driver
Pulling traefik (traefik:)…
latest: Pulling from library/traefik
97518928ae5f: Pull complete
8f1084cd7998: Pull complete
7f585f616a11: Pull complete
c4f598fe2b15: Pull complete
Digest: sha256:2f603f8d3abe1dd3a4eb28960c55506be48293b41ea2c6ed4a4297c851a57a05
Status: Downloaded newer image for traefik:latest
Creating n8n_traefik_1 …
Creating n8n_traefik_1 … error
WARNING: Host is already in use by another container

ERROR: for n8n_traefik_1 Cannot start service traefik: driver failed programming external connectivity on endpoint n8n_traefik_1
(b7c40646fb7ed1f82ed4a6141fcd9330c3889b984b6d30f7b388f667fb2ff277): Error starting userland proxy: listen tcp4 0.0.0.0:443: bind
Creating n8n_n8n_1 … done

ERROR: for traefik Cannot start service traefik: driver failed programming external connectivity on endpoint n8n_traefik_1 (b7c4
0646fb7ed1f82ed4a6141fcd9330c3889b984b6d30f7b388f667fb2ff277): Error starting userland proxy: listen tcp4 0.0.0.0:443: bind: addr
ess already in use
ERROR: Encountered errors while bringing up the project.
[root@freud .n8n]# docker-compose stop
Stopping n8n_n8n_1 … done
[root@freud .n8n]# docker-compose up -d
Starting n8n_traefik_1 …
Starting n8n_traefik_1 … error
WARNING: Host is already in use by another container

ERROR: for n8n_traefik_1 Cannot start service traefik: driver failed programming external connectivity on endpoint n8n_traefik_1
(311cfa3c70ef37424df7119ce1e26cde29c047ce846e85a7bcb2abedfae14098): Error starting userland proxy: listen tcp4 0.0.0.0:443: bind
Starting n8n_n8n_1 … done

ERROR: for traefik Cannot start service traefik: driver failed programming external connectivity on endpoint n8n_traefik_1 (311c
fa3c70ef37424df7119ce1e26cde29c047ce846e85a7bcb2abedfae14098): Error starting userland proxy: listen tcp4 0.0.0.0:443: bind: addr
ess already in use
ERROR: Encountered errors while bringing up the project.
[root@freud .n8n]#

Hey @Dimitri_Korenev,

That error would suggest your server already has something installed that is listening on port 443 do you have any other web services running?

Hi Jon,

here is the list of ports
[root@freud ~]# lsof -i -P -n | grep LISTEN
systemd 1 root 34u IPv4 3211708807 0t0 TCP *:111 (LISTEN)
sshd 421 root 3u IPv4 3211671181 0t0 TCP *:22 (LISTEN)
sshd 421 root 4u IPv6 3211671183 0t0 TCP *:22 (LISTEN)
php-fpm 425 root 6u IPv4 3211703178 0t0 TCP 127.0.0.1:9000 (LISTEN)
exim 434 exim 3u IPv4 3211714634 0t0 TCP *:25 (LISTEN)
exim 434 exim 4u IPv4 3211714635 0t0 TCP *:465 (LISTEN)
exim 434 exim 5u IPv4 3211714636 0t0 TCP *:587 (LISTEN)
named 491 named 21u IPv6 3211708134 0t0 TCP *:53 (LISTEN)
named 491 named 22u IPv4 3211708138 0t0 TCP 127.0.0.1:53 (LISTEN)
named 491 named 23u IPv4 3211708140 0t0 TCP 194.67.105.122:53 (LISTEN)
named 491 named 24u IPv4 3211703084 0t0 TCP 127.0.0.1:953 (LISTEN)
named 491 named 25u IPv6 3211703085 0t0 TCP [::1]:953 (LISTEN)
named 491 named 26u IPv4 3218517170 0t0 TCP 172.17.0.1:53 (LISTEN)
named 491 named 27u IPv4 3218548378 0t0 TCP 172.18.0.1:53 (LISTEN)
dovecot 504 root 24u IPv4 3211708068 0t0 TCP *:110 (LISTEN)
dovecot 504 root 25u IPv4 3211708069 0t0 TCP *:995 (LISTEN)
dovecot 504 root 37u IPv4 3211708092 0t0 TCP *:143 (LISTEN)
dovecot 504 root 38u IPv4 3211708093 0t0 TCP *:993 (LISTEN)
httpd 525 root 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
php-fpm 527 apache 0u IPv4 3211703178 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 528 apache 0u IPv4 3211703178 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 529 apache 0u IPv4 3211703178 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 530 apache 0u IPv4 3211703178 0t0 TCP 127.0.0.1:9000 (LISTEN)
php-fpm 531 apache 0u IPv4 3211703178 0t0 TCP 127.0.0.1:9000 (LISTEN)
nginx 541 root 17u IPv4 3211706329 0t0 TCP 194.67.105.122:443 (LISTEN)
nginx 541 root 18u IPv4 3211706330 0t0 TCP *:80 (LISTEN)
nginx 541 root 19u IPv6 3211706331 0t0 TCP [2a00:f940:2:1:2:0:1:4649]:80 (LISTEN)
nginx 541 root 20u IPv6 3211706332 0t0 TCP [2a00:f940:2:1:2:0:1:4649]:443 (LISTEN)
nginx 543 apache 17u IPv4 3211706329 0t0 TCP 194.67.105.122:443 (LISTEN)
nginx 543 apache 18u IPv4 3211706330 0t0 TCP *:80 (LISTEN)
nginx 543 apache 19u IPv6 3211706331 0t0 TCP [2a00:f940:2:1:2:0:1:4649]:80 (LISTEN)
nginx 543 apache 20u IPv6 3211706332 0t0 TCP [2a00:f940:2:1:2:0:1:4649]:443 (LISTEN)
ihttpd 547 root 6u IPv4 3211706349 0t0 TCP *:1500 (LISTEN)
httpd 563 apache 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
httpd 564 apache 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
proftpd 565 nobody 0u IPv6 3211709654 0t0 TCP *:21 (LISTEN)
/usr/bin/ 567 root 5u IPv4 3211712814 0t0 TCP 127.0.0.1:783 (LISTEN)
/usr/bin/ 567 root 6u IPv6 3211712816 0t0 TCP [::1]:783 (LISTEN)
mysqld 583 mysql 23u IPv4 3211671281 0t0 TCP *:3306 (LISTEN)
spamd 597 root 5u IPv4 3211712814 0t0 TCP 127.0.0.1:783 (LISTEN)
spamd 597 root 6u IPv6 3211712816 0t0 TCP [::1]:783 (LISTEN)
spamd 598 root 5u IPv4 3211712814 0t0 TCP 127.0.0.1:783 (LISTEN)
spamd 598 root 6u IPv6 3211712816 0t0 TCP [::1]:783 (LISTEN)
httpd 1071 apache 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
httpd 4178 apache 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
httpd 6130 apache 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
docker-pr 16821 root 4u IPv4 3218751548 0t0 TCP 127.0.0.1:5678 (LISTEN)
httpd 22599 apache 3u IPv4 3211662100 0t0 TCP 127.0.0.1:8080 (LISTEN)
shellinab 22829 root 4u IPv4 3220554507 0t0 TCP 127.0.0.1:60655 (LISTEN)

Hey @Dimitri_Korenev,

You have 443 in there so I suspect it could be that as you have Traefik set to bind to all IPs on port 443. Do you know what web service or container you have running that is using that port, Would be worth stopping it to see what happens.

You also have Apache running port 80 which may cause other issues with getting the Lets Encrypt certificate.

Hi Jon,

I have several sites running on server, so I can not start changing of ports of Apache or Nginx and danger the sites. Stoppign sites to see what happens is not a solution either)))) That are critical applications. What else can I do to run n8n on my server?

Hey @Dimitri_Korenev,

Are you running a reverse proxy?

Hi Jon, I have no clue what is reverse proxy))) That is server I purchaised for hosting of php, sites etc. So my task is to check how to install n8n to run integration processes))

Which Unix order should I run to answer your question?

Hey @Dimitri_Korenev,

It is a bit trickier than that, So the first thing you could try is to change the Traefik ports but if you are running multiple sites I would imagine you are using virtual hosts or mod proxy.

What you could do is configure an Apache virtual host to act as a proxy and send the requests back to the n8n container. Then you can remove the Traefik part from your compose file and you can then handle your SSL certs in whatever way you normally would.

As an example your Apache virtual host may look something like the below (untested - I am not that familiar with Apache).

<VirtualHost *:80>
  ServerName n8n.host.com
  ProxyPass / http://127.0.0.1:5678
  ProxyPassReverse / http://127.0.0.1:5678
</VirtualHost>

This would assume a compose file that is something like:

version: "3"

services:
  n8n:
    image: n8nio/n8n
    restart: always
    ports:
      - "127.0.0.1:5678:5678"
    environment:
      - N8N_BASIC_AUTH_ACTIVE=true
      - N8N_BASIC_AUTH_USER
      - N8N_BASIC_AUTH_PASSWORD
      - N8N_HOST=${SUBDOMAIN}.${DOMAIN_NAME}
      - N8N_PORT=5678
      - N8N_PROTOCOL=https
      - NODE_ENV=production
      - WEBHOOK_URL=https://${SUBDOMAIN}.${DOMAIN_NAME}/
      - GENERIC_TIMEZONE=${GENERIC_TIMEZONE}
    volumes:
      - ${DATA_FOLDER}/.n8n:/home/node/.n8n

The examples above are untested and your server configuration may mean the examples need to be tweaked to fit with your environment.

1 Like

Jon, thank you, but I am not a programmer, and have no clue what you mean. Which compose file? Thich Apache confoguration file??? Are there any functioning instructions???

I assume this is not the first case where people wanna install n8n on their own server))) So can you please provide functioning instruction how can I install n8n on my server???

Your colleague MutedJam suggested to user Docker according to documentation, but this approach fully fails! Before I tried to use npx. Other alternative is to use npm?

What is functioning??? Or if you suggest to manipulate Apache, where can I find instructions (which files, where to find, etc)?

Hey @Dimitri_Korenev,

You are correct it is not the first time someone wants to install n8n on their server but every server is different just like your desktop machine or laptop will be configured in a different way to mine.

While I would love to give you detailed steps I can only provide a certain level of information as I have no idea how you have your server configured as there are many different ways to do it.

The above suggestion will work but it does come with a general assumption that you know where your servers configuration files are for what you have already set up.

When you configure everything for the existing sites do you remember what you installed and where the config files are? Normally it would be something like /etc/apache2/sites-available but if you used docker for your web server that would be different.

The docker-compose file would be under /root/.n8n unless you moved it as suggested previously.

If you are able to provide more information on how you setup what you have now I may be able to provide more information.