10

I am a newbie with Linux general, and here's what I am trying to achieve:

I am trying to install nodejs version on Debian Linux with the following command:

apt-get install nodejs=8.14.0

But I get this error in return:

E: Version '8.14.0' for 'nodejs' was not found

As far as I found, this is the correct way to specify a version. If I do this, then it works fine:

apt-get install nodejs

But I need this specific version, and not the latest one. I am doing this for a Docker image, so it has to be installed at runtime.

nullpointer
  • 490
  • 2
  • 4
  • 20
  • 1
    There is a guide called [Installing Node.js via package manager](https://nodejs.org/en/download/package-manager/) which links to a [github page with commands to use](https://github.com/nodesource/distributions/blob/master/README.md#installation-instructions=). – Ben Butterworth Apr 05 '22 at 09:19

3 Answers3

11

Make sure you have the following packages:-

sudo apt-get install \
    apt-transport-https \
    curl \
    software-properties-common

Enable the NodeSource repository by using a command:-

sudo curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -

After enabling the repository, install Node.js using a command:-

sudo apt-get install nodejs
Godfather
  • 27
  • 1
  • 6
Munish
  • 1,377
  • 9
  • 16
  • I need to install curl for this, will give it a shot. – nullpointer Feb 05 '20 at 23:01
  • 1
    You have the full list of available nodejs versions https://github.com/nodesource/distributions#installation-instructions (maybe you can put this link in your anwser?) – jawira Jan 24 '22 at 10:01
1

If you're doing this for a Docker image, why not just use the Node Docker image with the version you need?

  • Because I need to make a custom image with specific java and gradle versions. – nullpointer Feb 05 '20 at 23:00
  • It sounds like you're going about building the Docker image the wrong way then, to be honest. What is it you're trying to accomplish? Because if it's to build something, maybe we can help you evaluate your approach, rather that installing all of this into a single container. –  Feb 07 '20 at 18:49
  • I want to create one image, that I can re-create everytime on a build that will use specific Java, Gradle, Node etc. versions in that image. Either this image will be re-built everytime or I can keep it in a private repo and re-use it. Please let me know if this seems wrong, I am new to Docker. – nullpointer Feb 07 '20 at 20:20
  • So I guess the question is _what_ are you trying to do with all of that, though? Build some kind of containerized CI system? Build a node project? Build and host a Node project? Without knowing what you're trying to do, it makes it tough to advise, but in general installing a bunch of stuff like you're describing sounds like an anti-pattern. –  Feb 10 '20 at 16:32
  • I am trying to containerize the build of this application. Isn't the point to have everything (Like nodejs, gradle, java) pre-installed on an image and just re-use it without having to worry about the installations? At least that's what I got out the whole containerization thing. I will just use it for builds, and not hosting the node project, as its a SpringBoot application. – nullpointer Feb 14 '20 at 15:03
  • It sounds like you'd want to do a multi-stage build or initContainers, really. If the container has to be built at runtime, you could run the gradle stuff as an initContainer to another container that hosts the node project. The two could share a volume, and the gradle initContainer could output the project to that volume. Or, you could do a multi-stage build where, in one dockerfile, you use an image to build the project, and then another image stage uses the output "FROM" the initial build to make a container with *just* the build artifacts. –  Feb 14 '20 at 18:40
  • Further, the general point of containers is to have *just* the things you need to run the project, in the end. It's kind of like, if you were running a C# project, you wouldn't want to install Visual Studio in a container, right? Same basic idea with having Gradle and Java in there. You might need Node in the image to build it, but you'd use a separate image/container that JUST had Node and nothing else, in order to run it. –  Feb 14 '20 at 18:42
  • Different containers sound like a good idea. Thanks @alc6379. Can you point me to some link that has an example similar to this, one container builds an image and the other container can pick it up? I am new to Docker. – nullpointer Feb 14 '20 at 19:38
  • 1
    I'd start here, and then post more to SO if you have questions! https://docs.docker.com/develop/develop-images/multistage-build/ –  Feb 17 '20 at 19:05
0

You can try installing your node using a package manager like nvm:

Installing Node.js to linux

Or download the binaries directly from here: Node.js v8.14.0

Charles. Hi
  • 111
  • 1
  • 8