npm install not installing things at /usr/bin

Tag: node.js , ubuntu , sails.js , ubuntu-13.04 Author: youngestgirl Date: 2014-03-30

I am trying to install SailsJS with:

$ sudo npm install -g sails

It works, install everything at /home/brunoluiz/npm/lib/node_modules/sails with the following log:

/home/brunoluiz/npm/bin/sails -> /home/brunoluiz/npm/lib/node_modules/sails/bin/sails.js
[email protected] /home/brunoluiz/npm/lib/node_modules/sails
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected]
??? [email protected] ([email protected], [email protected])
??? [email protected] ([email protected])
??? [email protected] ([email protected])
??? [email protected] ([email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected])
??? [email protected] ([email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected])
??? [email protected] ([email protected])
??? [email protected] ([email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected])
??? [email protected] ([email protected], [email protected], less@1.6.3)
??? socket.io@0.9.14 (base64id@0.1.0, policyfile@0.0.4, redis@0.7.3, socket.io-client@0.9.11)

The problem is when you try to use sails: you run "sails new project", for example, and it don't find sails. Investigating a little bit, I discovered that the npm is not installing the modules at /usr/bin. There is some reason for that? Some config?

The same is happening with Karma module.

I used the nodejs from ppa, created the symbolic link for node and installed npm from the official install.sh script (https://www.npmjs.org/install.sh).

Best Answer

It sounds like your npm installation is configured to use /home/brunoluiz/npm as prefix, meaning that it will place symlinks to the CLIs that come with globally installed packages in {prefix}/bin.

In a default installation, prefix is either /usr or /usr/local on Unix platforms (%APPDATA%/npm on Windows).

If {prefix}/bin is not in your $PATH, you won't be able to execute such CLIs just by name.

To see the current prefix value in effect, run:

npm get prefix

Your options are:

  • Add /home/brunoluiz/npm/bin to your $PATH

  • Change the value of the prefix configuration item to a folder whose bin subfolder is already in your $PATH; e.g.:

    npm set prefix /usr       # Ubuntu; CLI symlinks are placed in /usr/bin
    npm set prefix /usr/local # OSX; CLIs symlinks are placed in /usr/local/bin

Note, however, that you'd then have to reinstall your global packages for the symlinks to be created in the new {prefix}\bin location.

comments:

I used the first option, putting it at the $PATH using an export at ~/.bashrc. At the last line I added "export PATH=$PATH:$HOME/npm/bin" and then gave one "source ~/.bashrc" at the terminal
@BrunoLuiz: Sounds great. For both my benefit and that of future readers: If an answer solved your problem, please accept it by clicking the large check mark next to it; if you found an answer at least helpful, please up-vote it by clicking the up-arrow icon.