NodeJS in AL2023 - Amazon Linux 2023
Services or capabilities described in Amazon Web Services documentation might vary by Region. To see the differences applicable to the China Regions, see Getting Started with Amazon Web Services in China (PDF).

NodeJS in AL2023

NodeJS in AL2023 is represented by two major versions, 18 and 20. They are namespaced and can be installed simultaneously on the same system. NodeJS is distributed as several sub-packages that include the node, the npm tool of a given version that comes bundled with each official NodeJS release, documentation, libraries, and so on. For example, with NodeJS 18, node and npm are provided by the nodejs 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:
  1. Check what's configured in alternatives

    alternatives --list
  2. Check node's current configuration

    alternatives --display node
  3. Interactively change the NodeJS version

    alternatives --config node
  4. Switch to manual mode and select a specific version

    alternatives --set node /usr/bin/node-20
  5. Switch back to auto version selection mode

    alternatives --auto node