Share on Social Media

In this configuration guide, you will learn, how to install Java on CentOS 7 or other Redhat base Linux distros. #centlinux #linux #java

What is Java? :

Java is a widely used, high-level, object-oriented programming language developed by Sun Microsystems (now owned by Oracle). It was first released in 1995 and has since become one of the most popular programming languages due to its platform independence, portability, and versatility. Here are some key characteristics and aspects of Java:

  1. Platform Independence: One of the most significant features of Java is its “Write Once, Run Anywhere” (WORA) capability. Java programs can run on any device that has a Java Virtual Machine (JVM) installed, irrespective of the underlying hardware and operating system.
  2. Object-Oriented: Java is an object-oriented programming (OOP) language, which means it revolves around the concept of objects. It encourages the organization of code into modular and reusable components, promoting better code structure and maintenance.
  3. Syntax: Java’s syntax is similar to C++ but has been designed to eliminate certain programming constructs that can lead to common programming errors. It also includes automatic memory management through garbage collection.
  4. Multi-threading: Java provides built-in support for multithreading, allowing concurrent execution of multiple threads within a single program. This facilitates the development of efficient and responsive applications.
  5. Rich Standard Library: Java comes with a comprehensive standard library that provides a wide range of classes and methods for various common programming tasks. This makes it easier for developers to implement functionality without having to write everything from scratch.
  6. Security: Java incorporates various security features to ensure the safe execution of programs, especially when running applets in web browsers. The JVM includes a security manager that controls access to system resources.
  7. Networking: Java includes extensive libraries for networking, making it well-suited for developing distributed applications. This has contributed to the widespread use of Java in building server-side applications, web services, and enterprise-level systems.
  8. Community and Ecosystem: Java has a large and active developer community, contributing to a vast ecosystem of libraries, frameworks, and tools. Popular frameworks like Spring, Hibernate, and Apache Struts are widely used in Java development.

Java is employed in a variety of applications, including web development, mobile app development (Android apps are primarily written in Java), enterprise systems, scientific and research applications, and more. Its versatility, performance, and robustness have contributed to its enduring popularity in the software development landscape.

In this article, we will install Java on CentOS 7 from RPM and from tarball.

Read Also: How to install Java on Rocky Linux 9

Install Java on CentOS 7 from RPM:

Connect to java-server.example.com using ssh as root user.

Download Java JDK 11 RPM for CentOS 7 from Oracle Technical Network (OTN) and copy it to the home directory of root user.

Install the downloaded package using rpm command.

# rpm -ivh jdk-11.0.1_linux-x64_bin.rpm
warning: jdk-11.0.1_linux-x64_bin.rpm: Header V3 RSA/SHA256 Signature, key ID ec551f03: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:jdk-11.0.1-2000:11.0.1-ga        ################################# [100%]

Set JAVA_HOME environment variable.

# echo "export JAVA_HOME=/usr/java/jdk-11.0.1" >> /etc/profile
# export JAVA_HOME=/usr/java/jdk-11.0.1

Verify installation of Java JDK 11 by executing java command.

# java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

Java JDK 11 has been installed from RPM Package on CentOS 7 server.

Install Java on CentOS 7 from TAR:

Connect to java-server.example.com using ssh as root user.

Download Java JDK 11 TAR for CentOS 7 from Oracle Technical Network (OTN) and copy it to the home directory of root user.

Extract downloaded tarball using tar command.

# mkdir /usr/java
# tar xf jdk-11.0.1_linux-x64_bin.tar.gz -C /usr/java/
# ls /usr/java/
jdk-11.0.1

Set JAVA_HOME environment variable.

# echo "export JAVA_HOME=/usr/java/jdk-11.0.1" >> /etc/profile
# export JAVA_HOME=/usr/java/jdk-11.0.1

Create the symbolic link for java using alternatives command.

# alternatives --install /usr/bin/java java /usr/java/jdk-11.0.1/bin/java 2
# alternatives --config java

There is 1 program that provides 'java'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk-11.0.1/bin/java

Enter to keep the current selection[+], or type selection number:

We have only one JDK/JRE installed on this server, therefore, press <ENTER> to keep the current selection.

Create the symbolic link for javac using alternatives command.

# alternatives --install /usr/bin/javac javac /usr/java/jdk-11.0.1/bin/javac 2
# alternatives --config javac

There is 1 program that provides 'javac'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk-11.0.1/bin/javac

Enter to keep the current selection[+], or type selection number:

Press <ENTER>.

Create the symbolic link for jar using alternatives command.

# alternatives --install /usr/bin/jar jar /usr/java/jdk-11.0.1/bin/jar 2
# alternatives --config jar

There is 1 program that provides 'jar'.

  Selection    Command
-----------------------------------------------
*+ 1           /usr/java/jdk-11.0.1/bin/jar

Enter to keep the current selection[+], or type selection number:

Press <ENTER>

Verify installation of Java JDK 11 by executing java command.

# java -version
java version "11.0.1" 2018-10-16 LTS
Java(TM) SE Runtime Environment 18.9 (build 11.0.1+13-LTS)
Java HotSpot(TM) 64-Bit Server VM 18.9 (build 11.0.1+13-LTS, mixed mode)

Java JDK 11 has been installed from TAR on CentOS 7 server.

Conclusion:

In this configuration guide, you have learned, how to install Java on CentOS 7 or other Redhat based Linux distros.

Leave a Reply

Your email address will not be published. Required fields are marked *