How to setup and install node using nvm on macOS Sonoma?

Akarsh Seggemu, M.Sc.
2 min readJan 27, 2024

--

In my previous article — https://medium.com/@akarshseggemu/how-to-setup-macbook-pro-macos-sonoma-14-for-development-and-other-uses-using-homebrew-ec8738ee143a I shared how to setup brew on macOS Sonoma. In case, if you have not installed brew on your macOS please follow the article to install brew.

Install nvm— (Manage multiple Node.js versions)

brew install nvm

If you are using .zprofile or .zshrc you need to add the following to your shell profile. To add you can use nano or vim . In my case, I use .zprofile and I use nano .

nano ~/.zprofile
export NVM_DIR="$HOME/.nvm"
[ -s "/opt/homebrew/opt/nvm/nvm.sh" ] && \. "/opt/homebrew/opt/nvm/nvm.sh" # This loads nvm
[ -s "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" ] && \. "/opt/homebrew/opt/nvm/etc/bash_completion.d/nvm" # This loads nvm bash_completion

You need to source .zprofile or .zshrc after adding the above exports. This will load the variables to the shell environments. When you open the shell terminal next time it will be automatically loaded.

source ~/.zprofile

Install node LTS(long-term support)

nvm install node

Output

Downloading and installing node v21.6.1...
Downloading https://nodejs.org/dist/v21.6.1/node-v21.6.1-darwin-arm64.tar.xz...
################################################################################################################################################### 100.0%
Computing checksum with shasum -a 256
Checksums matched!
Now using node v21.6.1 (npm v10.2.4)
Creating default alias: default -> node (-> v21.6.1)

You can see from the above output the current node LTS version 21.6.1 is installed.

Check if node version installed using nvm

nvm ls 

Output

->      v21.6.1
default -> node (-> v21.6.1)
iojs -> N/A (default)
unstable -> N/A (default)
node -> stable (-> v21.6.1) (default)
stable -> 21.6 (-> v21.6.1) (default)
lts/* -> lts/iron (-> N/A)
lts/argon -> v4.9.1 (-> N/A)
lts/boron -> v6.17.1 (-> N/A)
lts/carbon -> v8.17.0 (-> N/A)
lts/dubnium -> v10.24.1 (-> N/A)
lts/erbium -> v12.22.12 (-> N/A)
lts/fermium -> v14.21.3 (-> N/A)
lts/gallium -> v16.20.2 (-> N/A)
lts/hydrogen -> v18.19.0 (-> N/A)
lts/iron -> v20.11.0 (-> N/A)

You can see from the above output the current node LTS version 21.6.1 is default version and the -> show the current version of node.

Verify the npm version installed

npm -v

Output

10.2.4

You can see from the above output the current npm version 10.2.4

Verify the node version installed

node --version

Output

v21.6.1

You can see from the above output the current node version 21.6.1 LTS.

nvm lets you install and use different version of node.

If you like my articles, please follow me on Medium and you can also support me by buying me a coffee.

--

--

Akarsh Seggemu, M.Sc.
Akarsh Seggemu, M.Sc.

Written by Akarsh Seggemu, M.Sc.

IT Team Lead | Post graduate Computer Science from TU Berlin | Telugu writings are found in this account https://medium.com/@akarshseggemu_telugu

No responses yet