By default in MS Windows 10, the NPM global install path will use your user profile directory;
%USERPROFILE%\AppData\Roaming\npm
%USERPROFILE%\AppData\Roaming\npm-cache
Which translates to something like;
C:\Users\YOUR-USER-PROFILE-NAME\AppData\Roaming\npm
C:\Users\YOUR-USER-PROFILE-NAME\AppData\Roaming\npm-cache
The first path above contains 51 characters and the second contains 57 characters. Depending on the length or your user profile name, your path may be a little shorter or longer.
So the aim is to change the directories used when you install anything with NPM globally by using the -g flag to use directories with fewer characters.
Change the "global" NPM folders to %ALLUSERSPROFILE%\(npm|npm-cache)
- Your user account should be a member of the administrators group or you may need to enter your administrator password when prompted.
- Copy the existing 'npm' folder from
%USERPROFILE%\AppData\Roaming\
and paste into %ALLUSERSPROFILE%
Open a Windows command prompt and run the following commands;
npm config --global set prefix "C:\ProgramData\npm"
npm config --global set cache "C:\ProgramData\npm-cache"
This will add/update the contents of: %USERPROFILE%\AppData\Roaming\npm\etc\npmc
with;
prefix=C:\ProgramData\npm
cache=C:\ProgramData\npm-cache
The first path above now only contains 18 characters and the second contains just 24 characters.
Add/change the PATH variable for NPM
Navigate to 'Environment Variables' by following these steps;
Start > Settings > System > About > System info > Advanced system settings
Under the 'Advanced' tab click the 'Environment Variables...' button.
Select the 'PATH' variable and click the 'Edit...' button.
If there is already an entry for NPM like C:\Users\YOUR-USER-PROFILE-NAME\AppData\Roaming\npm, select it and click the 'Edit' button. Otherwise, click the 'New' button.
Paste C:\ProgramData\npm
and click the 'OK' button to save.
Finally, restart your computer.