I have the start of my Dockerfile as below. Currently this installs version 10 of Node JS but I need a minimum of version 12. How can I change this to get v12?
FROM ruby:2.6.5
# Install 3rd party dependencies.
RUN curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add &&
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list &&
apt update &&
apt -y install nodejs
yarn
build-essential
libpq-dev
EDIT:
Error after trying @enrique-tejeda’s answer:
[ 2/13] RUN curl -fsSL https://deb.nodesource.com/setup_12.x | bash – apt-get install -y nodejs:
#5 0.328 /usr/bin/apt-get: /usr/bin/apt-get: cannot execute binary file
#5 0.440 curl: (23) Failed writing body (0 != 7027)
—— failed to solve: rpc error: code = Unknown desc = executor failed running [/bin/sh -c curl -fsSL
https://deb.nodesource.com/setup_12.x | bash – apt-get install -y
nodejs]: exit code: 126
2
Answers
You can install a specific version of nodejs installing the official Node.js Binary Distributions, for the 12.x version try this:
Reference: https://github.com/nodesource/distributions/blob/master/README.md#debinstall
In your Docker-based use case, as you already have node.js installed and maybe
npm
as well, you could try installing a more recent version of node by directly relying onnpm
? I mean:This strategy is mentioned here, among many other approaches, but it might not work, depending on how node.js has been installed in your base image.
Otherwise, a robust and user-wide way to update the version of node.js, consists in using
nvm
, the Node Version Manager.