How To Work With Multiple Versions Of Java On Linux

How To Work With Multiple Versions Of Java On Linux

hackernoon.com hackernoon.com3 days ago in #Dev Love44

@BairesdevBairesDev Malcom Ridgers is a tech expert at BairesDev specializing in the software outsourcing industry. Java has been a developer staple for quite some time. In fact, Java is one of the most popular programming languages on the market. Part of the reason for that is Android. When Java was first created, it was done so with the network in mind. Java also had the backing of major players in the industry (such as Sun Microsystems and IBM).  But Java has stood the test of time, and will continue to do so for the foreseeable future. And as Java continues to remain relevant, developers will continue to depend on this “write once, run anywhere” language. That doesn’t mean Java isn’t without its issues. One such caveat is that multiple versions of the language are still in use. For example, although Java 11 is available, many programs still depend on Java 8. Why is this the case? Java 8 is a Long Term Support release, which means it’ll be supported until 2030. Java 11 is also an LTS release, which enjoys support until 2026. The latest version, Java 14 was released in March 2020 but it isn’t an LTS. So at the moment, there are three viable Java releases developers (and users) have to contend with.   For many developers (such as those who work with Java development services), how do you deal with multiple releases of Java? Let’s take a look at how this is done on Linux. Installing Java on Linux Let’s say you want to install both JDK (Java Developer Kit) 8 and 11 on Ubuntu Linux. You can easily do this from the command line.  Open a terminal window and install Java 8 with the command: sudo apt-get install openjdk-8-jre-headless -y Install Java 11 with the command: sudo apt-get install openjdk-11-jre-headless -y Choosing which Java to use The problem with this is that, when you install Java 11, it will cause your system to automatically default to Java 11. What happens when you need to switch back to using Java 8? Fortunately, there’s a tool that allows you to select your default. That tool is update-alternatives, and it allows you to configure a number of tools when you have multiple versions installed. In the case of Java, when you have both Java 8 and 11 installed, you would run the command: sudo update-alternatives –config java You will be presented with the available options (in this case Java 8 and 11). To select which you want to set as the option to use on your system, type the number associated with the version to be used (Figure 1), and hit Enter. Figure 1 Selecting between Java 8 and 11 on Ubuntu Linux. Anytime you need to switch Java versions, run that same command and select the version you want to use. How to set the JAVA_HOME environment variable A number of Java applications depend on the JAVA_HOME environment variable to set the location of the Java installation. To determine where is this location, you’d first have to re-run the update-alternatives command like so: sudo update-alternatives –config java The output of that command not only allows you to select the version of Java you want to use, but it also includes the path for that version. Take a look at the example above (in Figure 1).  » Read More

Like to keep reading?

This article first appeared on hackernoon.com. If you'd like to keep reading, follow the white rabbit.

View Full Article

Leave a Reply