When we are installing Node Modules there is this strongly recommended rule. Install Globally [-g], only modules that require command line [run from Shell]. Install Locally [current working directory] modules that will be required from your app, i.e
There are cases we need both. Don’t spare disk space, just install them in both locations!
Using Node from our package manager has two issues (it has more actually!)
- Sometimes it is critical to use an earlier or a later version from the one that our package manager provides.
- Installing/updating and removing the dozens of modules from NPM Registry, requires root privileges ..really?!
For a custom installation we just need to download the Node binary, place it somewhere and export the PATH. I’m not sure about the dependencies, so feel free to install node from your package manager. We are going to override this anyway.
$ sudo dnf install nodejs npm
Fedora ships NPM and Nodejs as two different packages and that brings confusion with the updates, since some Node updates only upgrade the NPM. Like it happened on version 0.10.28.
Get the binary from
Extract it and give it a nicer name.
$ mv node-v0.10.28-linux-x64 node-0.10.28
Place it somewhere
The typical place to put it is somewhere in our $HOME. Alternative we can place it under
/opt/ to keep a more tidy system.
Create a folder to host it (i.e myNode)
$ sudo mkdir /opt/myNode
Change the ownership
$ sudo chown Your-Username:Your-Username(group)
Move Node there, so the structure will be..
Export the PATH
$ gedit ~/.profile
export MY_NODE_PATH=/opt/myNode/node-0.10.28 export PATH=$MY_NODE_PATH/bin:$PATH
$ source ~/.profile
Test the changes
$ which node && which npm
If right, you should see
Notice that this will override your system-wide Node (if installed), while the changes will be permanent [without sourcing .profile] on your next relog.
Just install a module, for example Shelljs
$ npm install -g shelljs
$ whereis shjs
The modules are installed under
For alternative folders configuration [not really recommented] check the manual
- https://www.npmjs.org/doc/files/npm-folders.html [npm help folders]