Considering starting Node.js development on your MacBook but unsure which version to choose? Managing multiple versions of Node.js is essential for developers working on diverse projects with different Node.js requirements. In this tech tech concept, I’ll walk you through the process of installing Node.js and managing various versions on a MacBook using Node Version Manager (NVM) along with different method of installing Node.js on MacBook.
Installing Node.js on a MacBook
There are several ways to install Node.js on macOS. We’ll cover three methods: using Homebrew, using NVM, and downloading from the official Node.js website.
1. Using Homebrew
Homebrew is a popular package manager for macOS. If you don’t have Homebrew installed, you can install it by opening Terminal and running the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Once Homebrew is installed, you can install Node.js using these commands:
brew update
brew install node
2. Using Node Version Manager (NVM)
NVM allows you to install and switch between different versions of Node.js seamlessly.
- Install NVM:
Open Terminal and run:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
- Load NVM:
Add the following lines to your~/.zshrc
(default to macOS terminal) or~/.bash_profile
file, then source it:
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 editing the file, reload it by running:
source ~/.zshrc
# or
source ~/.bash_profile
- Install Node.js with NVM:
To install the latest version of Node.js, run:
nvm install node
To install a specific version of Node.js, run:
nvm install <version>
For example:
nvm install 14.17.0
3. Download from Node.js Website
You can also download the installer directly from the Node.js official website.
- Go to Node.js downloads page.
- Download the macOS installer.
- Run the downloaded
.pkg
file and follow the instructions.
Verification
After installation, you can verify that Node.js and npm (Node Package Manager) are installed correctly by running:
node -v
npm -v
This will print the versions of Node.js and npm installed on your system.
Managing Node.js Versions with NVM
Once NVM is installed, managing multiple versions of Node.js becomes straightforward.
Install NVM
If you haven’t already installed NVM, you can do so by running the following command in your Terminal:
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
Load NVM
Add the following lines to your ~/.zshrc
or ~/.bash_profile
file, then source it:
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 editing the file, reload it by running:
source ~/.zshrc
# or
source ~/.bash_profile
Install Node.js Versions
To install a specific version of Node.js, use the following command:
nvm install <version>
For example, to install Node.js version 14.17.0, run:
nvm install 14.17.0
List Installed Versions
To see a list of all Node.js versions installed on your system, run:
nvm ls
Switch Between Versions
To switch to a different installed version of Node.js, use:
nvm use <version>
For example, to switch to version 14.17.0, run:
nvm use 14.17.0
Set Default Version
To set a default Node.js version to be used in new shells, use:
nvm alias default <version>
For example, to set version 14.17.0 as the default, run:
nvm alias default 14.17.0
Uninstall Node.js Versions
To uninstall a specific version of Node.js, use:
nvm uninstall <version>
For example, to uninstall version 14.17.0, run:
nvm uninstall 14.17.0
Example Workflow for managing Node.js version
Here’s an example workflow demonstrating the above commands:
# Install NVM
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.3/install.sh | bash
# Load NVM
source ~/.zshrc # or source ~/.bash_profile
# Install specific Node.js versions
nvm install 14.17.0
nvm install 16.13.0
# List installed versions
nvm ls
# Switch to a specific version
nvm use 14.17.0
# Set a default version
nvm alias default 14.17.0
# Uninstall a version
nvm uninstall 16.13.0
My Tech Advice: As a seasoned tech entrepreneur and code developer, I understand how crucial it is to have different development environments ready for critical tasks. Managing different versions is essential not only for Node.js but also for any programming language you choose for your tech projects. By using NVM, you can efficiently manage multiple versions of Node.js and switch between them as needed. This flexibility is particularly beneficial for developers working on various projects with different Node.js version requirements. Happy Coding, My Fellow Alchemist! 🧙♀️🧪
#AskDushyant
#NodeJS #macOS #NVM #VersionManagement #WebDevelopment #JavaScript #TechGuide #DeveloperTips #Coding #Programming
Leave a Reply