Error installing nodemon globally

Asked

Viewed 422 times

0

I have the following problem executing this command:

npm install -g [email protected] --save-dev --save-exact

Could someone help me?

inserir a descrição da imagem aqui

2 answers

2

Avoid running commands npm sudo. It may seem the easiest solution, but it opens the door for malicious scripts to run on your machine. This article talks a little about the subject.

Recommended solution

The solution officially recommended by npm is to reinstall npm using the Node version manager. The installation is very simple and explained in official repository of the project.

Workaround

If use nvm is not an option, the other recommendation is to manually change the npm directory:

  • Back up your machine
  • On the command line, being in the directory home, create a directory to install global packages: mkdir ~/.npm-global

  • Configure npm to use this new directory: npm config set prefix '~/.npm-global'

  • Add this new directory to PATH: Create or open the file ~/.profile and add this line: export PATH=~/.npm-global/bin:$PATH

  • Restart the terminal or run source ~/.profile to update the environment variables

  • Test the new configuration by installing the package globally without sudo: npm install -g [email protected] --save-dev --save-exact

Even better

If you are using npm 5.2 or higher, you can use the npx as an alternative to global packages. This article talks more about the subject.

1


Just use "SUDO", this is access permission error

sudo npm install -g [email protected] --save-dev --save-exact

Browser other questions tagged

You are not signed in. Login or sign up in order to post.