Missing write access to /usr/local/lib/node_modules means that there is no write permission. The official solution given by npm is to create a new folder with permissions and install the npm package in this new folder. This method does not apply to Microsoft Windows System.
Create a folder in the user's root directory (the name does not have to be .npm-global, you can choose it yourself):
mkdir ~/.npm-global
1
Set the installation path of npm global package:
npm config set prefix '~/.npm-global'
1
Check if there is a .profile file in the user's root directory. If not, create it, then open it with a text editor, add the following line, and save:
export PATH=~/.npm-global/bin:$PATH
1
Return to the terminal and run the following command to make the configuration take effect:
source ~/.profile
1
and then install the npm package globally.
Resolving EACCES permissions errors when installing packages globally