Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Setup Node Version Manager (NVM) on macOS M1 Silicon
Eric Bishard
Eric Bishard

Posted on • Edited on

     

Setup Node Version Manager (NVM) on macOS M1 Silicon

As a web developer these days, we typically need to be able to switch versions of Node on the fly, for this we want to install Node Version Manager on a clean install of our machine, we don't want to start by installing Node on its own as this will give us a single version of Node (whichever we decide to install)

If you install Node first and then try to install NVM, things can get complicated, so if you have already installed Node, my suggestion is to completely remove it before installing NVM.

As well, NVM is explicitly not supported when installed via homebrew - the only correct way to install it is with the install script inNVM's Readme.

So if you have a Mac M1, these are the steps I would encourage you to try.

Navigate to your home directory

cd ~
Enter fullscreen modeExit fullscreen mode

Create a.zshrc file (if it doesn't exist)

touch .zshrc
Enter fullscreen modeExit fullscreen mode

Before proceeding to the next step I needed to manually install Rosetta 2 in order run apps not built for Apple silicon.

softwareupdate --install-rosetta
Enter fullscreen modeExit fullscreen mode

Install NVM using curl (found on the NVM Readme)

curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
Enter fullscreen modeExit fullscreen mode

This last command will update your.zshrc file to look like the following:

export NVM_DIR="$HOME/.nvm"[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"  # This loads nvm[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Enter fullscreen modeExit fullscreen mode

Install Node using NVM

nvm install node
Enter fullscreen modeExit fullscreen mode

This will install the latest version of Node (v17.x at time of writing).

NOTE: Node versions before v15.x are not necessarily ARM compatible, but it seems that Node has addressed this issue, so if you do install a version prior to v15.x hopefully, you will not need to use Rosetta to run.

Install LTS version of Node

nvm install --lts
Enter fullscreen modeExit fullscreen mode

Running this command installed the current Node LTS which at the time of this writing is v16.x. I think I will try to stick with this version or better when developing, however; that's the beauty of NVM is that if I need and older version it's easy to switch!

List the versions of Node I have installed

nvm ls
Enter fullscreen modeExit fullscreen mode

Select an alternate version that I have installed

nvm use 16
Enter fullscreen modeExit fullscreen mode

or

nvm use --lts
Enter fullscreen modeExit fullscreen mode

Finally, to clear the nvm cache to reduce clutter, run:

nvm cache clear
Enter fullscreen modeExit fullscreen mode

Setting Default

nvm alias default v10.19.0
Enter fullscreen modeExit fullscreen mode

But it will give the following error

! WARNING: Version 'v10.19.0' does not exist. default -> v10.19.0 (-> N/A)
Enter fullscreen modeExit fullscreen mode

In that case, you need to run two commands in the following order

Install the version that you would like

nvm install 10.19.0
Enter fullscreen modeExit fullscreen mode

Set 10.19.0 (or another version) as the default

nvm alias default 10.19.0
Enter fullscreen modeExit fullscreen mode

Use a Specific Node Version

nvm use 12Now using node v12.22.3 (npm v6.14.13)
Enter fullscreen modeExit fullscreen mode

Now we are using that latest version of node. As time goes on, I could keep periodically running:

nvm install 12
Enter fullscreen modeExit fullscreen mode

And get any updates to the latest of that version, or set a more specific earlier version, and then I would have two different versions of 12 I could go back and forth if needed during development.

Uninstall a Node Version

nvm uninstall 12nvm: Cannot uninstall currently-active node version, v12.22.3 (inferred from 12).
Enter fullscreen modeExit fullscreen mode

Notice the comment about it inferring because we were not specific. But, we are on the node we are trying to delete, we need to get off of this version to delete it:

nvm use 16 && nvm uninstall 12Now using node v16.4.2 (npm v7.18.1)Uninstalled node v12.22.3
Enter fullscreen modeExit fullscreen mode

This is not a topic widely talked about in one easy to find resource and the best sources I have found on the subject came fromCode Fallacy on YouTube andMichael Baldwin who both have good information on this topic, so much thanks to them where all credit is due...

Top comments(7)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss
CollapseExpand
 
sandorturanszky profile image
Sandor | tutorialhell.dev
Sharing my wisdom and experiences is totally my thing, and you can feel the vibes in the epic tutorials I craft.
  • Email
  • Location
    Malta
  • Work
    Head of Platform and Infrastructure, where I combine my programming skills with DevOps.
  • Joined

You could add the need for refreshing zsh profile from the users home directorysource ~/.zshrc

CollapseExpand
 
httpjunkie profile image
Eric Bishard
Fullstack JavaScript, Web3 with twenty years of web development experience.
  • Location
    Palm Bay, FL
  • Education
    FullSail University
  • Work
    Software Engineer at MetaMask
  • Joined

Thank you, I will try to add this soon. I found a few small issues with this article, thank you for the feedback.

CollapseExpand
 
jubarcelos profile image
Julia Barcelos
I'm a Web Development student at Trybe. I enjoy writing and talking about technology and I'm using this media to improve my English and share my knowledge as well. My first language is Portuguese.
  • Location
    Florianópolis, SC, Brazil
  • Education
    Web dev full stack - Trybe | MBA project manager | Bachelor degree Chemistry.
  • Joined

Great! Tks, this article help me a lot. =)

CollapseExpand
 
jovylle profile image
Jovylle B
I do develop and maintain websites in code level.

Nice Thank. Great help.

CollapseExpand
 
franciscojs profile image
Francisco
Web Developer (Frontend/React)
  • Location
    Argentina
  • Work
    Frontend Developer
  • Joined

Thanks! This helped me get nvm working, I also edited my.bash_profile with the same code as.zshrc

CollapseExpand
 
deepankar_ios profile image
Deepankar Gupta
  • Joined

after running command:
curl -o-raw.githubusercontent.com/nvm-sh/n... | bash

% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
0 0 0 0 0 0 0 0 --:--:-- 0:01:15 --:--:-- 0

error:
curl: (28) Failed to connect to raw.githubusercontent.com port 443 after 75288 ms: Operation timed out

CollapseExpand
 
ashiqbyldd profile image
ashiqbyldd
sofwaredev
  • Joined

can I get any documentation to manually install Rosetta 2 in order to run apps not built for Apple silicon.

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Fullstack JavaScript, Web3 with twenty years of web development experience.
  • Location
    Palm Bay, FL
  • Education
    FullSail University
  • Work
    Software Engineer at MetaMask
  • Joined

More fromEric Bishard

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp