How to install Java on CentOS 7

Share on Social Media

Discover how to install Java on CentOS 7 with this detailed guide. Follow our step-by-step instructions to set up Java Development Kit (JDK) and Runtime Environment (JRE) seamlessly. #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.

Recommended Training for You: Complete Java SE 8 Developer Bootcamp – OCA Prep Included

821986 7b38 5show?id=oLRJ54lcVEg&offerid=1628165.821986&bids=1628165

Java vs Python

Java and Python are two of the most popular programming languages, each with its own strengths and use cases. Here’s a comparison to help you understand the key differences and decide which might be better suited for your needs:

Java

1. Performance:

  • Java is a statically-typed language that compiles to bytecode, which runs on the Java Virtual Machine (JVM). This often results in faster execution times compared to interpreted languages.

2. Syntax:

  • Java has a more verbose and complex syntax, which requires defining data types and strict adherence to structure. This can lead to more robust and maintainable code, but also increases development time.

3. Platform Independence:

  • “Write Once, Run Anywhere” is Java’s promise, as the bytecode can be executed on any platform with a JVM. This makes Java a good choice for cross-platform applications.

4. Use Cases:

  • Enterprise applications, Android development, large-scale systems, and server-side applications.

5. Libraries and Frameworks:

  • Java has a vast ecosystem with mature libraries and frameworks like Spring, Hibernate, and Apache Struts.

6. Community and Support:

  • Java has a large, active community with extensive documentation and support available.

Python

1. Performance:

  • Python is an interpreted language, which can result in slower execution compared to compiled languages like Java. However, for many applications, the performance difference is negligible.

2. Syntax:

  • Python features a simple, clean, and readable syntax that emphasizes code readability and reduces the cost of program maintenance. It is dynamically typed, which means variable types are determined at runtime.

3. Platform Independence:

  • Python code is also cross-platform, but you may need to install Python interpreters on the target machines.

4. Use Cases:

  • Web development, data science, machine learning, scripting, automation, and rapid prototyping.

5. Libraries and Frameworks:

  • Python boasts a rich set of libraries and frameworks such as Django, Flask, TensorFlow, and Pandas, which accelerate development in various fields.

6. Community and Support:

  • Python has a vibrant community with comprehensive documentation, tutorials, and third-party modules.

Summary

  • Choose Java if you need high performance, robust type checking, and are developing large-scale enterprise applications or Android apps.
  • Choose Python if you value simplicity and readability, and are working on web development, data science, machine learning, or scripting tasks.

Both languages have strong communities and extensive libraries, making them powerful tools for a wide range of programming needs. The choice often comes down to the specific requirements of your project and personal or team familiarity with the language.

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.

If you are new to Linux and facing difficulty in working at Linux Bash prompt. We recommend that, you should read The Linux Command Line, 2nd Edition: A Complete Introduction by William Shotts.

Final Thoughts

Installing Java on CentOS 7 is a crucial step for running Java applications and developing Java programs. By following this guide, you should have a fully functional Java Development Kit (JDK) and Java Runtime Environment (JRE) set up on your system.

If you need further assistance or professional support with your Java installation or other technical tasks, feel free to check out my services on Fiverr. I offer expert solutions to meet your development needs.

Hire me on Fiverr for professional help and quality service.

Leave a Comment