[Bug] - /usr/lib/nodejs18/bin is linked to /usr/bin instead of /usr/local/bin incorrectly
Describe the bug
The latest amazonlinux:2023 introduced a breaking change in the minor or patch release amazonlinux:2023.6.20250218.2. Previously the npm prefix is set to /usr/local in /etc/npmrc while the latest one sets the prefix to /usr/lib/nodejs18. Also, the /usr/lib/nodejs18/bin is a soft link of /usr/bin. In the release note it's mentioned the change shouldn't affect the majority customers (https://docs.aws.amazon.com/linux/al2023/release-notes/relnotes-2023.6.20250218.html) but this change causes npm install kong-pdk to install kong-js-pluginserver into /usr/bin instead of /usr/local/bin, which breaks our install. Probably /usr/lib/nodejs18/bin should be linked to /usr/local/bin instead of /usr/bin.
To Reproduce Steps to reproduce the behavior:
docker run -it --rm amazonlinux:2023 /bin/bashyum install -y nodejs npm && yum clean all && npm install --unsafe -g kong-pdk
Expected behavior
The kong-js-pluginserver should be installed into /usr/local/bin but now it's installed into /usr/bin.
Additional context
If you use the image amazonlinux:2023.6.20250203.1 and below versions, the kong-js-pluginserver is installed into /usr/local/bin correctly.
@AndyZhang0707 from the nodejs-npm changelog:
* Tue Jan 14 2025 Alexey Tsvetnov <[email protected]> - 18.20.5-1.amzn2023.0.3
- Use the `alternatives` to switch between NodeJS versions and manage
/usr/bin/{node,npm,npx} file names
- NodeJS 18 is a default version, has the highest priority in the `alternatives`,
and is activated in auto mode when installed
- A global "node_modules" is moved to a namespaced location
under /usr/lib/nodejs18/ prefix and is also managed by the `alternatives`
This might help you understand what's going on. Moving forward nodejs will be managed with alternatives so there could be multiple version of nodejs installed.
npmrc differences:
Latest container release:
bash-5.2# cat /etc/npmrc
prefix=/usr/lib/nodejs18
python=/usr/bin/python3
2023.6.20250203.1 release:
bash-5.2# cat /etc/npmrc
prefix=/usr/local
python=/usr/bin/python3
Notice the prefix changes!
yum install -y nodejs npm && yum clean all && npm install --unsafe -g kong-pdk
Just a few thoughts about this command that might be helpful to others...
- In AL2023, the main package manager is
dnf. Sure,yumstill works, but only because it's sym-linked to dnf
$ ls -l $(which yum)
lrwxrwxrwx. 1 root root 5 Feb 7 20:55 /usr/bin/yum -> dnf-3
npmis a very very old package and is no longer used, and that's why it's now pointing tonodejs-npm, the package that provides thenpmof the right version that is compatible with the installed version of thenode. But in fact, it's even better, because you don't need to explicitly specify a package name to install npm, it will be installed as a recommended package automatically
$ sudo dnf install nodejs
Last metadata expiration check: 0:10:05 ago on Fri Mar 7 21:50:22 2025.
Dependencies resolved.
==========================================================================================================================================================
Package Architecture Version Repository Size
==========================================================================================================================================================
Installing:
nodejs x86_64 1:18.20.6-1.amzn2023.0.2 amazonlinux 13 M
Installing dependencies:
libbrotli x86_64 1.0.9-4.amzn2023.0.2 amazonlinux 315 k
nodejs-libs x86_64 1:18.20.6-1.amzn2023.0.2 amazonlinux 14 M
Installing weak dependencies:
nodejs-docs noarch 1:18.20.6-1.amzn2023.0.2 amazonlinux 7.8 M
nodejs-full-i18n x86_64 1:18.20.6-1.amzn2023.0.2 amazonlinux 8.4 M
nodejs-npm x86_64 1:10.8.2-1.18.20.6.1.amzn2023.0.2 amazonlinux 1.9 M
-
there is an official documentation that shares some details on the NodeJS package names and how to use
alternativesin the newer package version: https://docs.aws.amazon.com/linux/al2023/ug/nodejs.html -
should be linked to /usr/local/bin instead of /usr/binThere is actually no such a technical requirement. -
As far as I can see, the current version of the nodejs package that uses alternatives tool to manage NodeJS versions, correctly installs and runs the mentioned cli tool
$ sudo dnf install nodejs
$ sudo npm install -g kong-pdk
added 24 packages in 3s
npm notice
npm notice New major version of npm available! 10.8.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
$ npm -g root
/usr/lib/nodejs18/lib/node_modules
$ ls -l /usr/lib/nodejs18/lib/node_modules/
kong-pdk/ npm/
$ ls -l /usr/lib/nodejs18/lib/node_modules/kong-pdk/bin
total 4
-rwxr-xr-x. 1 root root 836 Mar 7 22:14 kong-js-pluginserver
$ ls -l /usr/lib/nodejs18/bin/kong-js-pluginserver
lrwxrwxrwx. 1 root root 53 Mar 7 22:14 /usr/lib/nodejs18/bin/kong-js-pluginserver -> ../lib/node_modules/kong-pdk/bin/kong-js-pluginserver
$ ls -l /usr/bin/kong-js-pluginserver
lrwxrwxrwx. 1 root root 53 Mar 7 22:14 /usr/bin/kong-js-pluginserver -> ../lib/node_modules/kong-pdk/bin/kong-js-pluginserver
$ which kong-js-pluginserver
/usr/bin/kong-js-pluginserver
$ kong-js-pluginserver --version
0.6.0
I don't see any issues with the package. It works as expected, npm correctly installs cli tools and they can be executed.