Skip to content

Instantly share code, notes, and snippets.

@a2ron
Last active November 14, 2020 10:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save a2ron/c1ef8609ff1bca5f2687dd869f11061f to your computer and use it in GitHub Desktop.
Save a2ron/c1ef8609ff1bca5f2687dd869f11061f to your computer and use it in GitHub Desktop.
Load NVM on demand
export NVM_DIR="$HOME/.nvm"
# Default node version
alias node="$HOME/.nvm/versions/node/v8.11.1/bin/node"
# Function to load the original nvm and execute it
load_and_exec_nvm(){
unalias node
unalias nvm
echo "Loading 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
echo "Executing NVM..."
nvm $@
}
# Default nvm, the wrapper to load it and execute it
alias nvm="load_and_exec_nvm"
@a2ron
Copy link
Author

a2ron commented Jan 15, 2020

This snippet let you load NVM just when you need it, in order to save time and resources.
It also set a default node version, just in case.

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