[ACCEPTED]-How to install Java SDK on CentOS?-centos

Accepted answer
Score: 167

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

$ yum search java | grep 'java-'

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

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


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

$ yum install java-1.7.0-openjdk*

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

Score: 34

@Sventeck, perfecto.

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

OpenJDK 2 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 1 packages try:

yum list "java-*-openjdk-devel"
Score: 18

yum install java-1.8.0

and then:

alternatives --config java

and check:

java -version


Score: 13

On centos 7, I just do

sudo yum install java-sdk

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

Score: 10

An alternative answer is,

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

than select one 1 from list and install that

for example,

sudo yum install java-1.7.0-openjdk.x86_64
Score: 6

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

Below steps 3 are for the installation of latest Java 2 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 1 with a sample java program

Score: 3

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

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

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

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

Score: 2

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

Downloading Java JDK on Linux via wget is shown license page instead

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

Then you can put the tarball 2 contents in the right place and add java 1 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
Score: 0

use the below commands to install oracle 20 java8 through terminal

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

Step 18 -2) Download oracle java 8 using the below 17 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 16 -3) Install the java8 using below command sudo 15 yum localinstall jdk-8u121-linux-x64.rpm Now 14 the JDK should be installed at /usr/java/jdk1.8.0_121 Step 13 -4) Remove the downloaded .rpm file to utilize 12 the space. rm jdk-8u121-linux-x64.rpm 11

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

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

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

Score: 0

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

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 1 works for you.

Score: 0

enter image description here

This is what I did:

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

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

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

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

Score: 0

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

sudo yum 2 install java-1.8.0-openjdk

to verify java 1 -version

More Related questions