• Modern UX

    Edit and navigate faster in the terminal with Warp's IDE-like input editor.

  • Warp AI

    AI suggests what commands to run and learns from your documentation.

  • Agent Mode

    Delegate tasks to AI and use natural language on the command line.

  • Warp Drive

    Save and share interactive notebooks, workflows, and environment variables.

  • All Features

Re-Installing Npm

Thumbnail for Razvan LudosanuRazvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Published: 1/31/2024

About Terminus

The short answer

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

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

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

Run in Warp

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 npm using the -v option flag:

 $ npm -v

Run in Warp

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

Easily retrieve this command using Warp’s AI Command Search

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

Thumbnail for

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

Reinstalling Node.js and npm using the terminal

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

Reinstalling Node.js on MacOS with brew

To reinstall Node.js on MacOS with Homebrew, you can use the brew reinstall command:

 $ brew reinstall node@ <version>

Run in Warp

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

For example:

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

Run in Warp

Reinstalling Node.js on Linux with apt

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

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

Run in Warp

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

Run in Warp

Reinstalling Node.js on macOS, Linux, and Windows with nvm

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

 $ nvm deactivate <version>

Run in Warp

As you might otherwise get the following error message:

 nvm: Cannot uninstall currently-active node version

Run in Warp

You can then remove it from your system using the uninstall command:

 $ nvm uninstall <version>

Run in Warp

Then, reinstall it using the install command:

 $ nvm install <version>

Run in Warp

And finally set it as your current version using the use command:

 $ nvm use <version>

Run in Warp

For example, to reinstall Node.js version 20:

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

Run in Warp

Reinstalling Node.js and npm using the Node installer

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.

Thumbnail for

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

Written by

Thumbnail for Razvan LudosanuRazvan Ludosanu

Razvan Ludosanu

Founder, learnbackend.dev

Filed Under

Related Articles

Removing npm Packages

Learn how to remove packages locally, globally, and from the registry using the npm uninstall command.

Npm
Thumbnail for Utsav PoudelUtsav Poudel

Execute Packages With npx And npm

Discover the power of npm's npx tool, a developer's best friend for running packages without global installs.

Npm
Thumbnail for Glory KimGlory Kim

Install Dev Dependencies With npm

Learn how to install and update dev dependencies using the npm install command.

Npm
Thumbnail for Mansi ManhasMansi Manhas

Clear npm Cache

Learn how to clear the npm cache on Linux, macOS, and Windows.

NpmLinux
Thumbnail for Razvan LudosanuRazvan Ludosanu

How To Update NPM

Learn how to update npm to a specific version using the npm, nvm, or npx commands.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

How To Reinstall Packages With Npm

Brief guide to reinstalling npm packages using npm

Npm
Thumbnail for Glory KimGlory Kim

Check Npm Package Version

Check an npm package version within your project

Npm
Thumbnail for Glory KimGlory Kim

Install NPM Packages From GitHub

Check an npm package version within your project

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

List Installed Npm Packages

Learn how to list globally and locally installed packages with npm, including their dependencies.

Npm
Thumbnail for Razvan LudosanuRazvan Ludosanu

Trusted by hundreds of thousands of professional developers

Download Warp to get started

Download for Mac
Thumbnail for null