Manage Multiple Versions of Node Using nvm
Content
- Content
- Resources:
- Enviroment:
- Installation Steps:
- Remove existing
node
inbrew
- Install
nvm
- Next, create a directory for NVM.
- Add the following to your
~/.zshrc
file (or~/.bash_profile
if you are using older macOS). - Now either quit and reopen your Terminal, or run the following command to reload your shell.
- Now you can install
Node.js
versions. - Reference:
- Tips and Tricks:
I used to be very resistant to having excessive packages installed on my machine. After too many incidences and difficulties with Node.js version controls, I decided to take a step back and try to manage multiple versions of Node.js using the very popular tool nvm
What’s being funny is, I am not alone. For example this man:
A friend’s suggestion to try NVM to easily switch between Node environments popped into my head. I’ll admit I was hesitant that I would fall into a serious rabbit hole and divert too much time away from my task at hand, but it turned out to be really simple so I thought I’d share it with you all.
Resources:
https://formulae.brew.sh/formula/nvm
Enviroment:
macOS Big Sur 11.3.1, Apple Silicon
Installation Steps:
Check if you have node running by node -v
if you see something like v12.16.1
then you have node installed and running.
Check if it is installed via Homebrew
brew list
if you see something like node
or node@14
then you have node installed and managed by Homebrew
. In an event you are running node
from a non-Homebrew source, the usggestion is to keep it intact and install nvm
to manage multiple versions of node. Otherwise you should remove node from brew
before install nvm
.
Remove existing node
in brew
In my case I had node@14
installed and I wanted to remove it.
brew uninstall --ignore-dependencies node@14 # if you see an error like no Cellar found then use following one
brew uninstall --force node@14
then cleanup the brew cache
brew cleanup -s node@14
or even clear all brew cache by
brew cleanup -s
and remove any dead symlinks
brew cleanup --prune-prefix
Install nvm
brew update
brew install nvm
Next, create a directory for NVM.
mkdir ~/.nvm
Add the following to your ~/.zshrc
file (or ~/.bash_profile
if you are using older macOS).
export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh
Now either quit and reopen your Terminal, or run the following command to reload your shell.
source ~/.zshrc
use source ~/.bash_profile
if you are using older macOS.
Verify that nvm
is working by running the following command.
echo $NVM_DIR
# /Users/ben/.nvm
and
nvm --version
# v0.39.1
Now you can install Node.js
versions.
- Node version availability:
nvm ls-remote
- Install a specific version:
nvm install 14
- Install latest version:
nvm install latest
- Install the latest LTS version:
nvm install --lts
- List installed versions:
nvm ls
- Switch to a specific version:
nvm use 14
- Set default version:
nvm alias default 14
Enjoy using nvm
!
Reference:
https://blog.jamesauble.com/install-nvm-on-mac-with-brew-adb921fb92cc
Tips and Tricks:
Q: Tab
key does not accept syntax suggestions or Github Copilot suggestions.
A: This happens with some markdown plugins including markdown-all-in-one
as conflicts with the Tab
key.
Solution: is to update your keybindings.json
as follwoing instruction (credit to this):
Howto: Ctrl+Shift+p
, then find Preferences: Open Keyboard Shortcuts (JSON)
) by adding the following:
[
{
"key": "tab",
"command": "markdown.extension.onTabKey",
"when": "editorTextFocus && !inlineSuggestionVisible && !editorReadonly && !editorTabMovesFocus && !hasOtherSuggestions && !hasSnippetCompletions && !inSnippetMode && !suggestWidgetVisible && editorLangId == 'markdown'"
},
{
"key": "tab",
"command": "-markdown.extension.onTabKey",
"when": "editorTextFocus && !editorReadonly && !editorTabMovesFocus && !hasOtherSuggestions && !hasSnippetCompletions && !inSnippetMode && !suggestWidgetVisible && editorLangId == 'markdown'"
}
]