Switch nodejs version on machine executor [solved]

Hello, thank you for your recipe. I didn’t know nvm is installed by default in machine executor.

Unfortunately it does’t work properly for me.
Node 8.11.3 is installed for me within the same step, but in next step I have node 6.x again

      - run:
          name: Install  Node.js 8.9.1 with build in nvm tool
          # https://www.cloudesire.com/how-to-upgrade-node-on-circleci-machine-executor/
          command: |
            export NVM_DIR="/opt/circleci/.nvm"
            [ -s "$NVM_DIR/nvm.sh" ] && . "$NVM_DIR/nvm.sh"
            nvm install v8.11.3 && nvm use v8.11.3 && nvm alias default v8.11.3
            node -v

      - run:
          name: Check node version
          command: |
            node -v

which outputs

# first step:
Now using node v8.11.3 (npm v5.6.0)
Now using node v8.11.3 (npm v5.6.0)
default -> v8.11.3
v8.11.3

# and second step:

v6.1.0
1 Like