Cannot install node-red on Ubuntu 18.04 - Even using source

Hi all

Keep it short, here is the error I got:

As you can see, I am using sudo npm install --production, but it still shows Permission denied.

alucard@chatbot:/home/alucard/node-red/node-red-0.19.5$ sudo npm install --production
npm WARN deprecated formatio@1.1.1: This package is unmaintained. Use @sinonjs/formatio instead
npm WARN deprecated mailparser@0.6.2: Mailparser versions older than v2.3.0 are deprecated
npm WARN deprecated nodemailer@1.11.0: All versions below 4.0.1 of Nodemailer are deprecated. See https://nodemailer.com/status/
npm WARN deprecated nomnom@1.8.1: Package no longer supported. Contact support@npmjs.com for more info.
npm WARN deprecated mimelib@0.3.1: This project is unmaintained
npm WARN deprecated mailcomposer@2.1.0: This project is unmaintained
npm WARN deprecated buildmail@2.0.0: This project is unmaintained

> bcrypt@2.0.1 install /home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt
> node-pre-gyp install --fallback-to-build

node-pre-gyp ERR! Pre-built binaries not installable for bcrypt@2.0.1 and node@11.1.0 (node-v67 ABI, glibc) (falling back to source compile with node-gyp)
node-pre-gyp ERR! Hit error EACCES: permission denied, mkdir '/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib'
gyp WARN EACCES user "root" does not have permission to access the dev dir "/root/.node-gyp/11.1.0"
gyp WARN EACCES attempting to reinstall using temporary dev dir "/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/.node-gyp"
gyp WARN install got an error, rolling back install
gyp WARN install got an error, rolling back install
gyp ERR! configure error
gyp ERR! stack Error: EACCES: permission denied, mkdir '/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/.node-gyp'
gyp ERR! System Linux 4.15.0-38-generic
gyp ERR! command "/usr/bin/node" "/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "configure" "--fallback-to-build" "--module=/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib/binding/bcrypt_lib.node" "--module_name=bcrypt_lib" "--module_path=/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib/binding" "--napi_version=3" "--node_abi_napi=napi"
gyp ERR! cwd /home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt
gyp ERR! node -v v11.1.0
gyp ERR! node-gyp -v v3.8.0
gyp ERR! not ok
node-pre-gyp ERR! build error
node-pre-gyp ERR! stack Error: Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi' (1)
node-pre-gyp ERR! stack     at ChildProcess.<anonymous> (/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/node_modules/node-pre-gyp/lib/util/compile.js:83:29)
node-pre-gyp ERR! stack     at ChildProcess.emit (events.js:182:13)
node-pre-gyp ERR! stack     at maybeClose (internal/child_process.js:970:16)
node-pre-gyp ERR! stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:257:5)
node-pre-gyp ERR! System Linux 4.15.0-38-generic
node-pre-gyp ERR! command "/usr/bin/node" "/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/node_modules/.bin/node-pre-gyp" "install" "--fallback-to-build"
node-pre-gyp ERR! cwd /home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt
node-pre-gyp ERR! node -v v11.1.0
node-pre-gyp ERR! node-pre-gyp -v v0.9.1
node-pre-gyp ERR! not ok
Failed to execute '/usr/bin/node /usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js configure --fallback-to-build --module=/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib/binding/bcrypt_lib.node --module_name=bcrypt_lib --module_path=/home/alucard/node-red/node-red-0.19.5/node_modules/bcrypt/lib/binding --napi_version=3 --node_abi_napi=napi' (1)
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN node-red-node-test-helper@0.1.7 requires a peer of node-red@~0.18.4 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bcrypt@2.0.1 (node_modules/bcrypt):
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: bcrypt@2.0.1 install: `node-pre-gyp install --fallback-to-build`
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: Exit status 1

added 319 packages from 314 contributors and audited 6871 packages in 30.197s
found 1 low severity vulnerability
  run `npm audit fix` to fix them, or `npm audit` for details

And no matter I run sudo npm install -g --unsafe-perm node-red or downloading source, when I run node-red, I got:

alucard@chatbot:/home/alucard/node-red/node-red-0.19.5$ node-red
path.js:39
    throw new ERR_INVALID_ARG_TYPE('path', 'string', path);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.join (path.js:1155:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-red/red.js:94:50)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:308:19)

node -v: v11.1.0
npm -v: 6.4.1
Ubuntu: 18.04.

Hope someone can help me.

Thank you very much in advance for your help.

The first error was because you weren't using the --unsafe-perm flag.

The second error shows you've successfully installed node-red, but you hit an error when trying to start.

The line hitting the error in particular is this one: https://github.com/node-red/node-red/blob/master/red.js#L94 where it is trying to locate your home directory.

That suggests you do not have any of HOME, HOMEPATH or USERHOME set in your environment - that is the only way an undefined would get passed to the the join call throwing an error.

I note you're using Node 11 - which we don't currently test against. I've done a quick sniff test and I see HOME is set for me when running node 11, so that won't be the root cause. There may of course be other issues with Node 11, but this isn't one.

what does echo $HOME return?

I don't know whether it is of interest but you can use the Pi bash <(curl script to install on Ubuntu. That is how I do it.
https://nodered.org/docs/hardware/raspberrypi

Thanks @knolleary and @Colin for the replies.

  • Under Ubuntu 18.04, echo $HOME return nothing. I have to manually set this variable in my .bashrc to run that.
  • I remember that when I first run sudo npm install -g --unsafe-perm node-red, I have this --unsafe-perm parameters. Today I run it again and it works now.

So now when I run sudo node-red, it works~

Thank you very much again for your support.

is there a specific reason you want to start Node-RED with sudo?
If not it is better practice to run without using sudo

Oh, @ukmoose, Thanks for the question.

The only reason why I use sudo node-red is that it works.

If I use node-red (without sudo), I will have the following error:

alucard@chatbot:~/chatbot/chatbot-python$ node-red
path.js:39
    throw new ERR_INVALID_ARG_TYPE('path', 'string', path);
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type undefined
    at assertPath (path.js:39:11)
    at Object.join (path.js:1155:7)
    at Object.<anonymous> (/usr/local/lib/node_modules/node-red/red.js:94:50)
    at Module._compile (internal/modules/cjs/loader.js:707:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:718:10)
    at Module.load (internal/modules/cjs/loader.js:605:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:544:12)
    at Function.Module._load (internal/modules/cjs/loader.js:536:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:760:12)
    at startup (internal/bootstrap/node.js:308:19)

The HOME variable I added is in my home directory: /home/alucard defined in my ~/.bashrc file, not the one from root account. Since I am not quite familiar with this config (the HOME var), when it works, I don't think too much about it. :smiley:

I understand that it is not a very good practice, but I don't quite sure what to do with it, so I leave it as it is.

Hope you can understand.


Quick update:

When I enter: nohup node-red -u /home/alucard/my_self_defined_directory &, it works nicely.

Thank you.