GitHub Actions virtual environments (VM images) include nvm, the Node Version Manager,
the nvm
command doesn't work by default on GitHub Actions (GHA).
This document describes how to get it working,
and demonstrates how to integrate nvm and npm with GHA's handy caching functionality to speed up your builds.
Why doesn't the nvm
command work by default?
Recall that when you install nvm it adds a snippet to your shell's startup scripts.
For Bash, it's added to ~/.bash_profile
, which is only sourced (included) as part of interactive shell startup [1].
A GHA run step runs Bash with flags that skip sourcing that file, by default:
bash --noprofile --norc -eo pipefail {0}
If you override the shell
command to include the --login
flag Bash will automatically do the sourcing:
jobs:
steps:
- run: |
nvm install
shell: "bash -eo pipefail --login {0}"
This is a bit of a mouthful to repeat on each step, but that's what it takes.
[1] | See the INVOCATION section of bash(1) |