Skip to content
Theme:

Install Node.js — installer vs. Homebrew vs. NVM

No matter if you are working on backend or are in the frontend camp, Node.js is getting more popular day by day and you may need to install it at some point. There is plenty of ways to install it on your operating system and I am about to show you the most popular methods and highlight pros and cons of each of them.

Pre-built installer for your platform

The easiest and most obvious way is to download a pre-built installer for your platform from the Node.js downloads page. Installation itself is very straight forward — next, next, next, done.

Node.js pre-built installer

Despite the fact it is the easiest way of installing it, it comes with many disadvantages. It locks you to a particular version — it may not be a big issue on day one but it can be in the long run if you are willing to jump between projects that depend on different versions. Another (worst) issue with this method is the fact that it requires admin permissions (sudo) to install package globally. I published “Fix privileges and never again use sudo with npm” with some solutions for this issue, but you better check “Resolving EACCES permissions errors when installing packages globally” on official documentation or follow this article.

Node from Homebrew / Chocolatey

“Homebrew — the best friend of the macOS user” explains why I love this tool so much. Windows users can find an alternative like Chocolatey. Both of these package managers allow you to install Node.js with ease.

brew install node
choco install nodejs.install

CLI tools like that allow you to install / uninstall software in no time and never again be bothered by insufficient permissions. Although they allow you to manage versions too, in Node.js you should use…

NVM (Node Version Manager)

Node Version Manager is a simple bash CLI that allows you to install multiple Node.js versions and switch between them using simple commands. Although it is available for macOS and Linux only, Node.js version manager for Windows exists (ironically it is written in Go). Installation is straightforward — you can use a simple bash script or brew (my preferred way).

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

Thats the way to install the latest version of Node.js.

nvm install node

Be curious and explore more nvm commands on an official nvm documentation. My most frequently used commands are: install, uninstall, list and use.

NVM (Node Version Manager) — list all the installed versions

It is hard to remember the version of Node.js that a project depends on — smash the version into .nvmrc file in the root of your project and run nvm use inside this directory. If something can be automated, it should be automated — installing the right version of dependencies is not an exception. I made a simple bash script that runs nvm use whenever it encounters a .nvmrc file inside your project. There is a cool zsh-nvm plugin for Zsh users that does the same job.

Comments

  • K
    Karthik Varma

    Thanks for this great article!

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      I am glad it helped you out. Have a great day!

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • R
    Richard Rich Steinmetz

    thank you! definitely more detailed and nicer explained than other top google ranked posts on this topic. What are the most important reasons to use nvm over brew?

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Hi.

      Thanks for nice words. The main reason why I use nvm is the fact that I work on multiple projects. Some of them are built with the latest node runtime, some of server-less lambda stuff that I work on is on 8.10. The ease of switching versions is extremely convenient. Other than that and if you always work with the latest version I would suggest being stick to `brew install node`.

      Have a great day 🥑

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
      • R
        Richard Rich Steinmetz

        perfect, thank you for clarifying! :)

        👆 you can use Markdown here

        Your comment is awaiting moderation. Thanks!
  • A
    AA Parky

    Very helpful, thank you.

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Enjoy ⚡️

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • s
    skube

    It should be noted that installing nvm with Homebrew is not officially supported:

    Homebrew installation is not supported. If you have issues with homebrew-installed nvm, please brew uninstall it, and install it using the instructions below, before filing an issue.

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Yes you are right.

      The only reason why is the fact that nvm needs to be added to shell session. Official installation script does it for you. Brew installation requires a few lines of code to be added to .zshrc / .bashrc / .whareverrc...

      Post-install message from brew formula gives a detailed instruction about this step.

      Thanks for contribution. Have a fantastic day!

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • c
    careerinwriting

    Thank you. Now, I can move on with my Node.js course. Best wishes.

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      My pleasure. Good luck in your programming career!

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • E
    Enrique

    Thanks for share! Very useful information, just add the notes about the missing lines in the ~/.bash_profile that we should add when we install nvm through brew

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Thanks a ton for suggestion. I will update this article at some point. Have a great day Enrique 🥑

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • D
    Dickson

    Thank you very much, I was stuck with ng not found due to global permissions- this is helpful

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      I am glad it helped you out !

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • D
    Dickson

    I installed Homebrew, as a newbie, and ran the commands on z profile at the end of the installation. I successfully did brew install nvm. However, nvm install node gives me ""zsh: command not found nvm" am i doing something wrong here? I will work with different versions of node, how do I install these? should I cd into different directories then do brew install node_versionxx? , or should it be nvm install node_vesionxx when I am inside a specific directory? Thanks!

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      You installed everything correctly. The only thing that you need to do now is to configure your .bashrc file accordingly to nvm instructions (looks like you use bash not zsh).

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • C
    Cynthia

    Thanks for this article! Just got a new Mac and had to reinstall everything (I develop in Quasar) and of course, I forgot the details. :) Trying to install Node with the downloaded installation just kept getting me permission errors. Installed Homebrew first and viola, works. :)

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
  • P
    Pablo

    The one very obnoxious thing about nvm is the amount of time it takes for it to get loaded in your .bashrc file.

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      Personally I have never experienced such an issue.

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!
  • A
    Alberto Jacome

    I am new on Mac. I have a windows system where I installed nvm-windows and Node.js using Microsoft instructions. I want to install nvm, node.js and npm on Mac following you instructions. I already have Homebrew installed because I installed Git using it. I can see that I have Node.js 19.8.1 and npm 9.8.0, but not nvm. I want to install first nvm with Homebrew and then Node.js using nvm. Do I have to uninstall first the available Node.js and npm? Thanks for the useful information.

    👆 you can use Markdown here

    Your comment is awaiting moderation. Thanks!
    • Pawel Grzybek
      Pawel Grzybek

      You do everything correctly. As long as brew is installed, the only you need to do is…

      brew install nvm
      

      …and then you need to follow some post-install instructions. Have a look at nvm formula for more details.

      👆 you can use Markdown here

      Your comment is awaiting moderation. Thanks!

Leave a comment

👆 you can use Markdown here

Your comment is awaiting moderation. Thanks!