CloudesireDevelopers Corner Blog How to upgrade node on CircleCI machine executor

How to upgrade node on CircleCI machine executor

CircleCI offers 3 different executor types: machine, Docker and MacOS. On Linux the best choice would be the docker executor but if you need full control over the job environment you must opt for the machine executor.

The default machine executor image includes Docker, docker-compose, along with common language tools like nvm for node.
The issue we have encountered at Cloudesire is that if you need a different version of node you can’t just install it via apt because the workspace uses nvm to manage node versions. And you can’t just use nvm because on every run CircleCI resets the nvm configuration.

What we have found to work is to load nvm from /opt/circleci/.nvm install the required version and set it as default.
For example to use node v8.11.3:

export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"
# config.yml
version: 2

    machine: true

      - checkout
      - run:
          name: Install [email protected]
          command: |
            nvm install v8.11.3
            nvm alias default v8.11.3

      - run: |
          npm version

Source: Developers’ Corner Blog