A place to breathe

Wednesday, February 15, 2017

Changing NPM default module folders

When you install NPM on Linux, it will install into the root location by default. Often times, it could cause trouble if you want to modify the node_modules. 

To know where the node_modules are going to be installed globally: 

%> npm config get prefix
/usr

Now, I don't want to play around with the '/usr' permission because it is a standard OS directory. Trying to modify some stuff for node and have to deal with the top root directories is just not worth it. 

Now, change the NPM prefix: 

%> npm config set prefix=$HOME/.node_modules_global

so test it now: 
%> npm config get prefix

You should see that it list :
/path/to/home/.node_modules_global 

Change the path inside your .bash_profile: 
%> export PATH="$HOME/.node_modules_global/bin:$PATH

OK, now update your environment: 
%> source .bash_profile

Try installing an NPM just to check whether the global works: 
%> npm install npm --global
%> npm --version 

You should see your version changes from previously because it is now getting the latest npm.



No comments:

About Me

I'm currently a software engineer. My specific interest is games and networking. I'm running software company called Nusantara Software.