Node.js in AL2023
Node.js
This is achieved using the capabilities of the alternatives tool. It is important to remember that the default executable names are virtual and can change at any time when pointing to a different installed Node.js version. This flexibility enables software that uses node in the shebang to select the desired version when invoked. However, when a specific version of Node.js is required, persistence of the version can be achieved by calling the namespaced executables (e.g., node-20 or node-22), which will always use the specified version of the runtime. Additionally, the namespaced executables of the npm tool, such as npm-20 or npm-22, are always associated with the corresponding Node.js version, regardless of the currently active runtime.
Node.js is distributed as several namespaced packages. These packages provide node, a compatible with it version
of npm tool, documentation, libraries, and more. The only exception is Node.js 18, which historically
is not namespaced and provides node and npm in the nodejs
and nodejs-npm
packages, respectively.
However, the subsequent versions of Node.js are namespaced and begin with "nodejs{MAJOR_VERSION}
".
For example, node and npm of the Node.js 20 are provided by the nodejs20
and nodejs20-npm
packages, respectively.
The alternatives tool provides a single command for switching between Node.js versions. By default, alternatives is configured to be in auto mode, which uses priorities to determine the currently active Node.js version. However, you can activate any installed version at any time. Currently, all supported versions of Node.js have equal priority, meaning the first installed version will be activated automatically.
Some useful examples of using alternatives
-
Check what alternatives is configured for
alternatives --list
-
Check node's current configuration
alternatives --display node
-
Interactively change the Node.js version
alternatives --config node
-
Switch to manual mode and select a specific version
alternatives --set node /usr/bin/node-{MAJOR_VERSION}
-
Switch back to auto version selection mode
alternatives --auto node