0
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 variablesTest the new configuration by installing the package globally without sudo:
npm install -g nodemon@1.18.4 --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.
Good morning Raiany, td well ? Apparently it’s a permission issue, basically you’re not allowed to access these directories, try running the command like this: sudo npm install -g nodemon@1.18.4 --save-dev --save-Exact
– Gabriel José de Oliveira
sudo npm install -g nodemon@1.18.4 --save-dev --save-exact
. Read SUDO: What is "sudo su" on Linux?– Augusto Vasques