Terminus by Warp
Re-Installing Npm

Re-Installing Npm

Razvan Ludosanu
Razvan Ludosanu
Founder, learnbackend.dev

The short answer

In some cases, you might end up with a broken installation of [.inline-code]npm[.inline-code], preventing you from managing your locally or globally installed packages.

To force reinstall the [.inline-code]npm[.inline-code] command-line tool on macOS and Linux, you can run the following [.inline-code]curl[.inline-code] command:

 $ curl -qL https://www.npmjs.com/install.sh | sh

That will fetch and execute the official npmjs installation script.

Once executed, you can verify that the installation was successful by displaying the current version of [.inline-code]npm[.inline-code] using the [.inline-code]-v[.inline-code] option flag:

 $ npm -v

Note that if you're facing incompatibility issues between your [.inline-code]npm[.inline-code] and [.inline-code]node[.inline-code] versions, or you simply want to update [.inline-code]npm[.inline-code] to a higher version, you can read our article on how to update [.inline-code]npm[.inline-code] globally or per project.

[#easily-recall-with-ai]Easily retrieve this command using Warp’s AI Command Search[#easily-recall-with-ai]

If you’re using Warp as your terminal, you can easily retrieve this command using the Warp AI Command Search feature:

Entering [.inline-code]reinstall npm with curl[.inline-code] in the AI Command Search will prompt a [.inline-code]curl[.inline-code] command that can then quickly be inserted into your shell by doing [.inline-code]CMD+ENTER[.inline-code].

Reinstalling Node.js and npm using the terminal

Since, by default, Node.js and npm are bundled together, reinstalling [.inline-code]node[.inline-code] will also reinstall [.inline-code]npm[.inline-code] to its latest supported version, thus avoiding compatibility issues.

[#reinstall-with-brew]Reinstalling Node.js on MacOS with [.inline-code]brew[.inline-code][#reinstall-with-brew]

To reinstall Node.js on MacOS with Homebrew, you can use the [.inline-code]brew reinstall[.inline-code] command:

 $ brew reinstall node@ <version>

Where [.inline-code]<version>[.inline-code] is the current version of Node.js in use, which can be found using the [.inline-code]node -v[.inline-code] command.

For example:

$ node -v
v20.2.0
$ brew reinstall node@20

[#reinstall-with-apt]Reinstalling Node.js on Linux with [.inline-code]apt[.inline-code][#reinstall-with-apt]

To reinstall Node.js on Linux with [.inline-code]apt[.inline-code], you have to start by uninstalling it using the [.inline-code]remove[.inline-code], [.inline-code]purge[.inline-code], and [.inline-code]autoremove[.inline-code] commands:

$ sudo apt remove nodejs
$ sudo apt purge nodejs
$ sudo apt autoremove

Which will remove the current Node.js distribution from your system, as well as its configuration files, and any other unused packages that were installed with it.

Once you've done that, you can reinstall Node.js using the following command:

 $ sudo apt install nodejs

[#reinstall-with-nvm]Reinstalling Node.js on macOS, Linux, and Windows with [.inline-code]nvm[.inline-code][#reinstall-with-nvm]

If you are using [.inline-code]nvm[.inline-code] as your Node.js version manager, you can start by deactivating the desired Node.js version using the [.inline-code]deactivate[.inline-code] command:

 $ nvm deactivate <version>

As you might otherwise get the following error message:

 nvm: Cannot uninstall currently-active node version

You can then remove it from your system using the [.inline-code]uninstall[.inline-code] command:

 $ nvm uninstall <version>

Then, reinstall it using the [.inline-code]install[.inline-code] command:

 $ nvm install <version>

And finally set it as your current version using the [.inline-code]use[.inline-code] command:

 $ nvm use <version>

For example, to reinstall Node.js version 20:

$ nvm deactivate 20
$ nvm uninstall 20
$ nvm install 20
$ nvm use 20

[#reinstall-with-node]Reinstalling Node.js and npm using the Node installer [#reinstall-with-node]

Whether you're using macOS, Linux, or Windows, the easiest way to reinstall Node.js using the graphical interface is to visit the official Node.js website at https://nodejs.org/en/download.

Then click on the desired distribution to download the GUI installer program.

Experience the power of Warp

  • Write with an IDE-style editor
  • Easily navigate through output
  • Save commands to reuse later
  • Ask Warp AI to explain or debug
  • Customize keybindings and launch configs
  • Pick from preloaded themes or design your own
brew install --cask warp
Copied!
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.
Join the Linux waitlist or join the Windows waitlist
Join the Windows waitlist:
Success! You will receive an email from Warp when the release is available to download.
Oops! Something went wrong while submitting the form.