node.js – How to install a specific Yarn version (3.x/4.x) in node:25-alpine Docker image?

I had a Docker image based on node:20-alpine that I upgraded to node:

I am trying to update my Dockerfile to use node:25-alpine. In previous Node versions, I could simply run apk add yarn to use Yarn Berry (3.6.1).

However, in Node 25, yarn is already installed but with an old version. Corepack is no longer included by default, so I can’t easliy update it with that. When I try to install it manually via npm install -g corepack, I encounter the following error, even when I don’t install yarn via apk:

npm error code EEXIST

npm error path /usr/local/bin/yarn

npm error EEXIST: file already exists

npm error File exists: /usr/local/bin/yarn 

How do I properly configure a node:25-alpine image to use a global version of Yarn 3.6.1?

Read more here: Source link