Using npm to install file to /usr/local/bin
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
Related videos on Youtube

user1048676
Updated on September 18, 2022Comments
-
user1048676 3 months
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?
-
Admin almost 4 yearsAnd then read up on the issues associated with running tools like this as root: stackoverflow.com/q/4938592/1531971
-
user1048676 almost 4 years@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?
-
user1048676 almost 4 years@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
-
Yaron almost 4 years@user1048676 - in Ubuntu you don't need to use the user
root
, you can prefixsudo
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 answersudo npm install -g price-feeder
? -
user1048676 almost 4 years@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
-
user1048676 almost 4 yearsI got it figured out. Accepting your answer. Thanks