Skip to content


Use .nvmrc if present #192

merged 2 commits into from

5 participants


When you execute "nvm use" in a directory without specify a node version, if present a file .nvmrc that contain a node version, that version is used.

gpad@gpad-travel:~/workspace$ mkdir nvm_example
gpad@gpad-travel:~/workspace$ cd nvm_example/
gpad@gpad-travel:~/workspace/nvm_example$ echo "0.8.16" > .nvmrc
gpad@gpad-travel:~/workspace/nvm_example$ nvm use 0.6.3
Now using node v0.6.3
gpad@gpad-travel:~/workspace/nvm_example$ node -v
gpad@gpad-travel:~/workspace/nvm_example$ nvm use
Found .nvmrc files with version <0.8.16>
Now using node v0.8.16
gpad@gpad-travel:~/workspace/nvm_example$ node -v

@creationix creationix merged commit 0ec339e into creationix:master

When execute "nvm use" without the version its not loading the node version set on the .nvmrc file.

maumercado@Icio:[nodebeginner]$ nvm use
Found .nvmrc files with version <0.8.18>
Now using node

node is not loading, yet the $VERSION environment variable is there!


Hi maumercado, can you post the content of .nvmrc?


the content is simply:

created it as the example -> echo "0.8.16" > .nvmrc


I'm sorry, but it's a bug, I'm opening a n issue and creating a pull request


This is the pull request if you want


@gpad @creationix Is the use of 'function' here intentional?
I'm using nvm via Jenkins which uses /bin/sh by default, and it complains with "function not found" with this change.
The workaround I use is to change Jenkins to use /bin/bash as the shell of choice.

nvm used to work with /bin/sh, is it now a requirement to use a shell that supports 'function' keyword?


Good call. The script should probably have a #!/bin/sh directive at the top, and this function should be an sh function, not a bash function. can you open an issue or a PR about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jan 22, 2013
  1. @gpad
Commits on Jan 25, 2013
  1. @gpad

    read the .nvmrc if present

    gpad committed
This page is out of date. Refresh to see the latest.
Showing with 21 additions and 1 deletion.
  1. +21 −1
@@ -16,6 +16,14 @@ if [ ! -z "$(which unsetopt 2>/dev/null)" ]; then
unsetopt nomatch 2>/dev/null
+# Obtain nvm version from rc file
+function rc_nvm_version {
+ if [ -e .nvmrc ]; then
+ RC_VERSION=`cat .nvmrc | head -n 1`
+ echo "Found .nvmrc files with version <$RC_VERSION>"
+ fi
# Expand a version using the version cache
@@ -344,7 +352,19 @@ nvm()
"use" )
- if [ $# -ne 2 ]; then
+ if [ $# -eq 0 ]; then
+ nvm help
+ return
+ fi
+ if [ $# -eq 1 ]; then
+ rc_nvm_version
+ if [ ! -z $RC_VERSION ]; then
+ VERSION=`nvm_version $RC_VERSION`
+ fi
+ else
+ VERSION=`nvm_version $2`
+ fi
+ if [ -z $VERSION ]; then
nvm help
Something went wrong with that request. Please try again.