How to install node.js on Mac OS X

May 25, 2019

The method described on this page, to install node.js on Mac OS X is by using the nvm utility.


The reasons for chosing nvm are that with it, you can have several versions of node.js installed on your machine, and that everything is contained on your home folder. (Which will make it easier to remove it, if you later decide to uninstall node.js)


The first thing we need to check is if we have the .bash_profile file on our home folder.


We do that by executing the following commands on a terminal windows.


cd ~
ls .bash_profile

If the above commands return the message No such file or directory we will have to proceed to create the file as follows:


touch .bash_profile

Install nvm

Now we can proceed to install nvm.
So we head to the GitHub page of the nvm utility by opening the url https://github.com/nvm-sh/nvm on our favorite browser.


There we will find the installation script, which can be installed using either curl or wget.


At the time of this writing the command to install the current version, using curl, is as follows:


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

Install node

Now we can install node.js by running the following command.


nvm install node

Verify installation of node.js and npm (node package manager)

Finally we can verify the installation by checking the versions of node


node -v

and npm.


npm -v