You Got A Question? Ask    GNOME Community!


How To Install NodeJS Without Root Privillages

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 require('whatever').

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!)

  1. Sometimes it is critical to use an earlier or a later version from the one that our package manager provides.
  2. Installing/updating and removing the dozens of modules from NPM Registry, requires root privileges ..really?!

Installation

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.


Download

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..

/opt/myNode/node-0.10.28

Export the PATH

Open your ~/.profile

$ gedit ~/.profile

And add

export MY_NODE_PATH=/opt/myNode/node-0.10.28
export PATH=$MY_NODE_PATH/bin:$PATH

Source profile

$ source ~/.profile

Test the changes

$ which node && which npm

If right, you should see

/opt/myNode/node-0.10.28/bin/node
/opt/myNode/node-0.10.28/bin/npm

Notice that this will override your system-wide Node (if installed), while the changes will be permanent [without sourcing .profile] on your next relog.


Testing..

Just install a module, for example Shelljs

$ npm install -g shelljs

Test it

$ whereis shjs
shjs: /opt/myNode/node-0.10.28/bin/shjs

The modules are installed under

/opt/myNode/node-0.10.28/lib/node_modules

For alternative folders configuration [not really recommented] check the manual

 


 
  We can't watch comments unless G+ provides an API or if you send a notification, e.g +World Of Gnome
     Sometimes is better to place your questions on GNOME Community