[New]Node installation and configuration on linux-Ubuntu-22.04-LTS

  • A log for simple Node installation on the new server.
  • with yarn and pm2

Step 1

  • download the binary of the latest LTS version for the server from nodejs.org

I chose this version - 22.11.0(LTS)

Step 2

  • secondly we unzip the .tar.xz and mv it to /usr/local/ or somewhere else.

Now execute the following command.

1
2
tar -xvf ./node-v22.11.0-linux-x64.tar.xz
mv ./node-v22.11.0-linux-x64 /usr/local/
  • Important note: use you own .tar.xz file path and be more careful.

Step 3

  • then we configure the PATH and also the npm registry.

To confirue the path, because I use root (which is not recommend and very dangerous), so I just simply edit the /etc/profile, and you may edit the ~/.bashrc similarly.

1
nano /etc/profile

And then we add the following lines to the bottom of the file

1
2
3
export NODE_HOME=/usr/local/node-v22.11.0-linux-x64
export NODE_HOME
export PATH=$PATH:$NODE_HOME:$NODE_HOME/bin
  • Note: you may use vi or vim instead. And the first line of these is the path to you node location

Now execute source command to update PATH

1
source /etc/profile

Now let's check you PATH configuration, execute the following command, and you are expected to see the correspond output.

1
2
node -v
v22.11.0
1
2
npm -v
10.9.0

Note: if you use different version of Node, the output will be different but you can check it on the nodejs.org

Now let's configure the registry is you are in China

1
npm config set registry https://registry.npmmirror.com

Step 4

  • eventually we install yarn and pm2

Execute the following command

1
2
3
npm install -g yarn
yarn config set registry https://registry.npmmirror.com
yarn global add pm2

To check the installation of pm2, use the command pm2 -v, and you are supposed to see something like that

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
root@hostname:~# pm2 -v

-------------

__/\\\\\\\\\\\\\____/\\\\____________/\\\\____/\\\\\\\\\_____
_\/\\\/////////\\\_\/\\\\\\________/\\\\\\__/\\\///////\\\___
_\/\\\_______\/\\\_\/\\\//\\\____/\\\//\\\_\///______\//\\\__
_\/\\\\\\\\\\\\\/__\/\\\\///\\\/\\\/_\/\\\___________/\\\/___
_\/\\\/////////____\/\\\__\///\\\/___\/\\\________/\\\//_____
_\/\\\_____________\/\\\____\///_____\/\\\_____/\\\//________
_\/\\\_____________\/\\\_____________\/\\\___/\\\/___________
_\/\\\_____________\/\\\_____________\/\\\__/\\\\\\\\\\\\\\\_
_\///______________\///______________\///__\///////////////__


Runtime Edition

PM2 is a Production Process Manager for Node.js applications
with a built-in Load Balancer.

Start and Daemonize any application:
$ pm2 start app.js

Load Balance 4 instances of api.js:
$ pm2 start api.js -i 4

Monitor in production:
$ pm2 monitor

Make pm2 auto-boot at server restart:
$ pm2 startup

To go further checkout:
http://pm2.io/


-------------

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
5.4.2