One common issue that often crops up is the "Missing write access to /usr/local/lib/node_modules"
error when trying to install npm packages globally. In this guide, we'll unravel this problem and provide you with a quick and effective solution. So, whether you're a seasoned Linux enthusiast or a newcomer, let's dive in and get your npm packages up and running without a hitch.
Solving the issue: Fixing the Permission Error
The root cause of this problem lies in a permission error that prevents you from writing to the specified folder. The solution? Let's grant ourselves the necessary permissions. Follow these steps:
- Open your terminal.
- Execute the following command:
sudo chown -R $USER /usr/local/lib/node_modules
This command essentially changes the ownership of the /usr/local/lib/node_modules directory to your user account, granting you the required write access to successfully install npm packages globally.
If you still get error, try this:
sudo npm i -g <package name>