Linux: installing global npm packages without using sudo (a.k.a. resolving EACCES permissions errors when installing packages globally)

1. Create a directory where global packages will be deployed:

mkdir ~/.npm-global

2. Set the newly created directory as default global directory for npm:

npm config set prefix '~/.npm-global'

3. Update the $PATH environment variable by adding this to your .profile file (in your user home directory) so that the terminal knows where to find the global packages:

export PATH=~/.npm-global/bin:$PATH

4. Reload environment in current shell by running (or just open a new one):

source ~/.profile

5. Test if the setup was successful by installing a package (without using sudo):

npm i -g jshint

6. And running it (should print out jshint version):

jshint --version

Stay healthy!

Вашият коментар

Вашият имейл адрес няма да бъде публикуван.