In ruby when using rbenv you can make a
You can do this with a combination of NVM, dotfiles in your project directory, and a little tool called
direnv which allows you to load in environment variables on a per-directory basis.
Install NVM and direnv, and then
cd to the directory you want to change Node versions in.
Add a file called
.nvmrc in that directory, containing just the version number of the Node version you want to auto-switch to, e.g.,:
Then add an environment configuration file called
.envrc to your directory, containing this script:
nvmrc=~/.nvm/nvm.sh if [ -e $nvmrc ]; then source $nvmrc nvm use fi PATH_add node_modules/.bin
If you now
cd out of this directory, and then
cd back in, direnv will kick in and you should be asked to add the directory to your direnv whitelist by typing
direnv allow . at the prompt. Once whitelisted, direnv will auto-run that script whenever you enter this directory, setting your Node version to the version number in
As a bonus, it will also add the
node_modules directory to your PATH, so you can execute binaries from those directories without prepending the