2

I tried to install a file using the following command:

npm install -g price-feeder

It's supposed to be installed in the /usr/local/bin folder since it's using the global parameter to be accessible from a cron job. For some reason it's being installed in the following location though:

/.nvm/versions/node/v8.9.4/bin/

Any idea if there is a setting or something that would need to be set for the global parameter to install in the correct place?

1 Answer 1

3

To see npm current prefix value in effect, run:

npm get prefix

As described in install-and-configure-nodejs-and-npm-properly-on-ubuntu

You can set npm prefix e.g.:

$  npm config set prefix /usr/local

Note: Official NPM docs specify that:

When in global mode, executables are linked into {prefix}/bin on Unix

Hence, your npm prefix shouldn't include the /bin suffix

In order to install in a system folder (e.g. /usr/local/bin) you should execute npm as root using sudo, e.g.:

sudo npm install -g price-feeder
6
  • 2
    And then read up on the issues associated with running tools like this as root: stackoverflow.com/q/4938592/1531971
    – user459652
    Dec 17, 2018 at 15:37
  • @Yaron I created a user and disabled root login etc, is there a way to run it as a root user from my created user? Dec 17, 2018 at 15:56
  • @Yaron Also, when I did this I got an error: checkPermissions Missing write access to /usr/local/lib. When I did the npm get prefix it showed me the /usr/local path without the big as you pointed out but now looking at the lib folder instead of bin by the looks of it Dec 17, 2018 at 16:00
  • @user1048676 - in Ubuntu you don't need to use the user root, you can prefix sudo to your commands (assuming that your user holds the relevant permissions - which I assume is the case in your case) - did you try the running command in my answer sudo npm install -g price-feeder ?
    – Yaron
    Dec 17, 2018 at 16:05
  • @Yaron I got the message: sudo: npm: command not found. So I did sudo apt-get install npm but still getting the same error: checkPermissions Missing write access to /usr/local/lib Dec 17, 2018 at 16:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.