Tags: Node.JS
Those of us wanting to keep up with the latest Node.js version, or to test our code on alternative Node.js versions, probably have installed nvm. It is an easy-to-use tool for quickly installing the latest Node.js version, or to easily switch between Node.js versions to test our code. But nvm doesn't fit all use cases, and that's where nave comes in. Its purpose is extremely similar to nvm, but it satisfies a slightly different set of use cases that one may find interesting.
NAVE project: https://github.com/isaacs/nave
There are two documented methods to install NAVE:
npm install -g nave
basher install isaacs/nave
Since I have the heebie-jeebies about installing npm packages globally, I went the second route. And, I knew nothing about Basher and installed it: How to install Basher, the shell script package manager for Linux, Mac OS X, etc -- Bottom like is that Basher is a package management system for BASH scripts.
With Basher installed:
$ basher install isaacs/nave
Cloning into '/Users/david/.basher/cellar/packages/isaacs/nave'...
remote: Enumerating objects: 135, done.
remote: Counting objects: 100% (135/135), done.
remote: Compressing objects: 100% (109/109), done.
remote: Total 135 (delta 2), reused 89 (delta 0), pack-reused 0
Receiving objects: 100% (135/135), 127.93 MiB | 1.36 MiB/s, done.
Resolving deltas: 100% (2/2), done.
Checking out files: 100% (115/115), done.
But the instructions does not result in an an executable thing.
$ nave ls
-bash: nave: command not found
What we find is that the command is here:
$ ls /Users/david/.basher/cellar/packages/isaacs/nave/bin
nave
One way to proceed is to add $HOME/.basher/cellar/packages/isaacs/nave/bin
to your PATH variable. However I have the directory ~/bin
already present in my PATH variable, and did this instead:
$ ln -s /Users/david/.basher/cellar/packages/isaacs/nave/bin/nave ~/bin/nave
After that the help text prints as expected:
$ nave
Usage: nave <cmd>
Commands:
install <version> Install the version passed (ex: 0.1.103)
use <version> Enter a subshell where <version> is being used
use <ver> <program> Enter a subshell, and run "<program>", then exit
use <name> <ver> Create a named env, using the specified version.
If the name already exists, but the version differs,
then it will update the link.
usemain <version> Install in /usr/local/bin (ie, use as your main nodejs)
clean <version> Delete the source code for <version>
uninstall <version> Delete the install for <version>
ls List versions currently installed
ls-remote List remote node versions
ls-all List remote and local node versions
latest Show the most recent dist version
cache Clear or view the cache
help Output help information
auto Find a .naverc and then be in that env
auto <dir> cd into <dir>, then find a .naverc, and be in that env
auto <dir> <cmd> cd into <dir>, then find a .naverc, and run a command
in that env
exit Unset all the NAVE environs (use with 'exec')
Version Strings:
Any command that calls for a version can be provided any of the
following "version-ish" identifies:
- x.y.z A specific SemVer tuple
- x.y Major and minor version number
- x Just a major version number
- lts The most recent LTS (long-term support) node version
- lts/<name> The latest in a named LTS set. (argon, boron, etc.)
- lts/* Same as just "lts"
- latest The most recent (non-LTS) version
- stable Backwards-compatible alias for "lts".
To exit a nave subshell, type 'exit' or press ^D.
To run nave *without* a subshell, do 'exec nave use <version>'.
To clear the settings from a nave env, use 'exec nave exit'
Kicking the tires of NAVE as an experienced NVM user
With this command we can see the total list of Node.js versions that can be installed using NAVE:
$ nave ls-remote
It's a long list which I didn't want to put here. To install the latest:
$ nave install 12
############################################ 100.0%
$ nave ls
src:
installed:
12.7.0
named:
This doesn't make that Node.js version immediately available. Instead you do this:
$ node --version
v4.9.1
$ nave use 12
bash-3.2$ node --version
v12.7.0
bash-3.2$ which node
/Users/david/.nave/installed/12.7.0/bin/node
bash-3.2$ exit
$ which node
/Users/david/.nvm/versions/node/v4.9.1/bin/node
What's happening is that - first, NAVE recognizes "12" as a shortcut for the latest version of 12.x, just as NVM does. Second, when you say use Node.js release X.Y it starts a sub-shell with the PATH setup for that release.
This is unlike NVM which modifies the variables in the current shell to point to the desired Node.js release.
As the NAVE help text explains, to exit from the subshell use Control-D or the exit
command in the shell.
Creating a named version
Wo you like using version numbers? It's possible to avoid that as so:
$ nave use foo
What version of node?
lts, lts/<name>, latest, x.y, or x.y.z > lts/argon
Creating new env named 'foo' using node 4.9.1
bash-3.2$
bash-3.2$ node --version
v4.9.1
$ nave ls
src:
installed:
4.9.1 12.7.0
named:
foo: 4.9.1
For some reason lts/argon
mapped to Node.js v4.9.1. To completely uninstall both foo
and 4.9.1
I had to do this:
$ nave uninstall foo
$ nave ls
src:
installed:
4.9.1 12.7.0
named:
$ nave uninstall 4.9.1
$ nave ls
src:
installed:
12.7.0
named:
Will I use NAVE over NVM?
I don't think so. After a few minutes of kicking the tires, I am not groking the value.