Taming Your Java Environment

You may not be concerned with what version of Java or Node you are using to run your JavaScript on a regular basis. However, setting up a CI build that can run successfully and repeatedly over the years is a pretty crucial endeavor. Here are a few pointers to set up Java and Node properly in Linux.

Locking Down a Java Runtime

Your version of Linux will likely come with a version of Java (such as Java, Clojure, or even Kotlin) already installed, which will give you a Java Virtual Machine (JVM) to run your application. Though your app may be flexible enough to run on whatever modern-ish Java version at runtime, that may not hold true over time, due to the various libraries and dependencies you pick up over the lifetime of your application.

It’s natural to want to upgrade your Java environment as the world marches forward, but you’ll also want to ensure that your application will still work in an older Java environment. That may mean having multiple Java Development Kits (JDKs) and Java Runtime Environments (JREs) installed on your development machine.

You will likely use your operating system’s package manager to install other Javas, but choosing the right one is crucial to your workflow. In addition to verifying that your JAVA_HOME variable is set properly, you’ll also need to check that ‘java’ and ‘javac’ executables are pointing to the right binaries to run.

You could manage this all manually, but I strongly recommend you use a tool designed just for this purpose. Though ‘update-alternatives’ tool is one option, the ‘update-java-alternatives’ tool nicely coordinates them all. I recommend using ‘update-java-alternatives’ to install the various Java frameworks and switch between them.

Locking Down Node

Managing your Node version is a little easier, thanks to a couple of decent tools.

NVM – Node Version Manager

To install a new version of Node.js, (the latest is currently V.10), simply do the following: nvm install 10.
Use this to switch to Node 10: nvm use 10.
To list all of the versions of Node.js installed: nvm ls.

It is also easy to set a default Node version for any given project by creating a file .nvmrc in the root of your project/repository containing the string indicating which Node version to use.

N – Another Node Version Manager

Another alternative to manage multiple Node.js installations is called simply “N.” It has an even simpler API:

To install and/or switch to version 10: n 10
To list all installed versions on Node.js: n
Yep, that’s it!