# Circleci 2.0 installing nvm on docker executor fails

**URL:** <https://discuss.circleci.com/t/circleci-2-0-installing-nvm-on-docker-executor-fails/38011>\
**Category:** Build Environment\
**Tags:** nodejs, docker, circle-yml, 2.0\
**Created:** [November 5, 2020, 2:26pm UTC](https://discuss.circleci.com/t/circleci-2-0-installing-nvm-on-docker-executor-fails/38011 "2020-11-05T14:26:11Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![joepagan](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/joepagan/32/25906_2.png) [@joepagan](https://discuss.circleci.com/u/joepagan)\
**Post date:** [November 5, 2020, 2:26pm UTC](https://discuss.circleci.com/t/circleci-2-0-installing-nvm-on-docker-executor-fails/38011/1 "2020-11-05T14:26:11Z")

</div>

I’m trying to install nvm and set the node version based on the .nvmrc in my app

I have tried almost every potential suggestion from all other threads and it doesn’t reliably work.

I have to highlight, that on 1 app I have got it working with [this solution](https://stackoverflow.com/questions/49232758/how-to-enable-nvm-in-steps-in-circleci-2-0), however, trying the same exact method on another app it fails with `exit status 3`.

To be clear my build process fails at the following command as shown in my full config at the bottom:

```
nvm install
NODE_VERSION=$(node -v)
nvm alias default ${NODE_VERSION//v}

```

The failure is:

```auto
Exited with code exit status 3
CircleCI received exit code 3

```

[This comment suggests](https://github.com/nvm-sh/nvm/issues/1985#issuecomment-456022013) that this could occur when one would source inside the same dir as an `.nvmrc` file, so, I have tried to `cd ..` then back in to the dir to `nvm install` after sourcing, however I get the same result `Exited with code exit status 3`:

```
- run:
    name: Install nvm
    command: |
      cd ..
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
      echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
      echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
- run:
    name: Set node to version required by application for future circleci steps
    command: |
      cd ~/repo
      nvm install
      NODE_VERSION=$(node -v)
      nvm alias default ${NODE_VERSION//v}

```

Full config without `cd`ing:

```
version: 2
jobs:
  node-setup:
    docker:
      - image: circleci/python:3.7
    working_directory: ~/repo
    steps:
      - checkout
      - setup_remote_docker:
          docker_layer_caching: true
      - run:
          name: Install nvm
          command: |
            curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.36.0/install.sh | bash
            echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
            echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
      - run:
          name: Set node to version required by application for future circleci steps
          command: |
            nvm install
            NODE_VERSION=$(node -v)
            nvm alias default ${NODE_VERSION//v}
      - run:
          name: node version
          command: |
            node -v

```

Additionally, Trying [this solution](https://discuss.circleci.com/t/nvm-does-not-change-node-version-on-machine/28973/14) results in a failure too, though I am aware this is for `machine` not `docker`:

```
#!/bin/bash -eo pipefail
node -v
/bin/bash: node: command not found
Exited with code exit status 127
CircleCI received exit code 127

```

Any help would be appreciated,  
Thanks in advance,  
Joe

---

<div class="post-metadata">

**Author:** ![joepagan](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/joepagan/32/25906_2.png) [@joepagan](https://discuss.circleci.com/u/joepagan)\
**Post date:** [November 5, 2020, 4:17pm UTC](https://discuss.circleci.com/t/circleci-2-0-installing-nvm-on-docker-executor-fails/38011/2 "2020-11-05T16:17:52Z")

</div>

I have figured out my issue it seems…

For some reason it works with: `- image: circleci/python:3.7-node`  
not: `- image: circleci/python:3.7`,  
strange, I didn’t realise you need node for the thing that installs node

Doesn’t appear to show as being a prerequisite on [https://github.com/nvm-sh/nvm#system-version-of-node](https://github.com/nvm-sh/nvm#system-version-of-node) but whatever 🤷‍♀️

---

<div class="post-metadata">

**Author:** ![nolson-berry](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@nolson-berry](https://discuss.circleci.com/u/nolson-berry)\
**Post date:** [November 5, 2020, 7:52pm UTC](https://discuss.circleci.com/t/circleci-2-0-installing-nvm-on-docker-executor-fails/38011/3 "2020-11-05T19:52:00Z")

</div>

This has always worked for us…(snippets of our deploy steps)

```auto
setupNvm: &setupNvm
  name: Setup NVM
  command: |
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    echo 'export NVM_DIR=$HOME/.nvm' >> $BASH_ENV
    echo 'source $NVM_DIR/nvm.sh' >> $BASH_ENV
setupNode: &setupNode
  name: Setup Node
  command: |
    nvm install 12.13
    nvm use node
    node -v
    npm i -g npm@6.12.0
    npm -v

```

---

<div class="post-metadata">

**Author:** ![hvitis](https://sea2.discourse-cdn.com/circleci/user_avatar/discuss.circleci.com/hvitis/32/26558_2.png) [@hvitis](https://discuss.circleci.com/u/hvitis)\
**Post date:** [January 28, 2021, 11:15pm UTC](https://discuss.circleci.com/t/circleci-2-0-installing-nvm-on-docker-executor-fails/38011/4 "2021-01-28T23:15:06Z")

</div>

> [@joepagan](#):
>
> - image: circleci/python:3.7-node

Worked!

- image: circleci/python:3.7-node

Thanks
