Skip to content

Instantly share code, notes, and snippets.

@heikomat
Last active December 21, 2022 16:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save heikomat/da06c9e983ab56a12683ca8f076fe9c2 to your computer and use it in GitHub Desktop.
Save heikomat/da06c9e983ab56a12683ca8f076fe9c2 to your computer and use it in GitHub Desktop.
How to switch to fast-reuse for faster nvm loading

Install nvm-ng

  • If you use nvm via the zsh-plugin, disable it by removing nvm from the plugins of your ~/.zshrc
  • If you have nvm installed via the install-script from creationix, unistall it as described here
  • do a regular nvm-ng-install as described here

BE SURE TO NOT HAVE A PREFIX CONFIGURED IN NPM!!!

Setting a prefix changes the installation directory for global packages and is not supported by nvm.

if npm config get prefix is either not set, or a subpath of echo $NVM_DIR, then you're good to go. Otherwise run npm config delete prefix to unset your prefix.

Setup fast-reuse

In the file where nvm gets initialized (~/.zshrc or ~/.bashrc) add --fast-reuse to the line that reads

[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"

Initializing nvm should then look like this:

export NVM_DIR="$HOME/.nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" --fast-reuse # This loads nvm
[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment