Skip to content

Instantly share code, notes, and snippets.

@xiaoyunyang
Last active July 11, 2023 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xiaoyunyang/3e79356f6547a791192187ae777ed839 to your computer and use it in GitHub Desktop.
Save xiaoyunyang/3e79356f6547a791192187ae777ed839 to your computer and use it in GitHub Desktop.
How to install and use `nvm` on a Mac

What is nvm?

nvm is a version manager for node.js which lets you easily switch between different node versions. You can define an .nvmrc file in your node project which enforces the node version standardization with your codebase collaborators.

Install NVM

Install

wget -qO- https://raw.githubusercontent.com/nvm-sh/nvm/v0.35.3/install.sh | bash

.bashrc

# make sure you have this code

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

.bash_profile

if [ -f ~/.bashrc ]; then
    source ~/.bashrc
fi

You have to exit the Terminal then open again for the change to take effect.

Use nvm

Create a .nvmrc file in the same directory as your package.json.

Run nvm use before you run npm install or yarn.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment