How to install Java on CentOS 7

Share on Social Media

Want to run Java applications on CentOS 7? Don’t miss out! Follow this simple guide to install Java and unlock powerful features for your development environment. Set it up today and stay ahead in the tech game! #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.
How to install Java on CentOS 7
How to install Java on CentOS 7

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.

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.

Recommended Training: Java Masterclass 2025: 130+ Hours of Expert Lessons from Tim Buchalka

533682 c10c 4
show?id=oLRJ54lcVEg&bids=1597309

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

Output:

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

Output:

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/

Output:

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

Output:

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

Output:

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

Output:

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

Output:

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.

Frequently Asked Questions (FAQs)

What is Java, and why do I need it on CentOS 7?
Java is a programming language and computing platform used to run many applications. You may need it to develop or run Java-based software on your CentOS 7 system.

Which version of Java should I install?
You can choose between OpenJDK (open-source) or Oracle Java (proprietary). For beginners, OpenJDK is recommended as it’s free and easy to install via CentOS repositories.

Do I need root access to install Java?
Yes, you need root (or sudo) privileges to install Java system-wide using package managers like yum or manually configuring it.

How do I check if Java is already installed?
Run java -version in the terminal. If Java is installed, it will show the version; otherwise, you’ll see a “command not found” error.

What should I do after installing Java?
Verify the installation with java -version and set the JAVA_HOME environment variable if needed for applications that require it.

Final Thoughts

Congratulations! You’ve successfully installed Java on CentOS 7, unlocking a world of development possibilities. Whether you’re running enterprise applications, developing web services, or experimenting with new projects, Java is now ready to power your system.

Don’t wait for outdated versions to hold you back—ensure you’re using the latest, most secure Java runtime for your needs. Take action now and enjoy a smoother, more efficient development experience. The tech world is moving fast—stay ahead!

Looking for a Linux server expert? I provide top-tier administration, performance tuning, and security solutions for your Linux systems. Explore my Fiverr profile for details!

Looking for something?

Leave a Reply