Updating Ghost on a Low Memory Server

So you picked up a low cost server and decided to put Ghost on it. You heard Ghost was lightweight and fast so you didn't think you needed much hardware. Everything was going great! That is, until you decided to update Ghost to a new version.

npm Gets Killed While Running an Install

If you're running Ghost on a server with very little memory, you may have seen the foreboding message Killed when you attempted to run npm install --production.

$ npm install --production
extract:lodash → gunzTarP ▀ ╢████████████████████████████████████████████████████████████░░░░░░░░░░░░░░╟  
Killed  

This likely means that your server ran out of memory and the kernel killed npm. Ghost may not need much RAM to run, but sometimes, having too little RAM can cause npm to fail while running an install1. Your server will need more memory in order for npm install to complete successfully.

You have two choices:

  • Add more RAM to your server, or
  • Add some swap space

Once more memory is available to npm, it should stop being Killed while running. However, there's one more thing you need to complete before rerunning the install.

Cleaning Up After a Killed npm Installation

If you attempt to run an npm install after it has failed with Killed, you will most likely see something like the following.

$ npm install --production

> ghost@0.11.1 preinstall /var/www/ghost
> node core/server/utils/npm/preinstall.js

npm WARN unmet dependency /var/www/ghost/node_modules/ghost-gql requires lodash@'3.10.1' but will load  
npm WARN unmet dependency /var/www/ghost/node_modules/lodash,  
npm WARN unmet dependency which is version 4.16.0  
npm WARN unmet dependency /var/www/ghost/node_modules/gscan requires chalk@'1.1.1' but will load  
npm WARN unmet dependency /var/www/ghost/node_modules/chalk,  
npm WARN unmet dependency which is version 1.1.3  
npm WARN unmet dependency /var/www/ghost/node_modules/gscan requires fs-extra@'0.26.2' but will load  
...

These "unmet dependency" warnings happen because npm was interrupted and its dependency installation is in an inconsistent state. To clean this up, and fix the warnings, do the following2:

  1. Remove the node_modules directory from your ghost install directory: rm -r node_modules
  2. Run npm cache clean

With more memory available to npm and the bad failed installation cleaned up after, npm install --production should now successfully complete.