How to install Java SDK on CentOS?

JavaSdkCentos

Java Problem Overview


I have CentOS 5, but I don't know the steps to install Java SDK on Linux.

Where to download the RPM file and what can I do next to fully install that?

Then I need to install Tomcat.

Or is there any ready-made package for all?

Java Solutions


Solution 1 - Java

The following command will return a list of all packages directly related to Java. They will be in the format of java-<version>.

$ yum search java | grep 'java-'

If there are no available packages, then you may need to download a new repository to search through. I suggest taking a look at Dag Wieers' repo. After downloading it, try the above command again.

You will see at least one version of Java packages available for download. Depending on when you read this, the lastest available version may be different.

java-1.7.0-openjdk.x86_64

The above package alone will only install JRE. To also install javac and JDK, the following command will do the trick:

$ yum install java-1.7.0-openjdk*

These packages will be installing (as well as their dependencies):

java-1.7.0-openjdk.x86_64
java-1.7.0-openjdk-accessibility.x86_64
java-1.7.0-openjdk-demo.x86_64
java-1.7.0-openjdk-devel.x86_64
java-1.7.0-openjdk-headless.x86_64
java-1.7.0-openjdk-javadoc.noarch
java-1.7.0-openjdk-src.x86_64

Solution 2 - Java

@Sventeck, perfecto.

redhat docs are always a great source - good tutorial that explains how to install JDK via yum and then setting the path can be found here (have fun!) - Install OpenJDK and set $JAVA_HOME path

OpenJDK 6:

yum install java-1.6.0-openjdk-devel

OpenJDK 7:

yum install java-1.7.0-openjdk-devel

To list all available java openjdk-devel packages try:

yum list "java-*-openjdk-devel"

Solution 3 - Java

yum install java-1.8.0

and then:

alternatives --config java

and check:

java -version

Solution 4 - Java

On centos 7, I just do

sudo yum install java-sdk

I assume you have most common repo already. Centos just finds the correct SDK with the -devel sufix.

Solution 5 - Java

An alternative answer is,

sudo yum list \*java-1\* | grep open 

than select one from list and install that

for example,

sudo yum install java-1.7.0-openjdk.x86_64

Solution 6 - Java

Here is a detailed information on setting up Java and its paths on CentOS6.

Below steps are for the installation of latest Java version 8:

  1. Download java rpm package from Oracle site. (jdk-8-linux-x64.rpm)
  2. Install from the rpm. (rpm -Uvh jdk-8-linux-x64.rpm)
  3. Open /etc/profile, and set the java paths, save it.
  4. Check the java installation path, and java version, with the commands: which java, java -version

Now you can test the installation with a sample java program

Solution 7 - Java

Since Oracle inserted some md5hash in their download links, one cannot automatically assemble a download link for command line.

So I tinkered some nasty bash command line to get the latest jdk download link, download it and directly install via rpm. For all who are interested:

> wget -q http://www.oracle.com/technetwork/java/javase/downloads/index.html -O ./index.html && grep -Eoi ']+>' index.html | grep -Eoi '/technetwork/java/javase/downloads/jdk8-downloads-[0-9]+.html' | (head -n 1) | awk '{print "http://www.oracle.com"$1}'; | xargs wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" -O index.html -q && grep -Eoi '"filepath":"[^"]+jdk-8u[0-9]+-linux-x64.rpm"' index.html | grep -Eoi 'http:[^"]+' | xargs wget --no-cookies --header "Cookie: gpw_e24=xxx; oraclelicense=accept-securebackup-cookie;" -q -O ./jdk8.rpm && sudo rpm -i ./jdk8.rpm

The bold part should be replaced by the package of your liking.

Solution 8 - Java

If you want the Oracle JDK and are willing not to use yum/rpm, see this answer here:

https://stackoverflow.com/questions/10268583/how-to-automate-download-and-installation-of-java-jdk-on-linux

As per that post, you can automate the download of the tarball using curl and specifying a cookie header.

Then you can put the tarball contents in the right place and add java to your PATH, for example:

curl -v -j -k -L -H "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-linux-x64.tar.gz > jdk.tar.gz

tar xzvf jdk.tar.gz
sudo mkdir /usr/local/java
sudo mv jdk1.8.0_45 /usr/local/java/
sudo ln -s /usr/local/java/jdk1.8.0_45 /usr/local/java/jdk

sudo vi /etc/profile.d/java.sh
export PATH="$PATH:/usr/local/java/jdk/bin"
export JAVA_HOME=/usr/local/java/jdk

source /etc/profile.d/java.sh

Solution 9 - Java

use the below commands to install oracle java8 through terminal

Step -1) Visit Oracle JDK download page, look for RPM version

Step -2) Download oracle java 8 using the below command wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u121-b13/e9e7ea248e2c4826b92b3f075a80e441/jdk-8u121-linux-x64.rpm

Step -3) Install the java8 using below command sudo yum localinstall jdk-8u121-linux-x64.rpm Now the JDK should be installed at /usr/java/jdk1.8.0_121 Step -4) Remove the downloaded .rpm file to utilize the space. rm jdk-8u121-linux-x64.rpm

Step -5) Verify the java by using command java -version

Step -6) If the CentOS has multiple JDK installed, you can use the alternatives command to set the default java sudo alternatives --config java

Step -7)Optional set JAVA_HOME Environment variables. copy the path of jdk install i.e /usr/java/jdk1.8.0_121 use below command to export java home export JAVA_HOME=/usr/java/jdk1.8.0_121 export PATH=$PATH:$JAVA_HOME

Solution 10 - Java

I have written a shell script to install/uninstall java on centos. You can get it done by just run the shell. The core of this shell is :

1.download the jdk rpm(RedHat Package Manager) package.
2.install java using rpm.

You can see more detail here: https://github.com/daikaixian/WaterShell/tree/master/program_installer

Hope it works for you.

Solution 11 - Java

enter image description here

This is what I did:

  1. First, I downloaded the .tar file for Java JDK and JRE from the Oracle site.

  2. Extract the .tar file into the opt folder.

  3. I faced an issue that despite setting my environment variables, JAVA_HOME and PATH for Java 9, it was still showing Java 8 as my runtime environment. Hence, I symlinked from the Java 9.0.4 directory to /user/bin using the ln command.

  4. I used java -version command to check which version of java is currently set as my default java runtime environment.

Solution 12 - Java

To install OpenJDK 8 JRE using yum with non root user, run this command:

> sudo yum install java-1.8.0-openjdk

to verify java -version

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJohnView Question on Stackoverflow
Solution 1 - JavaLou GrossiView Answer on Stackoverflow
Solution 2 - JavaxprosView Answer on Stackoverflow
Solution 3 - Javauser831217View Answer on Stackoverflow
Solution 4 - JavafangmobileView Answer on Stackoverflow
Solution 5 - JavaicebergView Answer on Stackoverflow
Solution 6 - Javashasi kanthView Answer on Stackoverflow
Solution 7 - JavaBenjenView Answer on Stackoverflow
Solution 8 - JavaAnthony HaywardView Answer on Stackoverflow
Solution 9 - JavaDilip DView Answer on Stackoverflow
Solution 10 - JavaDai KaixianView Answer on Stackoverflow
Solution 11 - JavaSangeeta GuptaView Answer on Stackoverflow
Solution 12 - Javamuhammad shahanView Answer on Stackoverflow