Similar to nvm-sh but meant to be faster (on startup at least).
You shell must be zsh
The following commands also needed for operation:
curl
awk
tail
head
cut
sort
uniq
git clone https://github.com/Ajnasz/znvm $HOME/src/znvm
Edit you .zshrc and the following line to enable the plugin:
# enable znvm plugin
. $HOME/src/znvm/znvm.plugin.zsh
# enable autocompletion for znvm
fpath+=$HOME/src/znvm
# load default nodejs version
# but only if it's not set (for example it will be set if you use tmux)
# remove the if statement if you want to make sure the default version used in a new shell
if ! znvm current > /dev/null
then
znvm use default
fi
# load version defined in .nvmrc
znvm hookwdchange
cd $ZSH
git submodule add https://github.com/Ajnasz/znvm custom/plugins/znvm
Install in zgenom
Add zgenom load Ajnasz/znvm
in your .zshrc
with your other zgenom load
commands.
How to enable plugins in oh-my-zsh
# load default nodejs version
znvm use default
# load version defined in .nvmrc
znvm hookwdchange
The ZNVM_DIR
environment variable, default value is $HOME/.znvm
ZNVM_DIR="$HOME/.znvm"
The ZNVM_SEARCH_FILENAMES
environment variable is a list of filenames (separated by space) znvm will look for whenever it executes the chpwd
hook listener. Default value is .znvmrc .nvmrc Dockerfile
To disable Dockerfile read remove it from the list:
ZNVM_SEARCH_FILENAMES=".znvmrc .nvmrc"
To install the latest nodejs v12:
znvm install v12
To install nodejs v8.1.1
znvm install v8.1.1
znvm alias default v12
znvm use v12
Use a default version
znvm use default
Add the following line to the .zshrc
znvm hookwdchange
The hook will traverse directory structure upwards from the current directory looking for the files defined in $ZNVM_SEARCH_FILENAMES
every time you change directory.
That will add a hook, which executes every time you change directory. The hook listener will search .znvmrc
, .nvmrc
and Dockerfile
in the directory you entered to. If no file found, it will try to find it in the parent directory until it reaches the root directory.
When it searches in a Dockerfile
, it will try to extract the version number from FROM node:
line.