Created
April 7, 2019 17:47
-
-
Save faryar76/95f6578bd287562918351f23b0bc7a3b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
base on https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally | |
Reinstall npm with a node version manager§ | |
This is the best way to avoid permissions issues. To reinstall npm with a node version manager, follow the steps in “Downloading and installing Node.js and npm”. You do not need to remove your current version of npm or Node.js before installing a node version manager. | |
Manually change npm’s default directory§ | |
Note: This section does not apply to Microsoft Windows. | |
To minimize the chance of permissions errors, you can configure npm to use a different directory. In this example, you will create and use hidden directory in your home directory. | |
Back up your computer. | |
On the command line, in your home directory, create a directory for global installations: | |
--------------mkdir ~/.npm-global | |
Configure npm to use the new directory path: | |
--------------npm config set prefix '~/.npm-global' | |
In your preferred text editor, open or create a ~/.profile file and add this line: | |
--------------export PATH=~/.npm-global/bin:$PATH | |
On the command line, update your system variables: | |
--------------source ~/.profile | |
To test your new configuration, install a package globally without using sudo: | |
--------------npm install -g jshint | |
Instead of steps 2-4, you can use the corresponding ENV variable (e.g. if you don’t want to modify ~/.profile): | |
--------------NPM_CONFIG_PREFIX=~/.npm-global |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment