Installing the npx RPM package on Red Hat Linux

npx is a command-line tool that runs Node.js packages, allowing you to use them without needing local or global installation. Essentially you can use it to run a command from a local or remote npm package.

However, npx was not found on my Red Hat Enterprise Linux release 9.4 installation:

dev@devhost:/home/codeceptjs> which npx

/usr/bin/which: no npx in (/home/dev/.local/bin:/home/dev/bin:/usr/share/Modules/bin:/usr/local/bin:/usr/bin:/usr/local/sbin:/usr/sbin)

After logging in as root, I tried to install the npx RPM, which apparently doesn't exist:

root@devhost:/root> yum install npx

Last metadata expiration check: 3:12:16 ago on Thu 01 Aug 2024 02:59:04 PM GMT.
No match for argument: npx
Error: Unable to find a match: npx

Turns out it's the nodejs RPM that I needed to install:

root@devhost:/root> yum install nodejs

Last metadata expiration check: 3:12:53 ago on Thu 01 Aug 2024 02:59:04 PM GMT.
Dependencies resolved.

Here is the full output:

root@devhost:/root> yum install nodejs

Last metadata expiration check: 3:12:53 ago on Thu 01 Aug 2024 02:59:04 PM GMT.
Dependencies resolved.
=============================================================================================================
 Package                  Architecture   Version                                 Repository             Size
=============================================================================================================
Installing:
 nodejs                   x86_64         1:16.20.2-8.0.1.el9_4                   ol9_appstream         122 k
Installing dependencies:
 nodejs-libs              x86_64         1:16.20.2-8.0.1.el9_4                   ol9_appstream          14 M
Installing weak dependencies:
 nodejs-docs              noarch         1:16.20.2-8.0.1.el9_4                   ol9_appstream         7.8 M
 nodejs-full-i18n         x86_64         1:16.20.2-8.0.1.el9_4                   ol9_appstream         8.2 M
 npm                      x86_64         1:8.19.4-1.16.20.2.8.0.1.el9_4          ol9_appstream         3.4 M

Transaction Summary
=============================================================================================================
Install  5 Packages

Total download size: 34 M
Installed size: 168 M
Is this ok [y/N]: y
Downloading Packages:
(1/5): nodejs-16.20.2-8.0.1.el9_4.x86_64.rpm                                 535 kB/s | 122 kB     00:00
(2/5): nodejs-docs-16.20.2-8.0.1.el9_4.noarch.rpm                             10 MB/s | 7.8 MB     00:00
(3/5): nodejs-full-i18n-16.20.2-8.0.1.el9_4.x86_64.rpm                       8.7 MB/s | 8.2 MB     00:00
(4/5): npm-8.19.4-1.16.20.2.8.0.1.el9_4.x86_64.rpm                            11 MB/s | 3.4 MB     00:00
(5/5): nodejs-libs-16.20.2-8.0.1.el9_4.x86_64.rpm                             13 MB/s |  14 MB     00:01
-------------------------------------------------------------------------------------------------------------
Total                                                                         25 MB/s |  34 MB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Running scriptlet: npm-1:8.19.4-1.16.20.2.8.0.1.el9_4.x86_64                                           1/1
  Preparing        :                                                                                     1/1
  Installing       : nodejs-libs-1:16.20.2-8.0.1.el9_4.x86_64                                            1/5
  Installing       : nodejs-docs-1:16.20.2-8.0.1.el9_4.noarch                                            2/5
  Installing       : nodejs-full-i18n-1:16.20.2-8.0.1.el9_4.x86_64                                       3/5
  Installing       : npm-1:8.19.4-1.16.20.2.8.0.1.el9_4.x86_64                                           4/5
  Installing       : nodejs-1:16.20.2-8.0.1.el9_4.x86_64                                                 5/5
  Running scriptlet: nodejs-1:16.20.2-8.0.1.el9_4.x86_64                                                 5/5
  Verifying        : nodejs-1:16.20.2-8.0.1.el9_4.x86_64                                                 1/5
  Verifying        : nodejs-docs-1:16.20.2-8.0.1.el9_4.noarch                                            2/5
  Verifying        : nodejs-full-i18n-1:16.20.2-8.0.1.el9_4.x86_64                                       3/5
  Verifying        : nodejs-libs-1:16.20.2-8.0.1.el9_4.x86_64                                            4/5
  Verifying        : npm-1:8.19.4-1.16.20.2.8.0.1.el9_4.x86_64                                           5/5

Installed:
  nodejs-1:16.20.2-8.0.1.el9_4.x86_64                     nodejs-docs-1:16.20.2-8.0.1.el9_4.noarch
  nodejs-full-i18n-1:16.20.2-8.0.1.el9_4.x86_64           nodejs-libs-1:16.20.2-8.0.1.el9_4.x86_64
  npm-1:8.19.4-1.16.20.2.8.0.1.el9_4.x86_64

Complete!
root@devhost:/root> npx

Entering npm script environment at location:
/root
Type 'exit' or ^D when finished

sh-5.1# exit
exit
npm notice
npm notice New major version of npm available! 8.19.4 -> 10.8.2
npm notice Changelog: https://github.com/npm/cli/releases/tag/v10.8.2
npm notice Run npm install -g npm@10.8.2 to update!
npm notice

root@devhost:/root>