2

What is the recommended way to do the follwing:

  • install a specific version of node in a ddev container
  • so it persists (after ddev stop/start)
  • and every user that downloads and builds the container gets the right node version?

The idea behind it is to "nail" the node version for compatibility (in our case, with older versions of Foundation for Sites framework)

Urs
  • 4,984
  • 7
  • 54
  • 116
  • Does this answer your question? [How can I add and use nvm in a DDEV web container?](https://stackoverflow.com/questions/58415512/how-can-i-add-and-use-nvm-in-a-ddev-web-container) – leymannx Oct 26 '21 at 11:33
  • @leymannx I decided it's too complex and dropped the task – Urs Oct 30 '21 at 11:35

3 Answers3

3

Edit 2022-08-10: In DDEV v1.19+ nvm is already pre-installed, and can be easily used inside the container or with ddev nvm.

Original anwer: What you really want is nvm for this requirement, so this is a duplicate of https://stackoverflow.com/a/61934500/215713, which shows how to install nvm with a specific default node version.

rfay
  • 9,963
  • 1
  • 47
  • 89
  • Thanks! You are very right, actually I wanted nvm but I thought I'd also take less :-) – Urs May 24 '20 at 16:05
1

I know this is an old question and also already marked as "Answered", but I would like to add my own answer since OP was not enterily happy and couldn't complete what he was asking.

If you want a specific node version then you can edit you .ddev/config.yaml file and add a post-start hook, like this one:

hooks:
 post-start:
   - exec: nvm install v1x.xx.0 && nvm current

I added the nvm current command just so you can verify you are running your desire node version.

That way everytime you run ddev start you will have that version installed for that specific project.

DarkteK
  • 821
  • 1
  • 15
  • 26
1

We switched to use basic ddev commands. This proved very flexible and robust:

.ddev/commands/web/npm_install -> ddev npm_install

#!/bin/bash

## Description: Se gulp
## Usage: npm_install
## Example: ddev npm_install

GREEN='\033[0;32m'
RED='\033[0;31m'
NC='\033[0m\n' # set no color and line end

printf "${GREEN}Launching npm install inside ddev${NC}"

nvm install v17
nvm use v17

cd path/to/dir-with-gulpfile

npm install

.ddev/commands/web/build -> ddev build

#!/bin/bash

cd path/to/dir-with-gulpfile

gulp build
Urs
  • 4,984
  • 7
  • 54
  • 116