n (node version manager): cannot create directory

1.7k Views Asked by At

On lubuntu 14.10. I'm trying to update node with "n" (node version manager)

Installed with:

sudo npm install -g n

without "sudo" it would fail asking for admin privileges...

when trying to use "n", I always get "cannot create directory", "permission denied".

How to make "n" use the proper permissions?

2

There are 2 best solutions below

0
tokosh On BEST ANSWER

I think the best way to install n is to use n-install.

2
shadowspawn On

Older versions of n tried to create the cache folder /usr/local/n no matter what command was run.

Since n v3.0.2, the cache folder is only created when needed. This allows you to run read-only command like n --lts without using sudo.

(Note that an install does require write permission to the cache folder and to the install folder, so you either need to use sudo, or define N_PREFIX to a writeable location, or change permissions/ownership of the install location.)