CircleCI forgetting node version on machine executor

Driving me crazy. I’m setting the node version to 10.15.1 with nvm and in the next run step it’s back to 6.1.0 . I’ve tried several variations including this one :

Am I missing something obvious? I just need each run step to remember the node version I set in the first one so they will all use 10.15.1 in this case.

Here is the job in my workflow:

    BASH_ENV: run/env/test/.env
    image: circleci/classic:latest
  - checkout
  - run:
      name: Install node@10
      command: |
        set +e

        curl -o- | bash
        export NVM_DIR="/opt/circleci/.nvm"
        [ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"
        nvm install 10
        nvm alias default 10

        rm -rf ~./node-gyp

        node -v # prints 10.15.1 as expected
  - run:
      name: Install yarn and rsync
      command: |
        node -v # prints 6.1.0

        export NVM_DIR="/opt/circleci/.nvm"
        [ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"

        node -v # prints 6.1.0

        curl -sS | sudo apt-key add -
        echo "deb stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
        sudo apt-get update && sudo apt-get install yarn rsync

  - run:
      name: Install node modules
      command: |
        node -v # prints 6.1.0

        yarn install # this is what is failing because of the unexpected node version

  - run:
      name: Deploy to Dev Server
      command: |
        if [ "${CIRCLE_BRANCH}" == "master" ]; then rsync -arhvz --exclude .git/ -e "ssh -o StrictHostKeyChecking=no" --progress \
        ./; fi
        if [ "${CIRCLE_BRANCH}" == "master" ]; then ssh -o StrictHostKeyChecking=no 'cd /var/www/xxx/xxx && pm2 restart all --update-env'; fi

I think this gets added to a file that isn’t sourced on each step due to a non-login shell. Can you try writing them to $BASH_ENV as explained here and see if that helps?

Not working when I replace that code with this :

echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
echo "[ -s \"$NVM_DIR/\" ] && . \"$NVM_DIR/\"" >> $BASH_ENV

If I do that, then I get :

export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
/bin/bash: line 6: nvm: command not found
/bin/bash: line 7: nvm: command not found

I have a feeling my syntax is off. I also tried adding source $BASH_ENV which didn’t help

This seems to work for now :

Seems the alias doesn’t hold but nvm can still pull up the previously installed version.


get we get admins to have a look at this, having to source nvm each time is crazy!

Solved with this post

1 Like

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.