How to Set the Default Node Version Using Nvm on MacOS

NottDev
1 min readOct 3, 2024

--

To set Node.js version 18 as the default version on macOS, you can use a Node.js version manager like nvm (Node Version Manager). Here's how to do it:

Step-by-Step Guide

  1. Install nvm (Node Version Manager):

If you don’t have nvm installed yet, you can install it with the following commands:

Open your terminal and run:

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.5/install.sh | bash

2. Activate nvm:

After installation, add nvm to your shell profile. If you're using bash, add the following line to your ~/.bash_profile or ~/.bashrc file. For zsh, add it to your ~/.zshrc file:

export NVM_DIR="$([ -z "${XDG_CONFIG_HOME-}" ] && printf %s "${HOME}/.nvm" || printf %s "${XDG_CONFIG_HOME}/nvm")"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

After adding this line, run the following command to reload your shell configuration:

source ~/.bashrc # or ~/.zshrc, depending on your shell

3. Install Node.js Version 18:

Use nvm to install Node.js version 18:

nvm install 18

4. Set Node.js Version 18 as Default:

To make Node.js 18 the default version, run the following command:

nvm alias default 18

5. Verify the Default Node Version:

To check that Node.js 18 is the default version, run:

node -v

This should return v18.x.x.

Now Node.js 18 is set as the default version on your macOS!

--

--

NottDev
NottDev

Written by NottDev

Your only limit is your mind.

No responses yet