What exact command is to install pm2 on offline RHEL
Asked Answered
O

5

13

First of all it's not a duplicate question of below:-

How to install npm -g on offline server

https://stackoverflow.com/questions/40976100/how-to-installl-pm2-on-offline-server

I install npmbox (https://github.com/arei/npmbox) on my offline REHL server but I'm still do not know how to install pm2 or any other package using that.

Please advise.

Occlusion answered 15/12, 2016 at 4:41 Comment(2)
@downvoter: kindly leave a solution if you know?Occlusion
@Soren: How to include all dependencies in the pack?Occlusion
F
32

You use npm install & pack

First on a machine that is online you install

$ npm install pm2

Then you pack it up

$ npm pack pm2

That gives you a tar file -- you copy that tar file to your offline machine and install, like

$ npm install pm2-2.2.1.tgz 

The above however only create a tarball for the specific module expluding dependencies, and you may still have dependencies that you need to resolve. While you could simply walk through and pack every dependency manually, there is a modules that will automated that for you

$ npm install -g npm-bundle

Then you can do

$ npm-bundle pm2

for the individual packages, or if you have a package.json for your project

$ npm-bundle

to pack everything in one big tarball

Flodden answered 15/12, 2016 at 6:17 Comment(5)
thanks a lot. npm install pm2-2.2.1.tgz -g worked for me.Occlusion
how to include all dependencies in the package?Occlusion
fabianlee.org/2016/10/02/… I tried this but it is also not working. it's looking for registry.npmjs.org/pm2/-/pm2-2.2.2.tgzOcclusion
npm-bundle works perfectly for me .. did you try to install pm2 locally (without -g) before bundle ... added my steps aboveFlodden
and npm ERR! enoent This is most likely not a problem with npm itself npm ERR! enoent and is related to npm not being able to find a file. npm ERR! enoentCuprite
B
1

An alternate way to install pm2 offline is:

Create the tar file with the above steps mentioned by @soren.

in my case Installation hung while executing "npm install pm2.tar.gz".

npm install pm2.tar.gz

[..................] - fetchMetadata: sill resolveWithNewModule [email protected] checking installable status
[..................] - fetchMetadata: sill resolveWithNewModule [email protected] checking installable status

to get this resolved I have added the npm registry but that did not work.

npm config set registry="http://registry.npmjs.org"

Server's are into the DMZ or in a private subnet that's it's was not working.

Solution:-

Get the install path of the node_module directory

#npm config get prefix

Extract the tar file & Copy the pm2 directory to node_module

 #tar -zxvf pm2.tar.gz
 #cp pm2 /usr/local/lib/node_modules/npm/node_modules/ -r

cd into the /usr/bin & Crete the simlink for pm2

 # cd /usr/bin
 #ln -s /usr/local/lib/node_modules/npm/node_modules/pm2/bin/pm2 pm2

check pm2 command output & its output.

    # pm2
    usage: pm2 [options] <command>

    pm2 -h, --help             all available commands and options
    pm2 examples               display pm2 usage examples
    pm2 <command> -h           help on a specific command

    Access pm2 files in ~/.pm2
Beverlee answered 8/2, 2022 at 20:19 Comment(0)
W
1
  • On a linux machine with internet access:
    • cd /home/myName/Downloads
    • rm -r * (clear contents of folder)
    • npm i -g npm-bundle (globally install this package if you do not have it already)
    • npm i pm2 (will create node_modules, package.json, and package-lock.json)
    • npm-bundle pm2 (this will create a .tgz file)
  • Move the .tgz file to the offline machine, untar it (tar -xvzf pm2-#.#.#.tgz, rename its folder to pm2 (mv package pm2)
  • npm root -g (will show you where to put files for global packages)
  • cp -r pm2 /usr/lib/node_modules/
  • ln -s /usr/lib/node_modules/pm2/bin/pm2 /usr/local/bin/pm2 (create symlink for the pm2 command)
  • pm2 ls (should work now)
Wrench answered 12/1, 2023 at 15:0 Comment(0)
B
0

@Soren's answer work for me. to install it globally you need to pass -g argument to it.

Tested it on OpenSUSE 15 Enterprise.

for example:

ip-192-168-2-36:~ # npm install pm2-5.1.2.tgz -g
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.

added 181 packages, and audited 182 packages in 5s

12 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities


ip-192-168-2-36:~ # pm2 -v
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
5.1.2

Without -g argument pm2 command will not work.

ip-192-168-2-36:~ # pm2
-bash: /usr/local/bin/pm2: No such file or directory
Beverlee answered 1/2, 2022 at 19:53 Comment(0)
C
0

An alternate way,

just write a node service on your machine pm2 no longer needed to run you application.

Step -1

Run the command to find the node path which node --> /opt/rh/rh-nodejs14/root/usr/bin/node

Step -2

cd /etc/systemd/system

Step -3

Write a service of node as follows :-

vi node.service

[Unit]
Description=Node Service for Dashboard Application
After=syslog.target

[Service]
User=root
ExecStart=/opt/rh/rh-nodejs14/root/usr/bin/node 
/home/node/deployed/backend/server.js SuccessExitStatus=143

[Install]
WantedBy=multi-user.target

:wq!

--> save it

Step -4

Start the node service

systemctl start node.service

Step -5

systemctl status node.service

Step -6

Check your application your node is running without pm2

Carpathoukraine answered 19/10, 2022 at 6:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.