others-how to install nodejs/npm on a linux server without internet connection(offline)?

1. Purpose

In this post, I would introduce how to install nodejs(or node.js) and npm(nodejs package manager) on a linux server that does not have internet connection.



2. Install node(nodejs or node.js)

Download node

Navigate to nodejs official website to download the node.js install package. Choose the source code package.



3. Configure and Compile(Make) node.js

Now we can extract files from the package:

tar -zxvf node-v16.15.0-linux-x64.tar.xz


Then configure it:

[[email protected] node-v16.15.0]# ./configure
Node.js configure: Found Python 3.8.13...
Traceback (most recent call last):
  File "./configure", line 27, in <module>
    import configure
  File "/opt/node-v16.15.0/configure.py", line 14, in <module>
    import bz2
  File "/usr/local/python3/lib/python3.8/bz2.py", line 19, in <module>
    from _bz2 import BZ2Compressor, BZ2Decompressor
ModuleNotFoundError: No module named '_bz2'
[[email protected] node-v16.15.0]#


We got error ModuleNotFoundError: No module named '_bz2',so try to install the _bz2 module:

goto here to download libbz2-dev

[[email protected] ~]# rpm -ivh bzip2-devel-1.0.6-13.el7.x86_64.rpm
preparing...                          ################################# [100%]
Installing...
   1:bzip2-devel-1.0.6-13.el7         ################################# [100%]

rebuild python3 again:

./configure --prefix=/usr/local/python3  --enable-optimizations
make && make install
make altinstall

Now try to configure node again:

[[email protected] node-v16.15.0]# ./configure
Node.js configure: Found Python 3.8.13...
WARNING: C++ compiler (CXX=g++, 4.8.5) too old, need g++ 8.3.0 or clang++ 8.0.0
WARNING: warnings were emitted in the configure phase
INFO: configure completed successfully
[[email protected] node-v16.15.0]# make && make install


At last, we should create symbolic link to make the binary executable from command line:

[[email protected] node-v16.15.0-linux-x64]# ln -s /opt/node-v16.15.0-linux-x64/bin/node /usr/local/bin/node
[[email protected] node-v16.15.0-linux-x64]# ln -s /opt/node-v16.15.0-linux-x64/bin/npm /usr/local/bin/npm

Now we have installed the nodejs/npm offline, we can test it as follows: check installation:

[[email protected] node-v16.15.0-linux-x64]# node --version
v16.15.0
[ro[email protected] node-v16.15.0-linux-x64]# npm --version
8.5.5

4. Summary

In this post, I demonstrated how to install nodejs(or node.js) and npm(nodejs package manager) on a linux server that does not have internet connection. That’s it, thanks for your reading.