{"id":22367664,"url":"https://github.com/hugojosefson/install-nodejs-and-pm2","last_synced_at":"2026-04-27T21:32:09.019Z","repository":{"id":66830216,"uuid":"132650617","full_name":"hugojosefson/install-nodejs-and-pm2","owner":"hugojosefson","description":"Script for installing Node.js and pm2 in Linux — for example CentOS, RHEL, Ubuntu.","archived":false,"fork":false,"pushed_at":"2018-05-14T08:02:09.000Z","size":63,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-26T15:55:17.135Z","etag":null,"topics":["centos","nodejs","nvm","pm2","rhel"],"latest_commit_sha":null,"homepage":"","language":"Shell","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hugojosefson.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-05-08T18:43:59.000Z","updated_at":"2024-02-06T02:24:20.000Z","dependencies_parsed_at":"2023-02-21T05:45:24.997Z","dependency_job_id":null,"html_url":"https://github.com/hugojosefson/install-nodejs-and-pm2","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hugojosefson/install-nodejs-and-pm2","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Finstall-nodejs-and-pm2","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Finstall-nodejs-and-pm2/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Finstall-nodejs-and-pm2/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Finstall-nodejs-and-pm2/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hugojosefson","download_url":"https://codeload.github.com/hugojosefson/install-nodejs-and-pm2/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hugojosefson%2Finstall-nodejs-and-pm2/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32356598,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-27T20:07:02.737Z","status":"ssl_error","status_checked_at":"2026-04-27T20:07:00.910Z","response_time":128,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["centos","nodejs","nvm","pm2","rhel"],"created_at":"2024-12-04T18:19:57.147Z","updated_at":"2026-04-27T21:32:09.002Z","avatar_url":"https://github.com/hugojosefson.png","language":"Shell","funding_links":[],"categories":[],"sub_categories":[],"readme":"# install-nodejs-and-pm2\n\nScript for installing Node.js and [pm2](https://pm2.keymetrics.io/), on a Linux server with for example Ubuntu, Debian, CentOS or RHEL.\n\nTested in:\n\n * Ubuntu 18.04 and 14.04\n * RHEL 6.9\n * Debian 9 and 7\n\n## Get the script\n\n```bash\ncurl -o install-nodejs-and-pm2 https://raw.githubusercontent.com/hugojosefson/install-nodejs-and-pm2/master/install-nodejs-and-pm2\nchmod +x install-nodejs-and-pm2\n```\n\n## Run it\n\nRun as `root`:\n\n```bash\n./install-nodejs-and-pm2\n```\n\nIf you want, you can also override environment variables in the script. For example:\n\n```bash\nNODEJS_VERSION=12 NODEJS_HOME_DIR=/srv/nodejs ./install-nodejs-and-pm2\n```\n\n## What it does\n\n * Creates system user `nodejs` if it does not already exist.\n * Installs Node.js 10 via `nvm` for the `nodejs` user.\n * Installs latest versions of `npm`, `yarn`, `pm2`.\n * Sets up `pm2` to run as the `nodejs` user on boot.\n * Sets up `/var/nodejs/apps/` where configuration and apps live.\n     * Adds [`apps/ecosystem.config.js`](example/apps/ecosystem.config.js) unless it already exists.\n     * **Overwrites [`apps/ecosystem.config.js-helper`](example/apps/ecosystem.config.js-helper.js)** with the latest version.\n * Prints a message at the end, to prove Node.js was installed correctly.\n\nYou may re-run `install-nodejs-and-pm2` as `root` as many times as you like. It will then reinstall\nsoftware, replace [`apps/ecosystem.config.js-helper`](example/apps/ecosystem.config.js-helper.js),\nbut not touch any existing [`apps/ecosystem.config.js`](example/apps/ecosystem.config.js).\n\nIf you...\n\n * change any desired version numbers by setting corresponding\nenvironment variables, or\n * if newer versions of the installed packages are available,\n\n...they will be upgraded when you re-run the script as `root`.\n\n## Configure apps\n\nLog in as the `nodejs` user:\n\n```bash\nssh nodejs@prod-server\n\n# or if already logged in as root on the server:\nsu - nodejs\n```\n\nThe `install-nodejs-and-pm2` script sets up a directory `apps`, with an `ecosystem.config.js` file.\n\nThe `ecosystem.config.js` file is default configured to expect apps to have one directory each in\nthe `apps` folder. Add your apps' `pm2` configurations to `ecosystem.config.js`.\n\nA complete directory structure might look like this:\n\n```\n/var/nodejs/apps/\n├── ecosystem.config.js\n├── ecosystem.config.js-helper.js\n├── example-app\n│   └── releases\n│       ├── example-app-1.0.0\n│       │   ├── index.js\n│       │   └── package.json\n│       └── example-app-1.0.1\n│           ├── index.js\n│           └── package.json\n└── second-app\n    └── releases\n        ├── second-app-1.0.0\n        │   ├── index.js\n        │   └── package.json\n        └── second-app-1.1.2\n            ├── index.js\n            └── package.json\n```\n\nUnpack each app version in the app's `releases/` directory, and specify the version to use in the\ncommon `ecosystem.config.js`.\n\n## App structure\n\nEach app needs a `package.json` file with `scripts.start` set to something that starts the app. This\nis how each app is started by default by `pm2` via\n[`apps/ecosystem.config.js-helper`](example/apps/ecosystem.config.js-helper.js):\n\n```bash\nNODE_ENV=production yarn install \u0026\u0026 yarn start\n```\n\n...if there is a `yarn.lock` file. Otherwise,\n\n```bash\nNODE_ENV=production npm install \u0026\u0026 npm start\n```\n\n### Example apps\n\nLook at the [`example/apps/`](./example/apps) directory for how to structure your applications, and\nconfigure them. To download them directly, and overwrite your current config, you may do this as the\n`nodejs` user:\n\n```bash\ncurl -sS -L https://api.github.com/repos/hugojosefson/install-nodejs-and-pm2/tarball/master \\\n  | tar xzv --strip-components=2 --wildcards '*/example' -C ~\n```\n\nThen start all apps:\n\n```bash\npm2 startOrReload ~/apps/ecosystem.config.js\npm2 save\n```\n\n## Run and save\n\nTo start the apps defined in `apps/ecosystem.config.js`, log in as the `nodejs` user (`su - nodejs`)\nand use these commands:\n\n```bash\n# Check current status\npm2 status\npm2 dash\n\n# Start or reload defined services\npm2 startOrReload ~/apps/ecosystem.config.js\n```\n\nNote that `pm2 startOrReload` does not stop any apps you remove from `apps/ecosystem.config.js`.\nYou must therefore `pm2 stop` and/or `pm2 delete` them yourself.\n\n### Save\n\nFor the apps to start when `pm2` starts, you must save the current process list:\n\n```bash\n# Save current process list for next boot\npm2 save\n```\nRemember to `pm2 save` whenever you start or stop something that should stay started or stopped!\n\n## Deploy new version of app\n\nOn your CI server or development machine, in the app's source directory, create the release artifact\nwith `npm pack`. Then unpack it on the server, into the app's versioned directory in the `releases/`\ndirectory:\n\n```bash\ncd example-app\n\n# create example-app-1.0.1.tgz locally\nnpm pack\n\n# unpack onto server, from your local machine via ssh\nenv \\\n  APP_NAME=$(node -p \"require('./package.json').name\") \\\n  APP_VERSION=$(node -p \"require('./package.json').version\") \\\n  bash -c '\\\n    cat ${APP_NAME}-${APP_VERSION}.tgz | \\\n    ssh nodejs@prod-server \\\n      \"mkdir -p apps/${APP_NAME}/releases/${APP_NAME}-${APP_VERSION} \u0026\u0026 \\\n      tar xz -C apps/${APP_NAME}/releases/${APP_NAME}-${APP_VERSION} --strip-components=1\" \\\n  '\n```\n\n### Switch to new version\n\nOn the server, edit the `ecosystem.config.js` file to specify which version to use.\n\nThen tell `pm2` to reload the app:\n\n```bash\npm2 delete example-app\npm2 start ~/apps/ecosystem.config.js --only example-app\npm2 save\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugojosefson%2Finstall-nodejs-and-pm2","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhugojosefson%2Finstall-nodejs-and-pm2","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhugojosefson%2Finstall-nodejs-and-pm2/lists"}