How to fix npm install command not working (2024)

How to fix npm install command not working (1)

The npm install command is used for installing JavaScript packages on your local computer.

When developing web projects, you may see issues that cause the npm install command to fail.

You need to see the error message generated in the terminal for clues to resolve the error.

Some of the most common issues for npm install not working are as follows:

  • npm command not found
  • No package.json file describing the dependencies
  • Integrity check failed error
  • For Windows: Python not found

Let’s see how you can resolve these errors next.

The npm command not found error

To run the npm install command, you need to have npm installed on your computer

$ npm installsh: command not found: npm

The error above happens when npm can’t be found under the PATH environment variable.

First, you need to make sure that npm is installed on your computer.

npm is bundled with Node.js server, which you can download from the nodejs.org website.

Once you downloaded and installed Node.js, open the terminal and run the npm -v command.

You should see the version of npm installed on your computer as follows:

Once you see the npm version, you should be able to run the npm install command again.

For more details, visit the fixing npm command not found error article I’ve written previously.

ENOENT: No package.json file

The npm install command looks for a package.json file in order to find the packages it needs to install.

You need to make sure you have a package.json file right in the current directory where you run the command.

You can run the ls -1 command as follows:

$ ls -1index.jspackage-lock.jsonpackage.json

Once you see there’s a package.json file in the output as shown above, then you can run the npm install command.

For this reason, you should always run the npm install command from the root directory of your project.

By the way, npm install will install packages already listed under the dependencies object of your package.json file.

Suppose you have a package.json file as shown below:

{ "name": "n-app", "version": "1.0.0", "description": "A Node application", "dependencies": { "jest": "^28.1.1", "typescript": "^4.5.5", "webpack": "^2.7.0" }}

Then npm install will install jest, typescript, and webpack to the generated node_modules/ folder.

If you need to install a new package, then you need to specify the name like these examples:

# 👇 install react packagenpm install react# 👇 install react, react-dom, and axios packagesnpm install react react-dom axios

You can install one or many packages with the npm install command.

Integrity check failed error

When you have a package-lock.json file in your project, then npm will check the integrity of the package you downloaded with the one specified in the lock file.

When the checksum of the package is different, then npm will stop the installation and throw the integrity check failed error.

The following is an example of the error:

npm ERR! code EINTEGRITYnpm ERR! Verification failed while extracting @my-package@^1.2.0:npm ERR! Verification failed while extracting @my-package@^1.2.0:npm ERR! Integrity check failed:npm ERR! Wanted: sha512-lQ...HA== npm ERR! Found: sha512-Mj...vg==

When this happens, you can fix the issue by verifying the cache:

npm cache verify

When the command is finished, run npm install again.

If you still see the error, then delete your lock file and clean the npm cache.

Run the following commands from your project’s root directory:

# 👇 remove the lock filerm package-lock.json# 👇 remove the node_modules folderrm -rf node_modules# 👇 Clear the npm cachenpm cache clean --force# 👇 run npm install againnpm install

That should fix the issue with the integrity check.

For Windows only: Python not found

When running npm install on Windows, you may see an error that says Can’t find Python executable as shown below:

> node-gyp rebuild/n-app>node "\..\node_modules\node-gyp\bin\node-gyp.js" rebuildnpm http 304 https://registry.npmjs.org/bcryptgyp ERR! configure errorgyp ERR! stack Error: Can't find Python executable "python",you can set the PYTHON env variable.

The node-gyp module is a Node.js tool for compiling native modules written in C and C++. It requires Python to run properly.

Instead of installing Python by yourself, you can install the Windows Build Tools which has Python included.

This is because Windows also requires Visual Studio build tools to make node-gyp run successfully.

If you install only Python, then you may find that you need the build tools later.

Please note that the latest version of Node.js for Windows installer already includes the build tools by default.

But if you can’t update your Node.js version yet, then installing the build tools manually should help you fix this error.

Conclusion

The npm install command may fail to work because of many reasons.

When the command doesn’t work, you need to check the output first and see what specific error you have.

Try a Google search to fix the issue. When you don’t see a solution, try posting a new question at Stack Overflow mentioning the things you have tried to fix the issue.

Good luck resolving the issue! 👍

How to fix npm install command not working (2024)

FAQs

How to fix npm install command not working? ›

Common npm install errors and their solutions. This error occurs when npm does not have the necessary permissions to install packages or modify certain files or directories. To resolve this issue, you can try running the command with administrative privileges or fix the permissions for the specific directory.

Why is the npm install command not working? ›

Common npm install errors and their solutions. This error occurs when npm does not have the necessary permissions to install packages or modify certain files or directories. To resolve this issue, you can try running the command with administrative privileges or fix the permissions for the specific directory.

How to make npm install work? ›

To install a package, npm uses the following algorithm:
  1. load the existing node_modules tree from disk.
  2. clone the tree.
  3. fetch the package.json and assorted metadata and add it to the clone.
  4. walk the clone and add any missing dependencies.
  5. dependencies will be added as close to the top as is possible.
Sep 22, 2020

How do I force npm to install? ›

To force an NPM package to install, you can use the --force flag. This will tell npm to ignore any errors or conflicts that it encounters during installation. You should use the --force flag with caution, as it can lead to unexpected results.

Why my npm start command is not working? ›

Make sure that all items have read/write permission, otherwise attempting to run “npm start” will throw an error. It is also possible that you may be in the wrong directory when running “npm start”. Make sure that you are in the root folder of your project when you run this command.

