[Bug] - NodeJS Package Issue
Describe the bug The package nodejs.x86_64 is version 1:18.20.4-1.amzn2023.0.1. This needs to be updated to NodeJS 22, or at least NodeJS 20. As of December 18th 2024, updating NPM will fail due to the the version of NodeJS being <20.
To Reproduce Steps to reproduce the behavior:
- dnf install nodejs -y
- npm install npm -g
Expected behavior NPM should update without error.
Desktop (please complete the following information): I ran into this issue with the docker image amazonlinux:2023
Additional context
I also tried installing the package nodejs20. But subsequently running node --version gives "bash: node: command not found". Which I believe is also an issue.
EDIT: Adding link to NodeJS releases for easy reference - https://nodejs.org/en/about/previous-releases
@Joe-Zer0 if you install nodejs20 the name of the commands are node-20 and npm-20. After installation use update-alternatives to add node and npm:
[ec2-user@ip-x-x-x-x ~]$ sudo alternatives --install /usr/bin/node node /usr/bin/node-20 0
[ec2-user@ip-x-x-x-x ~]$ sudo alternatives --install /usr/bin/npm npm /usr/bin/npm-20 0
Verify:
[ec2-user@ip-x-x-x-x ~]$ alternatives --list
---cut---
node auto /usr/bin/node-20
npm auto /usr/bin/npm-20
[ec2-user@ip-x-x-x-x ~]$ command -v node
/usr/bin/node
[ec2-user@ip-x-x-x-x ~]$ command -v npm
/usr/bin/npm
[ec2-user@ip-x-x-x-x ~]$ node --version
v20.18.0
[ec2-user@ip-x-x-x-x ~]$ npm --version
10.8.2
Thank you for that workaround. That will be helpful. Hopefully they will update the main nodejs package soon.
I don't think they will. They usually leave the original package name for backwards compatibility and then append a short version number for subsequent releases. They did the same for python.
I believe that is due to python being critical to the functionality of the operation system. Most packages are kept up to date.
NodeJS 20 was added in the 2023.3.20231211 release, and can be installed through the nodejs20 package.
We namespace packages such as NodeJS so that we don't force customers to migrate from one major version to the next, rather allowing them to move at their own pace. This is covered for Python in the Python in AL2023 section of the Amazon Linux 2023 User Guide.
I am going to keep this issue open for some Documentation updates that cover nodejs specifically, as I see that isn't currently in our User Guide.
Should the existing syntax be used to allow users to pin a specific version?
sudo apt-get install <package name>=<version>
I think there should be a way to stay on the latest version (and latest LTS version in the case of node) without changing packages.
FYI there is now some documentation in the User Guide around how NodeJS is packaged in Amazon Linux 2023.
Let us know if this helps clarify or needs changes.
@zcobol , fyi NodeJS 18, as of the current latest package version 18.20.6-1.amzn2023.0.2 is managed by the alternatives tool already, right out of the box. And the support of the alternatives in NodeJS 20 package is coming!
$ cat /etc/amazon-linux-release
Amazon Linux release 2023.6.20250303 (Amazon Linux)
$ sudo dnf install -qy nodejs
Installed:
libbrotli-1.0.9-4.amzn2023.0.2.x86_64 nodejs-1:18.20.6-1.amzn2023.0.2.x86_64 nodejs-docs-1:18.20.6-1.amzn2023.0.2.noarch
nodejs-full-i18n-1:18.20.6-1.amzn2023.0.2.x86_64 nodejs-libs-1:18.20.6-1.amzn2023.0.2.x86_64 nodejs-npm-1:10.8.2-1.18.20.6.1.amzn2023.0.2.x86_64
$ alternatives --display node
node - status is auto.
link currently points to /usr/bin/node-18
/usr/bin/node-18 - priority 200
slave npm: /usr/bin/npm-18
slave npx: /usr/bin/npx-18
slave npmrc: /etc/npmrc.nodejs18
slave node_modules: /usr/lib/nodejs18/lib/node_modules
Current `best' version is /usr/bin/node-18.
$ node -v
v18.20.6
$ npm -v
10.8.2
@Joe-Zer0,
NPM should update without error.NPM should update without error.
as it's mentioned in the documentation that @stewartsmith has recently shared, every NodeJS release comes with a bunch of bundled software, and npm is one of it. For example, NodeJS 18.20.6 comes with the bundled npm 10.8.2
Ref: https://github.com/nodejs/node/blob/v18.20.6/deps/npm/package.json#L2
In addition, npm can be updated only up to a certain version in combination with the installed node version.
By the way, the npm is provided by thenodejs-npm package, and the one that comes with currently latest version 18.20.6-1.amzn2023.0.2 is able to update itself with no issues:
$ cat /etc/amazon-linux-release
Amazon Linux release 2023.6.20250303 (Amazon Linux)
$ sudo dnf install -qy nodejs
Installed:
libbrotli-1.0.9-4.amzn2023.0.2.x86_64 nodejs-1:18.20.6-1.amzn2023.0.2.x86_64 nodejs-docs-1:18.20.6-1.amzn2023.0.2.noarch
nodejs-full-i18n-1:18.20.6-1.amzn2023.0.2.x86_64 nodejs-libs-1:18.20.6-1.amzn2023.0.2.x86_64 nodejs-npm-1:10.8.2-1.18.20.6.1.amzn2023.0.2.x86_64
$ rpm -q nodejs-npm
nodejs-npm-10.8.2-1.18.20.6.1.amzn2023.0.2.x86_64
$ npm -v
10.8.2
$ sudo npm install -g npm
removed 9 packages, and changed 87 packages in 4s
25 packages are looking for funding
run `npm fund` for details
$ npm -v
10.9.2
$ npm list -g
/usr/lib/nodejs18/lib
└── [email protected]
npm notice
npm notice New major version of npm available! 10.9.2 -> 11.2.0
npm notice Changelog: https://github.com/npm/cli/releases/tag/v11.2.0
npm notice To update run: npm install -g [email protected]
npm notice
However, it's not possible to update npm to version 11.2.0 while having node version 18.20.6:
$ sudo npm install -g [email protected]
npm error code EBADENGINE
npm error engine Unsupported engine
npm error engine Not compatible with your version of node/npm: [email protected]
npm error notsup Not compatible with your version of node/npm: [email protected]
npm error notsup Required: {"node":"^20.17.0 || >=22.9.0"}
npm error notsup Actual: {"npm":"10.9.2","node":"v18.20.6"}
@stewartsmith - It would be nice if the documentation included the install flag. I found this comment (https://github.com/amazonlinux/amazon-linux-2023/issues/875#issuecomment-2575914401) more helpful than the documentation.
@Joe-Zer0, There is no need anymore in a manual installation (registration) of a NodeJS in the alternatives. It's done automatically by the pre/post install rpm scriptlets. When you install/remove NodeJS 18 or 20 (separately or at the same time) on Amazon Linux 2023, the registration/removal from the alternatives is done by the system.
The mentioned comment was a workaround for problems already fixed in the nodejs and nodejs20 packages, was written before those packages switched to using the alternatives tool, and is not quite compatible with the approach taken by the packages. For example, npm is now dependent on node. This means that in order to have a better experience when using NodeJS packages, you need to remove any workarounds you may have used previously, and let the new packages do the job the right way.
The support of alternatives in the NodeJS packages was introduced in following versions:
- NodeJS 18:
nodejs-18.20.6-1.amzn2023.0.1, AL release 2023.6.20250218 - NodeJS 20:
nodejs20-20.18.3-1.amzn2023.0.1, AL release 2023.7.20250331