Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Install Java 16 in Rocky Linux and AlmaLinux - DesignLinux

Aug 02 2021
designlinux 0 Comments

Java is a cross-platform, object-oriented, and multipurpose programming language that is primarily used for creating mobile, web, and cloud applications. Additionally, you can use Java to create games, chatbots, enterprise applications, and a whole lot more.

To develop Java applications, you need to install an IDE (Integrated Development Environment). IntelliJ IDEA is a perfect example of an IDE that is designed specifically for the development of Java applications. However, you need to have Java installed beforehand. This can be provided by either the OpenJDK (Open Java Development Kit) or Oracle JDK (Oracle Development Kit).

[ You might also like: 27 Best IDEs for C/C++ Programming or Source Code Editors on Linux ]

OpenJDK is an open-source implementation of the Java SE. It’s a development environment that was initially created by Sun Microsystems and is currently sponsored and maintained by Oracle. OpenJDK constitutes the Java compiler, Java Runtime Environment (JRE), Java Virtual Machine (JVM), and Java class library.

At the time of writing this guide, the latest version of Java is Java 16, which is provided by OpenJDK 16. Join us as we examine how you can install Java 16 on Rocky Linux 8 (also works on AlmaLinux 8).

Installing Java (OpenJDK) in Rocky Linux

To get started, we need to confirm that Java is not yet installed by running the following command.

$ java --version

bash: java: command not found...

Next, we are going to download the OpenJDK 16 binary file which comes as a tarball file using the following curl command.

$ curl  -O https://download.java.net/java/GA/jdk16.0.2/d4a915d82b4c4fbb9bde534da945d746/7/GPL/openjdk-16.0.2_linux-x64_bin.tar.gz

Once the download is complete, extract the compressed binary file.

$ tar -xvf openjdk-16.0.2_linux-x64_bin.tar.gz

Then move the decompressed folder to the /opt directory as shown.

$ sudo mv jdk-16.0.2 /opt

Thereafter, set the environment variables as shown.

$ export JAVA_HOME=/opt/jdk-16.0.2
$ export PATH=$PATH:$JAVA_HOME/bin

Java is now installed. To confirm the version installed, run the following commands:

$ echo $JAVA_HOME
$ java --version
Check Java Version in Rocky Linux
Check Java Version in Rocky Linux

Testing Java (OpenJDK) in Rocky Linux

To test if Java was correctly installed and working, we will code a simple Java program that adds two integers as follows.

$ sudo vim Hello.java

Paste the following lines of code and save the file.

public class Hello {

    public static void main(String[] args) {
        // Adds two numbers
        int x = 45;
        int y = 100;
        int z = x + y;
        System.out.println("Hello, the sum of the two numbers is: " +z);
    }

}

Compile the Java code;

$ javac Hello.java

Then run the Java code

$ java Hello
Testing Java in Rocky Linux
Testing Java in Rocky Linux

Great, all seems fine. We have successfully installed OpenJDK 16 and tested it by compiling and running a simple Java program in Rocky Linux.

Related

Tags: AlmaLinux Tips, Rocky Linux Tips

How to Install MariaDB Server on Rocky Linux 8

Prev Post

7 Best Mail Transfer Agents (MTA’s) for Linux

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 530
  • 612,709

DesignLinux.com © All rights reserved

Go to mobile version