Jitendra Pancholi
Jitendra Pancholi

Reputation: 7562

What exact command is to install pm2 on offline RHEL

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

How to install npm -g 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.

Upvotes: 13

Views: 22648

Answers (5)

mahendra rathod
mahendra rathod

Reputation: 1638

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

Upvotes: 1

xinthose
xinthose

Reputation: 3848

  • 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)

Upvotes: 1

Aaquib Jawed
Aaquib Jawed

Reputation: 1

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

Upvotes: 0

mahendra rathod
mahendra rathod

Reputation: 1638

@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

Upvotes: 0

Soren
Soren

Reputation: 14708

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

Upvotes: 32

Related Questions