This error:

-bash: /usr/bin/nodejs: cannot execute binary file: Exec format error

indicates that the nodejs executable installed in the linux distribution is not supported.

In my case I have had this error when installing a 18.15.0 LTS version of nodejs on Ubuntu 22.04.

To solve it, you must uninstall the version of node that gives the error with the following command in the case of Ubuntu:

sudo apt remove nodejs -y
sudo apt purge nodejs -y

And once we have uninstalled nodejs we proceed to run a compatible version, which in the case of Ubuntu 22.04 is a version 19 of node running:

curl -fsSL | sudo -E bash -

This command at the end tells us that we must execute to complete the installation of nodejs 19:

## Installing the NodeSource Node.js 19.x repo...

## Populating apt-get cache...

+ apt-get update
Get:1 jammy-security InRelease [110 kB]
Hit:2 jammy InRelease
Hit:3 jammy InRelease
Get:4 jammy-updates InRelease [119 kB]
Get:5 jammy-backports InRelease [107 kB]
Get:6 jammy-security/main amd64 Packages [693 kB]
Get:7 jammy-security/main Translation-en [143 kB]
Get:8 jammy-security/main amd64 c-n-f Metadata [9016 B]
Get:9 jammy-security/restricted amd64 Packages [645 kB]
Get:10 jammy-security/restricted Translation-en [100 kB]
Get:11 jammy-security/restricted amd64 c-n-f Metadata [588 B]
Get:12 jammy-security/universe amd64 Packages [714 kB]
Get:13 jammy-security/universe Translation-en [118 kB]
Get:14 jammy-security/universe amd64 c-n-f Metadata [14.1 kB]
Get:15 jammy-security/multiverse amd64 Packages [19.4 kB]
Get:16 jammy-security/multiverse amd64 c-n-f Metadata [228 B]
Get:17 jammy-updates/main amd64 Packages [949 kB]
Get:18 jammy-updates/main Translation-en [205 kB]
Get:19 jammy-updates/main amd64 c-n-f Metadata [13.8 kB]
Get:20 jammy-updates/universe amd64 Packages [895 kB]
Get:21 jammy-updates/universe Translation-en [179 kB]
Get:22 jammy-updates/universe amd64 c-n-f Metadata [18.4 kB]
Get:23 jammy-backports/universe amd64 Packages [19.5 kB]
Get:24 jammy-backports/universe Translation-en [14.0 kB]
Get:25 jammy-backports/universe amd64 c-n-f Metadata [392 B]
Fetched 5086 kB in 3s (1509 kB/s)
Reading package lists... Done

## Confirming "jammy" is supported...

+ curl -sLf -o /dev/null ''

## Adding the NodeSource signing key to your keyring...

+ curl -s | gpg --dearmor | tee /usr/share/keyrings/nodesource.gpg >/dev/null

## Creating apt sources list file for the NodeSource Node.js 19.x repo...

+ echo 'deb [signed-by=/usr/share/keyrings/nodesource.gpg] jammy main' > /etc/apt/sources.list.d/nodesource.list
+ echo 'deb-src [signed-by=/usr/share/keyrings/nodesource.gpg] jammy main' >> /etc/apt/sources.list.d/nodesource.list

## Running `apt-get update` for you...

+ apt-get update
Get:1 jammy InRelease [4563 B]
Hit:2 jammy InRelease
Hit:3 jammy-updates InRelease
Hit:4 jammy-backports InRelease
Hit:5 jammy InRelease
Hit:6 jammy-security InRelease
Get:7 jammy/main amd64 Packages [778 B]
Fetched 5341 B in 3s (1782 B/s)
Reading package lists... Done

## Run `sudo apt-get install -y nodejs` to install Node.js 19.x and npm
## You may also need development tools to build native addons:
     sudo apt-get install gcc g++ make
## To install the Yarn package manager, run:
     curl -sL | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn

We do what they say by running:

sudo apt-get install -y nodejs

And as it informs us, we install possibly necessary packages:

sudo apt-get install gcc g++ make

And we install Yarn by running:

curl -sL | gpg --dearmor | sudo tee /usr/share/keyrings/yarnkey.gpg >/dev/null
     echo "deb [signed-by=/usr/share/keyrings/yarnkey.gpg] stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
     sudo apt-get update && sudo apt-get install yarn

Once we finish this installation we verify by executing:

node -v

which returns that I have a version 19.8.1, and problem solved.