Knowledge Base
MilesWeb / Web Hosting FAQ

Prevent NPM Install from Being Killed by Checking the Swap File

Approx. read time : 2 min

Sometimes you are unable to perform npm install. You might face issues like command getting freezed, and after few minutes, npm displays ‘Killed’ message and breaks.

You can try several ways to resolve this issue as below:

  1. Install npm with every single dependency in package.json (about 20 dependencies, mostly grunt related).
  2. In package.json, remove ^ and ~ character to ensure npm only fetches correct version of dependencies (don’t compare and get latest version).
  3. Note that bower installation can go normal with about ~10 dependencies of AngularJS.

Try to npm rm -rf node_modules && npm cache clean, then npm install again does not work too, npm still be killed.

Steps to Prevent npm Install From Being Killed

This issue occurs mainly due to dirty workspace of node modules and for that you just need to clean the cache. But still for many the problem still persists. Many face the issue that the command runs on the local machine without any problem and the remote machine comprises of the same environment too. The difference is only about the machine configuration.

Check the example of configuration:

  • Local Machine Configuration: Dual core 1.3Ghz, with 4GB RAM and 4GB swap file, 256GB SSD.
  • Remote Machine Configuration: Single core CPU, with 512MB RAM and 20GB SSD
  • Even with this configuration you get an error npm install was Killed, after laggy (|) rotation

So, you can see that the biggest difference is memory. Here the remote machine (which is running Apache, nginx and MySQL) doesn’t have enough memory for npm to build something during the installation of dependencies – many dependencies need to be rebuilt by make.

For this check your swap file in remote machine using the below command:

You will get the result as no swap file are available:

Then create a 1GB swap file (on SSD system, swap speed can be much faster)

Prepare the swap file using the below command:

And activate it by executing this command:

Continue swap file after reboot by copying configuration on to the below path:

To make swap file to be a buffer for securing the application crashes, use the below command:

Lastly, set correct permission on it:

Then, clean cache and rebuild with npm:

That’s it! Install script is successfully completed. It takes just about 5 minutes for npm and make to build and install required dependencies. Then just npm start and your dashboard is online!


If you already succeed in something and fail with the same tasks, make sure to check what is different along with the software and hardware to detect the reason of failure.

Pallavi Godse
Pallavi is a Digital Marketing Executive at MilesWeb and has an experience of over 4 years in content development. She is interested in writing engaging content on business, technology, web hosting and other topics related to information technology.