NPM / Missing write access error when using npm

test

sudo chown -R $USER /usr/local/lib/node_modules

Let’s break it down:

sudo means we are running this command as root, the system super user. This is because we don’t have permission to write to that folder, but root will be able to fix any permission. This command also means the system will ask for your password to confirm.

chown is the command we use to change the owner of a file or folder. We set the -R option to change the owner recursively, so we also get owner access to all the files already contained in there.

$USER is an environment variable automatically set to your username.

And the final piece is the folder path.

Running this path will make the folder yours, so you can safely run your npm install -g <package> commands!

Pay attention to the folder listed by the error message. If it’s different, update the chown command accordingly.