diff --git a/src/nvm.go b/src/nvm.go index 08c2cdf..2a4cd9f 100644 --- a/src/nvm.go +++ b/src/nvm.go @@ -384,7 +384,15 @@ func findLatestSubVersion(version string) string { } func use(version string, cpuarch string) { - if version == "32" || version == "64" { + if version == "latest" { + installed := node.GetInstalled(env.root) + if len(installed) == 0 { + fmt.Println("No versions of node.js found. Try installing the latest by typing nvm install latest") + return + } + + version = installed[0] + } else if version == "32" || version == "64" { cpuarch = version v, _ := node.GetCurrentVersion() version = v @@ -603,7 +611,7 @@ func help() { fmt.Println(" nvm npm_mirror [url] : Set the npm mirror. Defaults to https://github.com/npm/cli/archive/. Leave [url] blank to default url.") fmt.Println(" nvm uninstall : The version must be a specific version.") // fmt.Println(" nvm update : Automatically update nvm to the latest version.") - fmt.Println(" nvm use [version] [arch] : Switch to use the specified version. Optionally specify 32/64bit architecture.") + fmt.Println(" nvm use [version] [arch] : Switch to use the specified version or use \"latest\" to switch to the latest installed version. Optionally specify 32/64bit architecture.") fmt.Println(" nvm use will continue using the selected version, but switch to 32/64 bit mode.") fmt.Println(" nvm root [path] : Set the directory where nvm should store different versions of node.js.") fmt.Println(" If is not set, the current root will be displayed.")