Where should node and node_modules be installed on Centos 7?

512 Views Asked by At

I am trying to install the Ghost blogging platform as a Node module on Centos 7 box. My question is: Where should node, npm, and node_modules be installed, ideally?

Currently, I have ghost installed in /var/www/ghost, and there are 50+ node modules in /var/www/ghost/node_modules/ (some of those modules have their own subdirectories called /node_modules/).

The Node binary itself is in /usr/local/bin, and forever and npm are in /usr/local/lib/node_modules/. /usr/local/bin and /usr/local/lib are owned by "500" (a system user?), and the files in /usr/local/... are owned by root.

However, I'm having all sorts of problems--As user A, ghost runs but forever fails, and the opposite happens as user B (forever works but ghost fails); NPM says I need to sudo; then when I use sudo it says "command npm not found;" Yarn fails, etc.

I'm guessing that I just have a tangle of permissions problems caused by installing modules in the wrong directories. The only complication is that I want Node to be installed system-wide but I want most of the processes to be run by unprivileged users:

  • For security, the ghost processes should be run by an unprivileged user, and I think Node should be as well;
  • I want to run ghost long-term using either forever or pm2 (which are also Node modules), and they should also be run by an unprivileged user;
  • Node must be installed system-wide (the Ghost installation documents say: "Ghost requires a system-wide installation. It is not enough to symlink the local installation to /usr/bin/node," and they strongly recommend against using NVM). I don't know if it's relevant, but I plan to do future non-Ghost projects (Node/Express/D3, etc.) based on the same Node installation.
  • I need to be able to update everything with NPM or Yarn.
0

There are 0 best solutions below