Change node version in macos executor

How can I update node version on macos executor?
I have already tried this Change node version in macos image, but it did not work as homebrew is always being updated, but not ruby which causes some random failures on CI and the second script do not install nvm even running the commands below

HOMEBREW_NO_AUTO_UPDATE=1 brew install nvm >/dev/null
set +e             
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
export NVM_DIR="/opt/circleci/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
nvm install 12
nvm alias default 12

I get nvm: command not found:

# Each step uses the same `$BASH_ENV`, so need to modify it
echo 'export NVM_DIR="/opt/circleci/.nvm"' >> $BASH_ENV
echo "[ -s \"$NVM_DIR/nvm.sh\" ] && . \"$NVM_DIR/nvm.sh\"" >> $BASH_ENV
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed

100 12461  100 12461    0     0  47210      0 --:--:-- --:--:-- --:--:-- 47380
=> Downloading nvm from git to '/Users/distiller/.nvm'

=> Cloning into '/Users/distiller/.nvm'...
remote: Enumerating objects: 261, done.        
remote: Counting objects: 100% (261/261), done.        
remremote: Compressing objects: 100% (227/227), done.        
remote: Total 261 (delta 31), reused 99 (delta 25), pack-reused 0        
Receiving objects: 100% (261/261), 115.89 KiB | 12.88 MiB/s, done.
Resolving deltas: 100% (31/31), done.
Note: checking out '6597e11971c5c71da97b67e9e8786dec23d52hn7'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b <new-branch-name>

=> Compressing and cleaning up git repository

=> Appending nvm source string to /Users/distiller/.bashrc
=> Appending bash_completion source string to /Users/distiller/.bashrc
=> 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
/bin/bash: line 4: nvm: command not found
/bin/bash: line 5: nvm: command not found

Trying to update with Homebrew:

brew unlink node >/dev/null
brew install node@12 >/dev/null
brew link --overwrite node@12 --force >/dev/null

I get the error about ruby version, because of the Homebrew updates automatically:
Updating Homebrew…
==> Downloading https://homebrew.bintray.com/bottles-portable-ruby/portable-ruby-2.6.3.mavericks.bottle.tar.gz

######################################################################## 100.0%
==> Pouring portable-ruby-2.6.3.mavericks.bottle.tar.gz
/usr/local/Homebrew/Library/Homebrew/brew.rb:10:in `<main>': Homebrew must be run under Ruby 2.6! You're running 2.3.7. (RuntimeError)

Exited with code exit status 1

I was able to install it with the code below. I used a circleci/node to test it locally, but it also worked on macos executor:

version: 2
jobs:
  build:
    docker:
      - image: circleci/node:6
    steps:
      - checkout
      - run: 
          name: install node@12.14.1
          command: |
              set +e         
              touch $BASH_ENV    
              curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.5/install.sh | bash
              echo 'export NVM_DIR="$HOME/.nvm"' >> $BASH_ENV
              echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> $BASH_ENV
              echo nvm install 12.14.1 >> $BASH_ENV
              echo nvm alias default 12.14.1 >> $BASH_ENV
      - run:
          name: verify node version
          command: node --version

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