DEV Community


nave vs nvm for node version management

goodevilgenius profile image Dan Jones ・3 min read

I recently discovered nave. I found it on npm's installation page.

It's a node version manager, which means that it allows you to install and use multiple versions of node on your machine.

It's similar to nvm, which I've been using for quite a while, and I imagine many of you have as well.

The main difference is that nvm generally requires you to modify your current shell. You have to modify your .bashrc file to ensure that it loads properly. nave doesn't require you to add anything to your shell. You just download the script and put it anywhere in your current $PATH and it's ready to use.

To use it, you do nave use <version>, and it opens a new shell with the path for <version> added to $PATH. When you're done, you just exit, and you're back to your regular shell without that node version.

If you'd like, nave can work more like nvm, and you can add it to your .bashrc and it can be used to modify your current shell, but it's not required.

nvm also has issues when used when $PREFIX is set. However nave creates a subshell which adds the node version you need to your $PATH. I've been unable to use nvm in Termux on my phone because of the issue with $PREFIX. Others have had issues using nvm on MacOS when also using brew for the same reason.

I installed nave on my desktop, and manually set a PREFIX in my shell, and nave still worked with no problems.

I've still been unable to use nave on my phone, because, due to the fact that Termux is based on Busybox, the precompiled binaries can't be used in Termux, so node must be compiled. Unfortunately, another dependency issue causes the compilation to fail, but I'm hopeful that issue can get resolved and I'll be able to use nave for node development on my phone.

Speaking of Busybox, nvm states that on Alpine Linux, which is based on Busybox, you have to specify nvm install -s version to tell it to compile from source, since, as I mentioned, the precompiled binaries won't work.

On my phone under Termux,nave automatically saw that it needed to download the source and compile, so I just did nave install latest and it fetched the source for the latest version and attempted to compile, while on my desktop, it fetched the binaries. So, nave seems a bit smarter than nvm in that regard.

However, with regards to Alpine, I did try to use nave under Alpine. I spun up an Alpine docker container. It took a while to install the necessary packages for it to work. I needed bash, curl, and perl-utils, and maybe a couple more. I also had to change my shell to bash. After that, I did nave install latest, thinking that it would download the source and compile, like it did under Termux. It didn't. It downloaded the binary. And after that, doing nave use latest opened a new shell, but node --version wouldn't work, because of the aforementioned reasons. nave doesn't provide a flag to force source install like nvm, so I had to run env NAVE_SRC_ONLY=1 nave install latest. I then had to install a few more packages so that compilation would work, like g++, make, linux-headers, and python(?). After (finally) compiling, it worked as expected.

However, it would be nice for it to detect that the precompiled binaries didn't actually work. This leads me to believe that it was something other than nave being smarter that it compiled on Android under Termux. It could just be that it just didn't realize that an aarch64 architecture is the same as arm64.

In any case, on the desktop in a traditional Linux distro, I'm finding nave really nice so far, and I'll be using it for a little while to see if I like it better than nvm.

P.S. Since I have both nvm and nave installed now, to avoid clashes, I modified my .bashrc so that it doesn't use nvm if I'm in a nave-launched subshell.

Here's my code:

# No point using two different node installers
if [[ -z "$NAVE" ]]; then
    export NVM_DIR="$HOME/.nvm"
    [ -s "$NVM_DIR/" ] && \. "$NVM_DIR/"  # This loads nvm
    [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"  # This loads nvm bash_completion
Enter fullscreen mode Exit fullscreen mode

Discussion (0)

Forem Open with the Forem app