NodeJSnodejs
and nodejs-npm
packages,
respectively. However, with NodeJS 20, node and npm are available in
the nodejs20
and nodejs20-npm
packages.
The default version is NodeJS 18, which means that the package with this version provides executables
such as /usr/bin/node
and /usr/bin/npm
, and also has the highest priority for auto-resolving
the current version in the alternatives system in case of a multi-version installation.
To allow simultaneous installation of different major versions of NodeJS, packages are shipped with executables, modules,
and other files namespaced to avoid overlapping and file system conflicts. For example, the node executable
is named /usr/bin/node-{MAJOR_VERSION}
and the npm executable is named
/usr/bin/npm-{MAJOR_VERSION}
. However, there can only be one /usr/bin/node
and one
/usr/bin/npm
on the running system. These executables are virtual names (symlinks) and point to the actual
executables of the currently active version of NodeJS.
To better support multiple versions of NodeJS and simplify the way of switching between installed versions
of NodeJS, Amazon Linux is gradually migrating NodeJS packages to use
the alternatives system. It's supported by the nodejs
package (NodeJS 18).
We'll update nodejs20
in a future update.
Switching to alternatives allows you to use a single command to select which NodeJS
version's configuration files, binaries (such as node
and npm
), and globally
installed modules are used. By default, alternatives is configured to be in auto mode, which uses
priorities to select the currently active version of NodeJS. However, you can switch between installed
versions at any time by running alternatives --config node
.
Some useful alternatives commands:
-
Check what's configured in alternatives
alternatives --list
-
Check node's current configuration
alternatives --display node
-
Interactively change the NodeJS version
alternatives --config node
-
Switch to manual mode and select a specific version
alternatives --set node /usr/bin/node-20
-
Switch back to auto version selection mode
alternatives --auto node