#capture
For installing nvm on zsh
https://github.com/lukechilds/zsh-nvm
git clone https://github.com/lukechilds/zsh-nvm ~/.oh-my-zsh/custom/plugins/zsh-nvm
then add this to the plugin list for zsh
plugins+=(zsh-nvm)
Then:
source ~/.zshrc
How To
List installed versions
nvm ls
nvm ls remote //for list of available versions to install
Switch between versions:
nvm use 13.6.0
Assign Alias
To name v18.14.0
nvm alias blog-version 18.14.0
nvm unalias blog-version
Find path of Node.js executable
nvm which 13.6.0
Node Versions on a Per-project basis
To assign an app to use a specific version of Node each time the project is opened, create an .nvmrc
file inside the project directory.
If you want to auto-switch to the preferred version upon cd
ing into the project directory in zsh, add this below the version number:
autoload -U add-zsh-hook
load-nvmrc() {
local node_version="$(nvm version)"
local nvmrc_path="$(nvm_find_nvmrc)"
if [ -n "$nvmrc_path" ]; then
local nvmrc_node_version=$(nvm version "$(cat "${nvmrc_path}")")
if [ "$nvmrc_node_version" = "N/A" ]; then
nvm install
elif [ "$nvmrc_node_version" != "$node_version" ]; then
nvm use
fi
elif [ "$node_version" != "$(nvm version default)" ]; then
echo "Reverting to nvm default version"
nvm use default
fi
}
add-zsh-hook chpwd load-nvmrc
load-nvmrc
https://stackoverflow.com/questions/57110542/how-to-write-a-nvmrc-file-which-automatically-change-node-version