How to do npm install again? ›

Reinstall a single npm package
  1. Uninstall the package: npm uninstall <package-name>
  2. Install the package: npm install <package-name>
May 20, 2024

How do I fix a broken npm? ›

Broken npm installation

If your npm is broken: On Mac or Linux, reinstall npm. Windows: If you're on Windows and you have a broken installation, the easiest thing to do is to reinstall node from the official installer (see this note about installing the latest stable version).

What is the command to install npm? ›

If NPM is not installed or is outdated, you can install it separately or update it by running the command npm install -g npm in the terminal. This will update NPM to the latest version. To verify the NPM installation, type npm -v in the terminal. It should display the latest version of NPM.

How to install npm completely? ›

How to Install Node.js and NPM on Windows?
  1. Step 1: Download the Installer. Download the Windows Installer from NodeJs official website. ...
  2. Step 2: Install Node.js and NPM. After choosing the path, double-click to install .msi binary files to initiate the installation process. ...
  3. Step 3: Check Node.js and NPM Version.
Feb 14, 2024

How do I start npm installation? ›

The Basics: Getting started with npm
  1. Using npm init to initialize a project.
  2. Using npm init --yes to instantly initialize a project.
  3. Install modules with npm install.
  4. Install modules and save them to your package.json as a dependency.
  5. Install modules and save them to your package.json as a developer dependency.
Feb 10, 2022

How to install npm on glitch? ›

Now, here's how to add an NPM package to your Glitch project:
  1. Open the project in the editor.
  2. In the file view on the left, click on package. ...
  3. Click the + ADD PACKAGE button which can be found at the top of the package. ...
  4. Use the search box to find the NPM package that you would like to add to your project.
May 31, 2023

How to check npm installed or not in cmd? ›

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4. 28. Create a test file and run it.

How to enable npm command? ›

npm Install Globally

Install a package on your system globally. Use the following command to install a package on your system globally: npm install <package_name> --global.

How to check if npm is installed or not? ›

To see if NPM is installed, type npm -v in Terminal. This should print the version number so you'll see something like this 1.4.

Top Articles
The Three Pillars of Happiness and Motivation: Hedonia, Eudaimoni
What Happens If You Don’t Eat Enough? 8 Ways Undereating Affects You
Missed Connections Inland Empire
Kokichi's Day At The Zoo
Koordinaten w43/b14 mit Umrechner in alle Koordinatensysteme
BULLETIN OF ANIMAL HEALTH AND PRODUCTION IN AFRICA
Naturalization Ceremonies Can I Pick Up Citizenship Certificate Before Ceremony
30% OFF Jellycat Promo Code - September 2024 (*NEW*)
Nation Hearing Near Me
Craigslist In Fredericksburg
Visustella Battle Core
Swimgs Yung Wong Travels Sophie Koch Hits 3 Tabs Winnie The Pooh Halloween Bob The Builder Christmas Springs Cow Dog Pig Hollywood Studios Beach House Flying Fun Hot Air Balloons, Riding Lessons And Bikes Pack Both Up Away The Alpha Baa Baa Twinkle
Acbl Homeport
Ncaaf Reference
Helloid Worthington Login
2135 Royalton Road Columbia Station Oh 44028
Yesteryear Autos Slang
How to watch free movies online
Truck Toppers For Sale Craigslist
Images of CGC-graded Comic Books Now Available Using the CGC Certification Verification Tool
Pizza Hut In Dinuba
Urban Airship Expands its Mobile Platform to Transform Customer Communications
White Pages Corpus Christi
O'Reilly Auto Parts - Mathis, TX - Nextdoor
Craigslist Pearl Ms
Rs3 Eldritch Crossbow
Buying Cars from Craigslist: Tips for a Safe and Smart Purchase
Gotcha Rva 2022
Truck from Finland, used truck for sale from Finland
His Only Son Showtimes Near Marquee Cinemas - Wakefield 12
Marlene2295
James Ingram | Biography, Songs, Hits, & Cause of Death
Metra Union Pacific West Schedule
Truis Bank Near Me
Why Holly Gibney Is One of TV's Best Protagonists
Craigslist Lakeside Az
Trivago Myrtle Beach Hotels
Craigslist Putnam Valley Ny
Froedtert Billing Phone Number
Gravel Racing
Sas Majors
Jane Powell, MGM musical star of 'Seven Brides for Seven Brothers,' 'Royal Wedding,' dead at 92
Dlnet Deltanet
Plumfund Reviews
Suppress Spell Damage Poe
Sitka Alaska Craigslist
Westport gun shops close after confusion over governor's 'essential' business list
Runescape Death Guard
How to Do a Photoshoot in BitLife - Playbite
Texas Lottery Daily 4 Winning Numbers
Latest Posts
Article information

Author: Eusebia Nader

Last Updated:

Views: 6422

Rating: 5 / 5 (80 voted)

Reviews: 87% of readers found this page helpful

Author information

Name: Eusebia Nader

Birthday: 1994-11-11

Address: Apt. 721 977 Ebert Meadows, Jereville, GA 73618-6603

Phone: +2316203969400

Job: International Farming Consultant

Hobby: Reading, Photography, Shooting, Singing, Magic, Kayaking, Mushroom hunting

Introduction: My name is Eusebia Nader, I am a encouraging, brainy, lively, nice, famous, healthy, clever person who loves writing and wants to share my knowledge and understanding with you.