Facebook X (Twitter) Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook X (Twitter) Instagram
    TecAdmin
    You are at:Home»MacOS»How To Install NVM on macOS with Homebrew

    How To Install NVM on macOS with Homebrew

    By RahulAugust 10, 20233 Mins Read

    Node Version Manager (NVM) is a widely-used tool that allows developers to manage multiple versions of Node.js on a single machine. Its importance cannot be overstated, as Node.js applications can sometimes be version-specific, and different projects may require different Node.js versions. The flexibility offered by NVM ensures a smooth development process, allowing developers to switch between Node versions seamlessly. On macOS, there are multiple methods to install NVM, but one of the most popular and efficient ways is using Homebrew, the renowned package manager for macOS.

    This guide will walk you through the detailed steps of installing NVM on macOS using Homebrew, allowing you to set up a flexible Node.js development environment with ease.

    Prerequisites

    • You must have macOS desktop access with administrator privileges.
    • If you don’t have Homebrew installed on your macOS, you can install it by pasting the following command in the terminal:
      /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" 
      

      For more instruction visit Homebrew installation tutorial.

    Step 1: Remove Existing Node Versions

    If your system already has a node installed, uninstall it first. My system already has installed node via Homebrew. So uninstalling it first. Skip if not already installed.

    brew uninstall --ignore-dependencies node 
    brew uninstall --force node 
    

    Step 2: Install NVM on macOS

    1. Before installing any packages, it’s always a good idea to update Homebrew to the latest version and update the formulae.
      brew update 
      
    2. After that, you can easily install NVM using the following command:
      brew install nvm 
      
    3. Next, create a .nvm directory in the home.
      mkdir ~/.nvm 
      
    4. Now, configure the required environment variables. Edit the following configuration file in your home directory
      vim ~/.bash_profile 
      
    5. Add the below lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or newer versions)
      
      export NVM_DIR="$HOME/.nvm"
      [ -s "/usr/local/opt/nvm/nvm.sh" ] && \. "/usr/local/opt/nvm/nvm.sh"
      [ -s "/usr/local/opt/nvm/etc/bash_completion" ] && \. "/usr/local/opt/nvm/etc/bash_completion"
      
      

      Press ESC + :wq to save and close your file.

    6. Next, load the variable to the current shell environment. From the next login, it will automatically loaded.
      source ~/.bash_profile   # or source ~/.zshrc 
      

    That’s it. The NVM has been installed on your macOS system. Go to next step to install Node.js versions with the help of nvm.

    Step 3: Using NVM

    First of all, see what Node versions are available to install. To see available versions, type:

    nvm ls-remote 
    

    Now, you can install any version listed in above output. You can also use aliases names like node for latest version, lts for latest LTS version, etc.

    nvm install node     ## Installing Latest version 
    nvm install 18       ## Installing Node.js 18.X version 
    

    After installing you can verify what is installed with:

    nvm ls 
    

    Install NVM macOS

    If you have installed multiple versions on your system, you can set any version as the default version any time. To set the node 18.X as default version, simply use:

    nvm use 18 
    

    Similarly, you can install other versions like Node 12, 15, and 18 versions and switch between them.

    Conclusion

    Having the capability to manage and switch between various Node.js versions is essential for modern web development, and NVM provides that flexibility. By leveraging Homebrew on macOS, the installation process becomes streamlined, making it easier than ever to get NVM up and running. Once installed, developers can enjoy a hassle-free experience, working on multiple Node.js projects regardless of their version requirements.

    This guide has furnished you with all the knowledge needed to install NVM on macOS using Homebrew. Now, you’re ready to tackle any Node.js project, knowing you have the power to easily manage and switch between Node versions at your fingertips.

    brew Homebrew nvm
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp

    Related Posts

    How to Enable Bash Completion on macOS

    How to Switch Between Zsh and Bash on macOS: A Comprehensive Guide

    How to Set Up Apache, MySQL, and PHP on macOS: A Comprehensive Guide

    View 45 Comments

    45 Comments

    1. Muneer AHmed on November 27, 2022 8:31 am

      I like the tutorial Thank a lot

      Reply
    2. Nawfel on November 15, 2022 4:50 pm

      thanks guys

      Reply
    3. Adina on November 10, 2022 2:29 pm

      I just want to say you saved my life!
      This is so amazing. thank you for this wonderful exact step by step guide
      God bless you

      Reply
    4. Aftab on October 15, 2022 3:34 am

      Amazing work!

      Reply
    5. jnsereko on September 22, 2022 7:42 am

      so cool 😎
      thanks Rahul

      Reply
    6. Ahmad Faraz on August 29, 2022 7:09 am

      Thankyou, your article was very helpful.

      Reply
    7. saif on August 11, 2022 8:15 pm

      thanks this is very helpful and great

      Reply
    8. Pablo Câmara on August 9, 2022 8:19 pm

      Why do you “export NVM_DIR=~/.nvm” right before the “source $(brew –prefix nvm)/nvm.sh”
      if inside the “$(brew –prefix nvm)/nvm.sh” there is already this export ?

      I have used only:
      source $(brew –prefix nvm)/nvm.sh

      and it works.

      Thanks for your post!

      Reply
    9. Syam Kishore on July 28, 2022 10:43 am

      Thank you so much for the detailed article

      Reply
    10. Maria on July 20, 2022 9:49 am

      Thank you so much! Your article was very helpful!

      Reply
    11. SOON on June 15, 2022 2:10 pm

      Thanks!!

      Reply
    12. Olivia on June 8, 2022 1:34 pm

      This is one of the few tutorials that actually worked. Thanks for making such a well-written post!

      Reply
    13. vnm on June 6, 2022 6:52 pm

      Thanks! This helped a lot!

      Reply
    14. umesh on May 24, 2022 1:12 pm

      it was usefull, thanks for clear explanation.

      Reply
    15. enzou on May 15, 2022 3:40 pm

      thanks, is a very useful article!

      Reply
    16. Guillaume Deschamps on May 9, 2022 9:44 am

      Hello,

      i am working on macOS BigSur v11.5.2. I wanted to install nvm in order to work with the 10.x version of sage/root (a wordpress theme builder).

      :: source ~/.bash_profile
      is not working for me.

      i used
      :: source ~/.nvm/nvm.sh
      instead.

      Thank you for the tut 😉

      Reply
      • alex escamilla on July 12, 2022 8:58 am

        Tengo exactamente la misma version, y me funciono muy bien

        Reply
    17. Kathy on May 6, 2022 3:06 pm

      Thank you for this tutorial.

      Reply
    18. Ravikant Kumawat on April 26, 2022 12:41 pm

      Nice Tutorial

      Reply
    19. Carmen on April 5, 2022 3:12 pm

      Thanks Rahul! Still very helpful!

      Reply
    20. Stuart on March 4, 2022 10:57 am

      Homebrew installation is not supported according to nvm docs:
      https://github.com/nvm-sh/nvm#installing-and-updating

      This article was a bit of a waste of time to be honest.

      I ended up with command not found: nvm
      This is because there was an empty .nvm folder in my user location.
      To fix this I installed nvm manually using:
      curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.1/install.sh | bash

      So you can skip over the homebrew stuff and just do that instead!

      Reply
      • Jens on March 30, 2022 6:24 am

        For me it worked using homebrew.

        Reply
    21. reena on December 16, 2021 2:50 pm

      Thanks.

      Reply
    22. Aykut Kılıç on December 13, 2021 6:55 pm

      Hello,

      Thanks for the clean explanation..
      I see a file named .zshenv. Is it possible to use this instead of zshrc?
      Regards.

      Aykut.

      Reply
    23. sowcheikh on December 13, 2021 1:18 am

      thank you so much. its ok for me

      Reply
    24. William Raiford on December 8, 2021 4:36 pm

      Thank you!

      Reply
    25. Florian on November 29, 2021 12:10 pm

      for beginners like me:

      last part of point 2 should be : source ~/.zshrc
      for any recent OS (Catalina, Big Sur, Monterey) It’s kind of mentioned at the step before that but it took me a minute 🙂

      Reply
    26. Ed on November 22, 2021 9:00 am

      Awesome. It saves my time. Great resource!!

      Thank you. !

      Reply
    27. Sachin on November 1, 2021 5:19 am

      Thanks a lot Rahul!

      Reply
    28. Raphy on October 23, 2021 12:08 am

      Very nice, thanks a lot!

      Reply
    29. Peter Holdsworth on October 6, 2021 12:25 pm

      nvm documentation explicitly states that homebrew installation is not supported. I tried it but had problems invoking minor versions of node.

      Reply
    30. Sitenol Team on July 19, 2021 1:03 pm

      Very Good Article Rahul

      Reply
      • peter on October 6, 2021 4:14 pm

        Totally agree and easy to understand and read.

        Reply
    31. George on July 19, 2021 12:25 pm

      When zshrc is installed, you have to add
      “`export NVM_DIR=~/.nvm
      source $(brew –prefix nvm)/nvm.sh“`
      to `~/.zshrc` file.

      Reply
      • Rahul on July 20, 2021 9:36 am

        Thanks George

        Reply
    32. sreedevi on July 16, 2021 6:39 am

      Thanks for sharing these details!

      Reply
    33. Felipe on July 7, 2021 6:37 am

      Easy to understand and working perfectly. Thanks you!

      Reply
    34. DK on July 6, 2021 8:02 pm

      amazing work dude

      Reply
    35. Michael on June 16, 2021 12:35 pm

      Definitely bookmarking this. Thanks

      Reply
    36. Johhny on June 7, 2021 7:37 am

      Thanks a lot, this article helped me to install nvm and node!

      Reply
    37. l_buzya on May 24, 2021 7:16 pm

      Thank you very much ??

      Reply
    38. Remya Senan on April 8, 2021 1:35 pm

      Good one, really helpful.

      Thank you so much.

      Reply
    39. Ahmad on April 8, 2021 11:36 am

      Thx for this tutorial. It was clear and very useful.

      Keep it going.

      Reply
    40. Albert on March 25, 2021 3:25 pm

      command not found: nvm

      Reply
    41. josfk on March 15, 2021 9:34 am

      Great resource!!

      Thanks so much Rahul!! This was extremely helpful.

      Reply

    Leave A Reply Cancel Reply

    Advertisement
    Recent Posts
    • Difference Between Full Virtualization vs Paravirtualization
    • Virtualization vs. Containerization: A Comparative Analysis
    • Using .env Files in Django
    • Using .env File in FastAPI
    • Setting Up Email Notifications for Django Error Reporting
    Facebook X (Twitter) Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.