NVM step doesn't switch Node version after first time

I came across this issue when trying to use nvm@1 step to set Node version a second time because I need different version for the React Native Android build and the end-to-end tests on the APK afterwards.

So if you try calling the NVM step the second time, it’ll just keep the previous Node version in path, see this output and pay attention to the last line:

  % 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 15037  100 15037    0     0   240k      0 --:--:-- --:--:-- --:--:--  240k
=> nvm is already installed in /root/.nvm, trying to update using git

=> 
=> Compressing and cleaning up git repository
=> nvm source string already in /root/.profile
=> bash_completion source string already in /root/.profile
=> 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
Switching to working directory: /bitrise/src
Downloading and installing node v20.10.0...
Downloading https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz...
#=#=#                                                                         

######################                                                    31.7%

###############################################################           87.9%
######################################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v20.10.0 (npm v9.8.1)
v16.20.2

Also, if you try to use it in your Script step later, the nvm binary isn’t in path, you can’t just call $NVM_DIR/nvm.sh or /root/.nvm/nvm.sh, so after trying everything I could think of, the only thing that worked was to install NVM from scratch and manually force the Node binary to the front of $PATH. This was obviously pretty frustrating to figure out, so thought I should share:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash &&
export NVM_DIR="$HOME/.nvm" &&
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
nvm install &&
export PATH=$(echo `nvm which --silent` | sed 's/\/node$//'):$PATH &&
envman add --key PATH --value $PATH &&
nvm use &&
node -v

This assumes you have a .nvmrc and pick up the version from there dynamically, but you can also hardcode a version like:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash &&
export NVM_DIR="$HOME/.nvm" &&
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" &&
nvm install 20 &&
export PATH=$(echo `nvm which 20` | sed 's/\/node$//'):$PATH &&
envman add --key PATH --value $PATH &&
nvm use &&
node -v