Facebook Twitter Instagram
    TecAdmin
    • Home
    • FeedBack
    • Submit Article
    • About Us
    Facebook 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 RahulJune 8, 20222 Mins Read

    The NVM (Node Version Manager) is a shell script used for installing and managing Node.js on a Linux-based system. The macOS users can install NVM using the homebrew.

    Advertisement

    This tutorial helps you to install NVM on your macOS system and manage Node.js versions.

    Prerequisites

    You must have macOS desktop access with administrator privileges.

    Login to the macOS desktop system and install Homebrew on your system (if not already installed)

    ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" 
    

    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

    Now, your system is ready for the installation. Update the Homebrew package list and install NVM.

    brew update 
    brew install nvm 
    

    Next, create a directory for NVM at home.

    mkdir ~/.nvm 
    

    Now, configure the required environment variables. Edit the following configuration file in your home directory

    vim ~/.bash_profile 
    

    and, add the below lines to ~/.bash_profile ( or ~/.zshrc for macOS Catalina or newer versions)

    export NVM_DIR=~/.nvm
    source $(brew --prefix nvm)/nvm.sh
    

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

    Next, load the variable to the current shell environment. From the next login, it will automatically loaded.

    source ~/.bash_profile
    

    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 – Install Node.js with 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 14       ## Installing Node.js 14.X version 
    

    After installing you can verify what is installed with:

    nvm ls 
    

    nvm list node.js 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 14.X as default version, simply use:

    nvm use 14 
    

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

    Conclusion

    This tutorial explained you to how to install NVM and node.js on the macOS system.

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

    Related Posts

    How to Install Postgres on MacOS

    How To Install PostgreSQL on MacOS

    How to Change Terminal Font Size in macOS

    How to Install LibreOffice on Mac

    How to Install LibreOffice on macOS

    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
    • Implementing a Linux Server Security Audit: Best Practices and Tools
    • cp Command in Linux (Copy Files Like a Pro)
    • 15 Practical Examples of dd Command in Linux
    • dd Command in Linux (Syntax, Options and Use Cases)
    • Iptables: Common Firewall Rules and Commands
    Facebook Twitter Instagram Pinterest
    © 2023 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

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