Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Installing JDK on Linux: Two Different Approaches

Tech May 18 2

Installing JDK on Linux: Two Different Approaches

Environment with Internet Access

Using YUM to Install

  1. Search for Java-related packages
  • 1
yum -y list java*


Alternatively,

  • 1
yum search jdk


  1. Install the JDK package
  • 1
yum install java-1.8.0-openjdk.x86_64


  1. Verify the installation
  • 1
java -version


  1. The default installation path with YUM is: /usr/lib/jvm
  2. Configure JAVA_HOME in the system profile
  • 1
vi /etc/profile


Append the following lines at the end of the file:

  • 1
  • 2
  • 3
  • 4
  • 5
# Set Java environment variables
JAVA_HOME=/usr/lib/jvm/jre-1.6.0-openjdk.x86_64
PATH=$PATH:$JAVA_HOME/bin
CLASSPATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar
export JAVA_HOME CLASSPATH PATH


Apply the changes to the profile:

source /etc/profile (Ensure there is a space after 'source')

Environment Without Internet Access

Manual Installation via Download and Upload

  1. Visit the Oracle website to download the appropriate JDK version for Linux. For this example, we use jdk-8u261-linux-x64.tar.gz, although your downloaded file might vary in version number, as long as it ends with .tar.gz.
  2. Create a directory for Java installation

Create a new folder under /usr/local/:

  • 1
  • 2
mkdir /usr/local/java
cd /usr/local/java


Place the downloaded file jdk-8u261-linux-x64.tar.gz into the /usr/local/java/ directory.

  1. Extract the JDK archive
  • 1
tar -zxvf jdk-8u261-linux-x64.tar.gz


  1. Configure Environment Variables

Edit the profile file:

vi /etc/profile

Add the following configuration:

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
# Set Java environment variables
JAVA_HOME=/usr/local/java/jdk1.8.0_261        
JRE_HOME=/usr/local/java/jdk1.8.0_261/jre     
CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$JRE_HOME/lib
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
export JAVA_HOME JRE_HOME CLASS_PATH PATH


Ensure that JAVA_HOME and JRE_HOME match your actual installlation paths and JDK version.

Reload the configuration:

  • 1
source /etc/profile


  1. Validate Installation
  • 1
java -version


If the command returns the version information, then the JDK has been successfully installed.

Installing Apache Maven

  1. Go to the official Maven website and download the .tar.gz package. Upload it to your server.

  2. Extract the archive:

    tar -zxvf apache-maven-3.8.2-bin.tar.gz

  3. Update the profile to include Maven's bin directory.

  4. Modify the local repository loctaion. All Maven artifacts are stored here (/usr/local/apache-maven-3.6.3/ck). Navigate to the conf directory and edit settings.xml:

    Locate <localRepository> and add the following line: <localRepository>/usr/local/apache-maven-3.6.3/ck</localRepository>

    Find the <mirrors> section and add Alibaba's mirror configuration.

  5. Save the changes and exit the editor.

  6. Reload the updated profile:

    source /etc/profile

  7. Test Maven installation:

    mvn -v

This should display the Maven version if everything is configured correct.

Tags: Java

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.