There are several ways to install Node.js. One of them is through it’s binary. This way of installation is not recommended since Node.js is constantly getting updates.
So to stay up-to-date. Node.js has many version managers. For instance, nvm, n, nodenv, asdf, etc. Today I am going to show you the working of nodenv which is an excellent Node version manager.
The first thing you need to do is install nodenv. You can either do this with Homebrew or you can use curl. If you have decided to go with Homebrew, copy-paste the following command in your terminal and press the Enter key.
brew install nodenv
If you are using curl, then do the same thing I described above but with the following command.
curl -fsSL https://github.com/nodenv/nodenv-installer/raw/master/bin/nodenv-doctor | bash
This will install nodenv on your computer.
Now to install Node.js on your computer, you need to run the following command.
nodenv install $version
You need to provide the version you want to install. You can also install multiple versions if you want.
To list all the available versions, nodenv provides you a command. Just copy and paste it into your terminal.
nodenv install -l
nodenv is an excellent Node.js version manager that you can try. If you are interested in taking a deep dive into it, here is the link to its documentation.