Home > Software engineering >  How to install npm after it uninstalled itself?
How to install npm after it uninstalled itself?

Time:03-16

I was recommended to run sudo npm install -g npm and so I did, now npm is gone!

It doesn't exist in the directory either /usr/local/lib/node_modules/.

Is there a way to install it back?

edit

I have node installed v14.17.0

CodePudding user response:

you can use NVM(nodejs version manager) simply by running this command :

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

and

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

now you can download any version of nodejs and use it into the single project or globally without problems

if you need to download any version you can do it by the comand : nvm install 14

now you have npm and node 14, but if you need to use it into the project you can do it by the command : nvm use 14

now you can switch between node(or npm) versions without any problem

CodePudding user response:

npm comes with nodejs, you can just install nodejs using your OS.

See the link below

enter image description here

Once you install nodejs, npm will be installed.

  • Related