Embrace Java applications on your desktop, and then run them on all desktops.
No matter what operating system you’re running, there are usually several ways to install applications. Sometimes you might find an app in the app store or install it using a package manager like DNF on Fedora or Brew on Mac, while other times you might download an executable or installer from a website. Because Java is the back end of so many popular applications, it’s good to know the different ways to install it. The good news is you have plenty to choose from, and this article covers all of them.
The bad news is that Java is too big, and I’m not just talking about file sizes. Java is an open source language and specification, which means that, theoretically, anyone can create an implementation of it. This means that before installing anything, you must determine which Java distribution to install.
Do I need a JVM, JRE or JDK?
Java is broadly divided into two download categories. The Java Virtual Machine (JVM) is a runtime component; It is the “engine” that enables Java applications to start and run on your computer. It is included in the Java Runtime Environment (JRE).
The Java Development Kit (JDK) is a Development Kit: you can think of it as a garage where repairmen can sit and tweak, fix, and improve. The JDK contains the Java runtime environment (JRE).
In terms of downloads, this means:
- If you are a user who wants to run Java applications, all you need is the JRE (including the JVM).
- If you’re a developer who wants to program in Java, you need the JDK (which includes the JRE library, which includes the JVM).
What is the difference between OpenJDK, IcedTea and OracleJDK?
When Sun Microsystems was acquired by Oracle, Java was a major part of the deal. Fortunately, Java is an open source technology, so if you’re not happy with the way Oracle is maintaining the project, there are other options. Oracle bundles proprietary components with Java downloads, while the OpenJDK project is completely open source.
The IcedTea project is essentially OpenJDK, but its goal is to make it easier for users to build and deploy OpenJDK using fully free and open source tools.
Alibaba also has a self-maintained Open JDK distribution called Dragonwell. From its official website: “Alibaba Dragonwell is a free, production-ready Open JDK release with long-term support, including performance enhancements and security fixes. … As the cornerstone of Java application, Alibaba Dragonwell supports all Java businesses in Alibaba economy. Alibaba Dragonwell is fully compliant with the Java SE standard…” )
Which Java should I install?
If you feel overwhelmed by these choices, the simple answer is that the Java implementation you should install should be the easiest one to install. When your application tells you that you need Java 12, but you only have Java 8 in your repository, you can install any implementation of Java 12 that can be found from reliable sources. On Linux, you can install several different versions of Java at once without interfering with each other.
If you are a developer who needs to choose which version to use, consider the components you need. If you choose the Oracle version, be aware that the package contains proprietary plug-ins and fonts that may affect how you distribute your application. It is safest to develop on IcedTea or OpenJDK.
Install OpenJDK from the repository?
Now that you know what to choose, you can use the package manager to search for OpenJDK or IcedTea and install the version you want. Some distributions use the keyword latest to indicate the latest version, which is usually required by the application you want to run. Depending on the package manager you use, you might even consider using grep to filter search results to include only the latest version. For example, on Fedora:
$ sudo dnf search openjdk | grep latest | cut -f1 -d':'
java-latest-openjdk-demo.x86_64
java-openjdk.i686
java-openjdk.x86_64
java-latest-openjdk-jmods.x86_64
java-latest-openjdk-src.x86_64
java-latest-openjdk.x86_64
[...]
Copy the code
Only if the application you’re trying to run insists that you use an older version of Java should you look at versions prior to latest.
Installing Java on Fedora ora similar system:
$ sudo dnf install java-latest-openjdk
Copy the code
If your distribution does not use the Latest tag, you can use other keywords, such as default. Here’s how to search for OpenJDK on Debian:
$ sudo apt search openjdk | less
default-jdk
Standard Java development kit
default-jre
Standard Java runtime
openjdk-11-jdk
OpenJDK development kit (JDK)
[...]
Copy the code
In this case, the default-JRE package is suitable for the user, while the default-JDK is suitable for the developer.
For example, to install JRE on Debian:
$ sudo apt install default-jre
Copy the code
Java is now installed.
You probably have a number of Java-related packages in your repository. To search for OpenJDK, look for the latest JRE or JVM if you are a user or the latest JDK if you are a developer.
Install Java from the Internet
If you can’t find a JRE or JDK in your repository, or if you can’t find one that meets your needs, you can download open source Java packages from the Internet. You can find OpenJDK downloads in tar form that need to be installed manually at Openjdk.java.net, or you can download Zulu community edition in tar form or its installable RPM or DEB packages from Azul.
Install Java from the TAR file
If you download the TAR file from Java.net or Azul, you must install it manually. This is often referred to as a “local” installation because you are not installing Java in a “global” location. You can select an appropriate location in the PATH.
If you don’t know what PATH contains, take a look to find out:
$ echo $PATH
/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/home/seth/bin
Copy the code
In this example PATH, the locations /usr/local/bin and /home/seth/bin are good choices. If you’re the only user on your computer, your own home directory makes a lot of sense. If you have many users on your computer, it is best to choose a generic location, such as /usr/local or /opt.
If you don’t have access to a system-level directory like /usr/local that requires sudo, you can create a local bin or Applications folder in your own home directory:
$ mkdir ~/bin
Copy the code
If it’s not in your PATH, add it to it:
$ echo PATH=$PATH:$HOME/bin > > ~/.bashrc $source ~/.bashrc
Copy the code
Finally, unzip the package to a directory of your choice.
$ tar --extract --file openjdk*linux-x64_bin.tar.gz --directory=$HOME/bin
Copy the code
Java is now installed.
Install Java from RPM or DEB
If you download an RPM or DEB file from Azul.com, you can install it using the package manager.
For Fedora, CentOS, and RHEL, download the RPM and use DNF to install.
$ sudo dnf install zulu*linux.x86_64.rpm
Copy the code
For Debian, Ubuntu, Pop_OS, and similar distributions, download the DEB package and install it using Apt:
$ sudo dpkg -i zulu*linux_amd64.deb
Copy the code
Java is now installed.
Install your Java version with Alternatives
Some applications are developed for a specific version of Java and cannot be used with any other version. It’s rare, but it does happen, and on Linux you can resolve this conflict using the local installation method (see the section “Installing Java from a TAR file” above) or using the Alternatives application.
The Alternatives command will find the applications installed on your Linux system and let you choose the version you want to use. Some distributions, such as Slackware, do not provide the Alternatives command, so you must use the local installation method. On Fedora, CentOS, and similar distributions, the command is Alternatives. On Debian, Ubuntu, and similar systems, the command is update-alternatives.
To get a list of available versions of applications currently installed on a Fedora system:
$ alternatives --list
Copy the code
On Debian, you must specify alternative applications:
$ update-alternatives --list java
Copy the code
Select which version you want the system to use as the default on Fedora:
$ sudo alternatives --config java
Copy the code
On the Debian:
$ sudo updates-alternatives --config java
Copy the code
You can change the default Java version as needed, depending on which application you want to run.
Running a Java application
Java applications are typically distributed as JAR files. Depending on how you install Java, your system may already be configured to run Java applications, which lets you just double click the application icon (or select it from the application menu) to run. If you must perform a native Java installation that is not integrated with the rest of the system, you can launch the Java application directly from the terminal:
$ java -jar ~/bin/example.jar &
Copy the code
Java is a good thing
Java is one of the few programming environments that puts cross-platform development first. There’s nothing more relaxing than asking if an application will run on your platform and finding out that the application was written in Java. It’s so simple that whether you’re a developer or a user, you can get rid of anxiety on any platform. Embrace Java applications on your desktop, and then run them on all desktops.
Via: opensource.com/article/19/…
By Seth Kenlon (lujun9972
This article is originally compiled by LCTT and released in Linux China