What is Java?
Java is considered one of the most popular programming languages. Java is a typed object-oriented programming language developed by Sun Microsystems (and subsequently acquired by Oracle). Development is mainly performed by a community organized through the Java Community Process. The language and the main technologies that implements it are distributed under the GPL but the trademark rights are owned by Oracle Corporation. Code written in Java (using the JVM – Java Virtual Machine) is transformed into bytecode and due to this, programs can run on any system where the JVM is installed. Therefore, Java is often called a cross-platform language. Most often, Java is used to develop backend programs and android applications.
Java JDK and Java JRE
There are two packages needed to install Java, the Java JDK and Java JRE.
- Java JRE (Java Runtime Environment) – is necessary for running programs on computers and contains JVM, class libraries (Java Class Library), console commands. JRE is not enough for programming and creating programs. Install JRE only for programs that need to use Java in their projects.
- Java JDK (Java Development Kit) – is necessary for developers and it includes JRE, javac compiler and other tools necessary for development in Java. If you plan to use Java in development, you need to use this version of the package.
Java SE and Java EE.
There are 2 main classifications of Java platforms, Java SE and Java EE. These are defined below.
- Java SE – This is the Java Standard Edition. It is the main Java edition that contains the compiler, API, JRE and is suitable for creating custom applications, primarily for desktop systems.
- Java EE – This is the Java Enterprise Edition. It includes a set of specifications used mainly for creating enterprise-level software.
Currently, the latest version is Java 13, however, the most popular and widely used version is Java 8. In many circumstances, it is not always the best choice to use the latest versions in programming languages. The reason being because many times, there are functions that are introduced in later versions which do not always work well with older versions.
We will use OpenJDK as this software is a project created to be an open-source, fully compatible Java JDK consisting exclusively of free and open-source code. By installing this package we can use it for free, but other implementations of Java may require a paid option.
One other thing, if you are planning to use Java in a development environment, we would advise the use of SDKMAN. This is a command-line utility which allows us to install multiple versions of Java, and it handles the variable settings for us. It is convenient to use, but we will try to do accomplish the installation without it first, and then show the process using the help of SDKMAN.
Installation on Ubuntu 18
Let’s begin by installing Java OpenJDK 13 on Ubuntu 18.04. First, we need to check and see if we have Java installed using the following command.
root@host:~# java -version Command 'java' not found, but can be installed with: apt install default-jre apt install openjdk-11-jre-headless apt install openjdk-8-jre-headless root@host:~#
This indicates that Java is not currently installed.
Download Java SDK 13
Our next step includes downloading the Java SDK (or software developer kit). We will accomplish this by using the wget command.
root@host:~# wget https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_linux-x64_bin.tar.gz --2020-04-04 15:41:57-- https://download.java.net/java/GA/jdk13.0.2/d4173c853231432d94f001e99d882ca7/8/GPL/openjdk-13.0.2_linux-x64_bin.tar.gz Resolving download.java.net (download.java.net)... 220.127.116.11 Connecting to download.java.net (download.java.net)|18.104.22.168|:443... connected. HTTP request sent, awaiting response... 200 OK Length: 195812001 (187M) [application/x-gzip] Saving to: 'openjdk-13.0.2_linux-x64_bin.tar.gz' openjdk-13.0.2_linu 100%[==================>] 186,74M 2,34MB/s in 72s 2020-04-04 15:43:10 (2,58 MB/s) - 'openjdk-13.0.2_linux-x64_bin.tar.gz' saved [195812001/195812001] root@host:~#
Next, we will create a working directory where Java will reside, change directories into that folder, copy the downloaded file into that directory, and finally, extract the tar.gz file into its directory.
root@host:~# mkdir /usr/java root@host:~# root@host:~# cd /usr/java root@host:/usr/java# root@host:/usr/java# cp /root/openjdk-13.0.2_linux-x64_bin.tar.gz openjdk-13.0.2_linux-x64_bin.tar.gz root@host:/usr/java# root@host:/usr/java# sudo tar -xzvf openjdk-13.0.2_linux-x64_bin.tar.gz ... root@host:/usr/java#
Set Environment Variables
The Set Environment Variables step is necessary because when using Java, Ubuntu needs to know where the program is located to run it from, and which Java version to use by default. To modify this, we will use the nano text editor. First, open the file in Nano.
root@host:/usr/java# nano /etc/profile root@host:/usr/java#
Next, scroll to the bottom of the file and paste this information.
# Java 13 JAVA_HOME=/usr/java/jdk-13.0.2 PATH=$PATH:$HOME/bin:$JAVA_HOME/bin export JAVA_HOME export JRE_HOME export PATH
Finally, we press ctrl + O + Y + Enter then ctrl + X + Enter to save and close the file.
Finishing the Configuration Setup
Our last step involves updating the information in our system to point the new program and its options. In this case, we update the information regarding the Java installation.
root@host:/usr/java# update-alternatives --install "/usr/bin/java" "java" "/usr/java/jdk-13.0.2/bin/java" 1 update-alternatives: using /usr/java/jdk-13.0.2/bin/java to provide /usr/bin/java (java) in auto mode root@host:/usr/java# root@host:/usr/java# update-alternatives --config java There is only one alternative in link group java (providing /usr/bin/java): /usr/java/jdk-13.0.2/bin/java Nothing to configure. root@host:/usr/java# root@host:/usr/java# update-alternatives --config javac There is only one alternative in link group javac (providing /usr/bin/javac): /usr/java/jdk-13.0.2/bin/javac Nothing to configure. root@host:/usr/java#
As a final verification, we can check the installation and the version using the following command.
root@host:/usr/java# java -version openjdk version "13.0.2" 2020-01-14 OpenJDK Runtime Environment (build 13.0.2+8) OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing) root@host:/usr/java#
Installation on Windows 10.
In order to install the Windows version of Java, we need to visit the official Java website and download the Windows executable. Once at the site, the licensing options are outlined in green. It states “The new Oracle Technology Network License Agreement for Oracle Java SE is substantially different from prior Oracle JDK licenses. The new license permits certain uses, such as personal use and development use, at no cost — but other uses authorized under prior Oracle JDK licenses may no longer be available. Please review the terms carefully before downloading and using this product. An FAQ is also available.
Commercial license and support is available with a low cost Java SE Subscription.” We will scroll down to see the available downloads.
We will be downloading the jdk-13.0.2_windows-x64_bin.exe version.
After we click on the selected version, we must accept the user agreement.
Once the download completes, run the executable.
Click next and agree with the selected folders by default. Click Close when complete.
Setup Environment Variables
JAVA_HOME is a variable that points to the directory in which Java is installed. Programs use it to determine where Java is located.
Click on the keyboard combination Win+R, the Run window will pop up, and we then enter the command control / name Microsoft.system.
Next, select Advanced system settings
Now, click on Environment Variables.
Now, choose Path, and then click on New.
Enter the name: JAVA_HOME. Next, specify the path. If you selected the default path, you will see the path C:\Program Files\Java\jdk-13.0.2
Next, select PATH edit.
Then, we click New and enter the following.
And click OK in all open windows.
Now, to verify everything, we will open the run console with the Windows+r command and enter cmd and then press enter.
Now, we will enter the following command to check if everything works as expected.
C:\Users\User>echo %JAVA_HOME% C:\Program Files\Java\jdk-13.0.2 C:\Users\User>
Next, we will check the Java version using the following command.
C:\Users\User>java -version java version "13.0.2" 2020-01-14 Java(TM) SE Runtime Environment (build 13.0.2+8) Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing) C:\Users\User>
Excellent! Let’s move on.
Installation on MacOS
There are several options on how to do it. We can do the same way as we did in Ubuntu or Windows. Since we are installing the JDK version for developers, and in the future we will need to be able to install some programs, we will install through the console. We launch the console. If you do not know how to enter the terminal, open the directory below, then in Applications -> Utilities -> Terminal.
For macOS we will use the SDKMAN utility, it is often used when you need to install several versions and configure it, SDKMAN does everything by itself. Conveniently, this installation can be used on macOS and Ubuntu.
Add SDKMAN Repository
In the initial step, we will install the SDKMAN repository.
curl -s "https://get.sdkman.io" | bash user-iMac:~ user$ curl -s "https://get.sdkman.io" | bash Now attempting installation... Looking for a previous installation of SDKMAN... Looking for unzip... Looking for zip... Looking for curl... Looking for sed... Installing SDKMAN scripts... Create distribution directories... Getting available candidates... Prime the config file... Download script archive... #####################################################100.0% Extract script archive... Install scripts... Set version to 5.7.4+362 ... Attempt update of login bash profile on OSX... Added sdkman init snippet to /Users/ellen/.bash_profile Attempt update of zsh profile... Updated existing /Users/ellen/.zshrc All done! Please open a new terminal, or run the following in the existing one: source "/Users/ellen/.sdkman/bin/sdkman-init.sh" Then issue the following command: sdk help Enjoy!!! user-iMac:~ user$
Set Environment Variable
Next, we will set the environment variable.
user-iMac:~ user$ source "$HOME/.sdkman/bin/sdkman-init.sh" user-iMac:~ user$
Now, we can check to ensure SDKMAN is installed.
user-iMac:~ user$ sdk version SDKMAN 5.7.4+362 user-iMac:~ user$
Now, we can review a list of Java versions.
user-iMac:~ user$ sdk list java =========================================================== Available Java Versions =========================================================== Vendor | Use | Version | Dist | Status | Identifier ----------------------------------------------------------- AdoptOpenJDK | | 14.0.0.j9 | adpt | 14.0.0.j9-adpt | | 14.0.0.hs | adpt | 14.0.0.hs-adpt | | 13.0.2.j9 | adpt | Use the Identifier for installation: $ sdk install java 11.0.3.hs-adpt =========================================================== user-iMac:~ user$
Install JDK 13
Next, we will select the version JDK 13 and install it.
user-iMac:~ user$ sdk install java 13.0.2-open Downloading: java 13.0.2-open In progress... ##############################################################100.0% Repackaging Java 13.0.2-open... Done repackaging... Cleaning up residual files... Installing: java 13.0.2-open Done installing! Setting java 13.0.2-open as default. user-iMac:~ user$
Now we can set the default Java version to use.
user-iMac:~ user$ sdk default java 13.0.2-open Default java version set to 13.0.2-open user-iMac:~ user$
Lastly, we can check the version of Java using the following command.
user-iMac:~ user$ java -version openjdk version "13.0.2" 2020-01-14 OpenJDK Runtime Environment (build 13.0.2+8) OpenJDK 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing) user-iMac:~ user$
And that’s it! We installed Java on macOS.
In this tutorial, we learned what Java is, which versions are available to install on multiple platforms. Finally, we learned how to install, configure and run Java on Ubuntu, Windows and MacOS.
Want to Join an Elite Group of Experts? Find Out if You’re Eligible!
Give us a call at 800.580.4985, or open a chat or ticket with us to speak with one of our knowledgeable Solutions or Experienced Hosting advisors to learn how you can take advantage of this technology today!