NVM pre-installed on macOS only?

I’ve started migrating a workflow from TravisCI to GitHub actions.

The workflow is for a node.js app, and the repo includes an .nvmrc file that specifies the version of Node to install/use.

On TravisCI (where nvm is pre-installed), I previously used the following command to install the desired node.js version:

  - nvm install

Unfortunately I can’t do a similar thing in GitHub actions, because (as per the software in virtual environments page) it seems that nvm only comes pre-installed for the macOS environment, but not the Ubuntu environments.  Was there a specific reason for not having NVM available on Ubuntu?

From what I understand, in Github Actions the common practice for installing a different Node.js version (than the default pre-installed one) is to use the setup-node action and specify the version to install:


Unfortunately, setup-node currently does not look for a .nvmrc file (but it looks like support for this is being considered), and the workaround (read the contents of .nvmrc into an output) seems like a bit of an ugly hack:

- name: Read .nvmrc
  run: echo "##[set-output name=NVMRC;]$(cat .nvmrc)"
  id: nvm

- name: Use Node.js (.nvmrc)
  uses: actions/setup-node@v1
    node-version: "${{ steps.nvm.outputs.NVMRC }}"

I’m interested to understand if there was a reason why NVM was picked as a pre-installed option on macOS only, and not on any other environments.

For what it’s worth, I tried adding an “Install nvm” step into my workflow as follows:

- name: Install nvm
  run: |
    curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
    export NVM_DIR="$HOME/.nvm"
    source "$NVM_DIR/nvm.sh"

The curl command runs fine (I tested it on its own first); but the three commands together fail with:

##[error]Process completed with exit code 3.

The full output of the step is below:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
  export NVM_DIR="$HOME/.nvm"
  source "$NVM_DIR/nvm.sh"
  shell: /bin/bash -e {0}
  % Total % Received % Xferd Average Speed Time Time Time Current
                                 Dload Upload Total Spent Left Speed

  0 0 0 0 0 0 0 0 --:--:-- --:--:-- --:--:-- 0
100 13226 100 13226 0 0 92489 0 --:--:-- --:--:-- --:--:-- 92489
=> Downloading nvm from git to '/home/runner/.nvm'

Cloning into '/home/runner/.nvm'...
=> => Compressing and cleaning up git repository

=> Appending nvm source string to /home/runner/.bashrc
=> Appending bash_completion source string to /home/runner/.bashrc
N/A: version "12.1.0 -> N/A" is not yet installed.

You need to run "nvm install 12.1.0" to install it before using it.
=> You currently have modules installed globally with `npm`. These will no
=> longer be linked to the active version of Node when you install a new node
=> with `nvm`; and they may (depending on how you construct your `$PATH`)
=> override the binaries of modules installed with `nvm`:

├── bower@1.8.8
├── grunt@1.0.4
├── gulp@4.0.2
├── n@6.0.1
├── now@16.1.1
├── parcel-bundler@1.12.3
├── typescript@3.5.3
├── webpack@4.39.2
└── webpack-cli@3.3.7
=> If you wish to uninstall them at a later point (or re-install them under your
=> `nvm` Nodes), you can remove them from the system Node as follows:

     $ nvm use system
     $ npm uninstall -g a_module

=> Close and reopen your terminal to start using nvm or run the following to use it now:

export NVM_DIR="$HOME/.nvm"
[-s "$NVM_DIR/nvm.sh"] && \. "$NVM_DIR/nvm.sh" # This loads nvm
[-s "$NVM_DIR/bash_completion"] && \. "$NVM_DIR/bash_completion" # This loads nvm bash_completion
##[error]Process completed with exit code 3.

Not entirely sure how to diagnose the “process completed with exit code 3” error?

nvm is returning error code 3.  There’s several reports about this in their issue tracker, in particular, one that sounds relevant describing this behavior when installing nvm while currently in a directory that contains a .nvmrc file.

There are some potential workarounds there like passing the --install flag.

1 Like

Thanks @ethomson , I followed your suggestion and was able to get it working with the --install flag.