NVM is a version manager for NodeJS. NVM is used to switch the active version of Node that is being used by your terminal session. Since all of the Node based projects I work in all have their own version of node, NVM allows me to switch between versions quickly and easily.
Like most version managers, NVM has a list places it looks to determine which version of Node it should be using. Most of the projects I work on have a file called
.nvmrc in their root that specifies a node version. If you’d like to learn more about how NVM is used, check out it’s README. It’s full of examples and documentation.
It’s easier to use the zsh-nvm plugin in oh-my-zsh instead of installing NVM yourself. The ZSH plugin handles the instaliation, shell configuration, and updating of NVM for you. Instructions for installing this plugin can be found in the NVM README.
NVM can be configured to automatically switch Node versions when you
cd to a directory that has an
~/.nvmrc file (more info on how NVM uses
~/.nvmrc can be found here here). To configure this behavior, set the following environment variable before loading the zsh-nvm plugin in oh-my-zsh.
# ~/.zshrc export NVM_AUTO_USE=true plugins+=(zsh-nvm)
A word of warning.. Auto-switching is convenient, but in my experience it’s incredibly slow. Unless you’re having to run NVM manually to switch node versions all the time, I would avoid enabline auto switching. Waiting 1 to 3 seconds for the terminal to finshing changing directories can be a real annoyance.