0% found this document useful (0 votes)
137 views

How To Install Java 8 On Centos/Rhel 7/6 and Fedora 28-23

CentOS Java
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
137 views

How To Install Java 8 On Centos/Rhel 7/6 and Fedora 28-23

CentOS Java
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

 HOME UBUNTU 16.04 FEEDBACK FUNNY TOOLS TUTORIALS

SUBMIT ARTICLE ABOUT US

How to Install JAVA  Search Now

8 on CentOS/RHEL
7/6 and Fedora
28-23
Written by Rahul K., Updated on August 30, 2018

 JAVA

 java, java 8, Java_home, jdk, jdk-jre, jre, jre_home, openjdk,


oracle java, sun java

POPULAR POSTS

How to Install Oracle


Java 11 on Ubuntu 18.04
LTS (Bionic)
This tutorial helps you to install Java 8 or update
How to Install Java 11 on
Java on your system. Read the instruction carefully
CentOS 7/6 & Fedora
before downloading Java from the Linux command 28-25
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

1 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

This Article. with ChromeDriver on


Debian 9/8

How to Install ownCloud


Step 1 – Download Latest Java 10 on Debian 9 (Stretch)

Archive How to Get Current Date


& Time in JavaScript
The Oracle team provides Java RPM packages as
well as compiled source code. Many times I have
tried Java installation using rpm packages but I
faced some issues. So I decided to install Java
using the compiled source code. Since then I have
installed a large number of times Java on CentOS,
Redhat based systems without any issues. To
download the latest Java SE Development Kit 8
release from its official download page or use
following commands to download from the shell.

# cd /opt/
# wget --no-cookies --no-check-certificate --header "Cookie: g
# tar xzf jdk-8u181-linux-x64.tar.gz

Step 2 – Install Java 8 with


Alternatives
The alternatives command is used for maintained
symbolic links. This command used to creates,
removes, maintains and displays information about
the symbolic links comprising the alternatives
system. Let’s use the alternatives command to
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

2 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

command is available in chkconfig package.

# cd /opt/jdk1.8.0_181/
# alternatives --install /usr/bin/java java /opt/jdk1.8.0_181/
# alternatives --config java

There are 3 programs which provide 'java'.

Selection Command
-----------------------------------------------
* 1 /opt/jdk1.7.0_71/bin/java
+ 2 /opt/jdk1.8.0_45/bin/java
3 /opt/jdk1.8.0_144/bin/java
4 /opt/jdk1.8.0_181/bin/java

Enter to keep the current selection[+], or type selection numb

At this point JAVA 8 has been successfully installed


on your system. We also recommend to setup javac
and jar commands path using alternatives

# alternatives --install /usr/bin/jar jar /opt/jdk1.8.0_181/bi


# alternatives --install /usr/bin/javac javac /opt/jdk1.8.0_18
# alternatives --set jar /opt/jdk1.8.0_181/bin/jar
# alternatives --set javac /opt/jdk1.8.0_181/bin/javac

Step 3 – Check Installed Java


Version
Java and javac binaries are available under PATH

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

3 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

version of Java runtime environment (JRE) on your


system by executing the following command.

# java -version

java version "1.8.0_181"


Java(TM) SE Runtime Environment (build 1.8.0_181-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.181-b11, mixed mod

Step 4 – Setup Java Environment


Variables
Most of Java based application’s uses environment
variables to work. Set the Java environment
variables using following commands

Set the JAVA_HOME, JRE_HOME and PATH


environment variables.

# export JAVA_HOME=/opt/jdk1.8.0_181
# export JRE_HOME=/opt/jdk1.8.0_181/jre
# export PATH=$PATH:/opt/jdk1.8.0_181/bin:/opt/jdk1.8.0_181/jr

Also add the above commands to /etc/bashrc file


to auto set environment variables on the system
boot.

SHARE IT!     

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

4 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

RAHUL K.   

I, Rahul Kumar am the founder and


chief editor of TecAdmin.net. I am a
Red Hat Certified Engineer (RHCE)
and working as an IT professional
since 2009..

RELATED POSTS

How to Install Oracle Java 11 on Ubuntu 16.04 LTS


(Xenial)
October 7, 2018

How to Install Java 11 on CentOS 7/6 & Fedora 28-25


September 30, 2018

How to Install Oracle Java 11 on Ubuntu 18.04 LTS


(Bionic)
September 30, 2018

How to Install Java on Debian 9 (Stretch)


September 22, 2018

How to Switch Between Multiple Java Versions on


Ubuntu 18.04 & 16.04
September 5, 2018

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

5 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

124 COMMENTS

SUMIT SAHAY  REPLY TO SUMIT

September 14, 2018 at 10:14 am


Hi Rahul,

I am trying to install jenkins on my centos vm instance but


unable to do so as its need java 8 and the java version in
my system is 1.7. Now, I am trying to update the java
version but due to proxy issue I am getting error so I
downloaded the java 8 couple of times “jre-8u181-linux-
x64.rpm” and whenever I am trying to execute this rpm
file, like below,
sudo yum install jre-8u181-linux-x64.rpm
But I am getting error like below,
Trying other mirror.
Error: Cannot retrieve repository metadata (repomd.xml)
for repository: local. Please verify its path and try again

Could you please navigate me to the correct direction.

Looking forward for your reply.

Regards
Sumit Sahay

RAHUL K.  REPLY TO RAHUL

September 14, 2018 at 10:16 am


Try below command:

sudo yum localinstall jre-8u181-linux-


x64.rpm

SANTIAGO ALAMOS  REPLY TO SANTIAGO

August 29, 2018 at 2:09 pm


Nice update !
Please fix this:
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

6 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

it should be 181 in both


LEAVE A REPLY

COMMENTS *

August 19, 2018 at 5:31 am


NAME * EMAIL * WEBSITE
Hi!
When i am trying to execute the below
command:
wget –no-cookies –no-check-certificate –header
“Cookie: gpw_e24=http%3A%2F
NOTIFY ME OF FOLLOW-UP COMMENTS BY EMAIL.
%2Fwww.oracle.com%2F; oraclelicense=accept-
securebackup-cookie”
“http://download.oracle.com/otn-pub/java
/jdk/8u171-
SUBMIT
/jdk-8u171-linux-x64.tar.gz”
It’s coming with 404 not found HTTP request, can
you help me, please?

ANOOP  REPLY TO ANOOP

August 7, 2018 at 11:55 pm


Very helpful and clearly documented. Thanks
Rahul

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

7 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

COLIN  REPLY TO COLIN

July 11, 2018 at 7:04 pm


I just wanted to add that this is very helpful for
anyone using SAP Hybris. The system and its
Apache Ant builder are very sensitive to Java
changes and build paths. Thank you for the
content.

SAIKIRAN  REPLY TO SAIKIRAN

July 10, 2018 at 6:23 pm


nice expalnation its worked for me

VAM  REPLY TO VAM

July 6, 2018 at 5:01 am


nice article
tq

MIKE  REPLY TO MIKE

June 21, 2018 at 12:38 pm


Works like a charm, thank you Rahul!

STEVEN  REPLY TO STEVEN

June 8, 2018 at 10:07 pm


Fantastic article, thank you!

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

8 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

SHAHAMA  REPLY TO SHAHAMA

April 12, 2018 at 5:17 am


I’m getting below error when I try java -version
command
-bash: /usr/bin/java: cannot execute binary file
Any Solutions?

RAHUL K.  REPLY TO RAHUL

April 13, 2018 at 6:23 am


Try:

chmod +x /opt/jdk1.8.0_161/bin/java

SHAHAMA  REPLY TO SHAHAMA

April 2, 2018 at 4:43 am


I need to upgrade my Oracle Java 1.7.0_79 to 1.8.
Is this above method will work? or is there any
other method?

RAHUL K.  REPLY TO RAHUL

April 2, 2018 at 6:39 am


Yes, it will work with Java upgrade also.

SHAHAMA
April 12,  REPLY TO SHAHAMA
2018 at 4:54 am
Thank you. It is working fine. This
article is very helpful. Keep on
Posting

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

9 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Thank you. It helps a lot and working.

NEERAJ SHARMA  REPLY TO NEERAJ

March 11, 2018 at 12:31 pm


Hi Rahul,

I’ve following you for quite some time and I really


appreciate your contribution. However I’ve never
been able to fathom how alternative command
works.

Will you please enlighten me.

ABHISHEK  REPLY TO ABHISHEK

February 22, 2018 at 6:36 am


Please for god’s sake remove the
/etc/environment update section…. that’s not
correct and it screws up the system

SRIPADA SARMA  REPLY TO SRIPADA


April 7, 2018 at 5:47 am
I followed it verbatim and later I saw
your comment. Now it is not working
and as good as not installed. The .sh file
is not running as exe program. Pl how to
undo /etc/bashrc.

NOOR  REPLY TO NOOR

February 7, 2018 at 8:13 am


I followed above steps but unfortunately i cannot
edit /etc/environment file now, due to change in
this file i am unable to run any command from

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

10 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

please help i can access files via ssh and winscp but with
no permission to edit.

VICTO  REPLY TO VICTO

February 24, 2018 at 4:08 pm


Reboot from dvd with rescue option,
then remove the lines in de environment
file.

NOOR KHAN  REPLY TO NOOR


March 20, 2018 at 10:33 am
really VICTO ? how to do this on
AWS linux instance? i am unable
to see such option on aws

ALEKSANDRK  REPLY TO ALEKSANDRK

February 1, 2018 at 8:30 am


Good tutorial. Thank you!

LUIS URZUA ARENAS  REPLY TO LUIS

January 31, 2018 at 6:23 pm


Thank you, very usefyll!

AMAR  REPLY TO AMAR

January 31, 2018 at 10:20 am


Thank you. saved lot of time

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

11 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

SD  REPLY TO SD

January 18, 2018 at 1:35 pm


Download Path incorrect

GIRI  REPLY TO GIRI

January 5, 2018 at 12:41 am


Even after following the instructions, the java
version on my Centos is still at 1.7. I can see the
folders for 1.8 are created but ‘java -version’ still
returns 1.7. Any reasons?

MADHUKAR REDDY
January 9, 2018  REPLY TO MADHUKAR
at 5:52 am
instructions messed up the root login
PATH

subsequent root login gives these errors


Last login: Tue Jan 9 00:45:24 2018 from
116.74.251.1
bash: tty: command not found…
Similar command is: ‘tty’
bash: ls: command not found…
Similar command is: ‘lz’
/usr/libexec/grepconf.sh: line 5: grep:
command not found
bash: grep: command not found…
bash: grep: command not found…
bash: uname: command not found…

MADHUKAR REDDY
January  REPLY TO MADHUKAR
9, 2018 at 6:08 am
Found the problem. Last
instruction to update
/etc/environment messing up
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

12 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

/etc/environment and it works fine.

For generic java 8 I would suggest the


following

cd /opt
ln -s /opt/jdk1.8.0_151 jdk1.8
export JAVA_HOME=/opt/jdk1.8
export JRE_HOME=/opt/jdk1.8/jre
export PATH=$PATH:/opt/jdk1.8/bin:/opt
/jdk1.8/jre/bin

NOOR  REPLY TO NOOR


February 7, 2018 at 8:10 am
I have same issue but
unfortunately i cannot edit
/etc/environment file now,
due to change in this file i
am unable to run any
command from my user
even i cannot run sudo,
sudo su or ls chown etc..
I am working on AWS Linux
instance.
please help i can access
files via ssh and winscp
but with no permission to
edit.

GIRI  REPLY TO GIRI

January 4, 2018 at 12:23 pm


After following the instructions, my java version is
still at 1.7. It has not changed to 1.8. Any
reasons?

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

13 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

GED  REPLY TO GED

December 18, 2017 at 9:01 pm


crap, it did not work

RAHUL K.  REPLY TO RAHUL

December 19, 2017 at 4:47 am


Hi Ged. What issue are you facing?

RESHMA  REPLY TO RESHMA

November 27, 2017 at 6:36 pm


This is really saved my time. Thanks!

SHAUN  REPLY TO SHAUN

November 9, 2017 at 11:37 pm


Please update step 1. to tar xzf jdk-8u151-linux-
x64.tar.gz. It still says tar xzf jdk-8u144-linux-
x64.tar.gz

RAHUL K.  REPLY TO RAHUL

November 10, 2017 at 3:19 am


Thanks, Shaun to point out… The tutorial
has been updated.

DANIEL  REPLY TO DANIEL

October 26, 2017 at 5:05 pm


Hi!

Apparently it’s going to work yes but i am having


a problem with this command:
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

14 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

%2Fwww.oracle.com%2F; oraclelicense=accept-
securebackup-cookie” “http://download.oracle.com/otn-
pub/java/jdk/8u152-
b01/090f390dda5b47b9b721c7dfaa008135/jdk-8u144-
linux-x64.tar.gz” Changed it to the last arquive (152)

It’s coming with 404 not found HTTP request, can you help
me, please?

DAVID  REPLY TO DAVID

October 14, 2017 at 10:09 pm


Thank you so much Tecadmin.net! I love this
post, THANK YOU!

CHETAN  REPLY TO CHETAN

September 1, 2017 at 10:16 am


Thank you for the tutorial it saves a lot of time
now.

BUGSDANNY  REPLY TO BUGSDANNY

August 23, 2017 at 1:43 pm


Thank you! amazing and usefull tutorial! just
what i need!.

SUMAN  REPLY TO SUMAN

August 7, 2017 at 6:06 am


Its was a great article for java config also had
clear approach to solve the install conflicts for
Jenkins installation. Thanks a lot I look forward for
your future articles.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

15 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Thank you very much for this rewarding article! It


was worth the try

JAYDEEP  REPLY TO JAYDEEP

July 18, 2017 at 3:00 pm


Hi,

I am not sure what I did wrong while installing


java 1.8
I have followed the same steps as mentioned but
when checking for JAVA version, it says 1.7.0.67
rather than 1.8.

[root@quickstart jdk1.8.0_131]# java -version


java version “1.7.0_67”
Java(TM) SE Runtime Environment (build
1.7.0_67-b01)
Java HotSpot(TM) 64-Bit Server VM (build 24.65-
b04, mixed mode)

DEEPAK A  REPLY TO DEEPAK

December 4, 2017 at 11:48 am


Hi Jaydeep,
Could you please let me know if you
could resolve this? I am stuck at this
point and don’t know how to proceed. I
believe this is the reason I am not able
to proceed with my SparkR set up too
and getting the below error:
————————————————–
> sc = sparkR.session(master=’local’)
Spark package found in SPARK_HOME:
/home/cloudera/.cache/spark/spark-
2.2.0-bin-hadoop2.7
Launching java with spark-submit
command /home/cloudera/.cache/spark
/spark-2.2.0-bin-hadoop2.7/bin/spark-
submit “–conf”
“spark.debug.maxToStringFields=100”
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

16 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

file:/tmp/RtmpvEvWZD
/backend_port2cd67996e589
Run with –help for usage help or –verbose for
debug output
Error in sparkR.sparkContext(master, appName,
sparkHome, sparkConfigMap, :
JVM is not ready after 10 seconds

ROBERTO MARQUEZ  REPLY TO ROBERTO

June 28, 2017 at 3:06 pm


Thanks, I needed a way to upgrade Java from the
server (command line).

MARC RAYGOZA  REPLY TO MARC

June 16, 2017 at 9:50 pm


Great article. Worked perfectly

EDUARDO FELIPE  REPLY TO EDUARDO

June 9, 2017 at 1:33 pm


Thank you, these were very especific and easy to
follow instructions.

RYANTO  REPLY TO RYANTO

May 23, 2017 at 3:30 am


Hello could you explain more specific on what
we’re doing on
“Also put all above environment variables in
/etc/environment file for auto loading on system
boot.” on the last step. /

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

17 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Hi Team,

After exporting the path, ls command and most of the


command is not working. Could you please help me on this.
I am so tired.

VERGI  REPLY TO VERGI

November 9, 2017 at 11:04 am


Did you solve your problem on this?

RAHUL K.  REPLY TO RAHUL

November 9, 2017 at 11:40 am


Hi Vergi,

Make sure you have included


$PATH: in command like

export PATH=$PATH:

AYOUB  REPLY TO AYOUB

April 21, 2017 at 5:44 pm


I don’t understand the Setup “Install Java with
Alternatives”???.?

YO!  REPLY TO YO!

April 19, 2017 at 11:54 am


Thanks man!

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

18 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

PAOLO  REPLY TO PAOLO

April 8, 2017 at 9:11 am


Thank you very much!

DAVID B.  REPLY TO DAVID

February 6, 2017 at 8:51 am


Used this to install it on 32 bit CEntos 6.5
successfully, great work!

MO CHI  REPLY TO MO

January 25, 2017 at 3:55 am


Thank you so much.

FHER  REPLY TO FHER

September 13, 2016 at 7:43 pm


Hi. From I run this commands:
echo “export JAVA_HOME=/opt/jdk1.8.0_51” >
/etc/profile.d/jre.sh
echo “export JRE_HOME=/opt/jdk1.8.0_51/jre” >>
/etc/profile.d/jre.sh
echo “export PATH=$PATH:/opt/jdk1.8.0_51
/bin:/opt/jdk1.8.0_51/jre/bin” >> /etc/profile.d
/jre.sh

I am getting this when I open the terminal

bash: $’\342\200\234export’:order not found


bash: $’\342\200\234export’: order not found
bash: $’\342\200\234export’: order not found
[evconsul8@localhost ~]$

How this could affects?


Thanks a lot

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

19 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

November 17, 2016 at 1:22 am


See if you have a JRE.SH on /etc/profile.d

I had this one and was point to a old


java version. Just deleted and is working
fine.

MAX PAVLOV  REPLY TO MAX

November 24, 2016 at 2:05 pm


1. Remove your jre.sh via rm
/etc/profile.d/jre.sh
2. Use these commands to correctly
export variables:

echo ‘export JAVA_HOME=”/opt


/jdk1.8.0_111″‘ >> /etc/profile.d/jre.sh
echo ‘export JRE_HOME=”/opt
/jdk1.8.0_111″‘ >> /etc/profile.d/jre.sh
echo ‘export PATH=”$PATH:/opt
/jdk1.8.0_111/bin:/opt/jdk1.8.0_111
/jre/bin”’ >> /etc/profile.d/jre.sh

Reboot the machine and you’ll be fine.

FHERPIE  REPLY TO FHERPIE

September 13, 2016 at 7:40 pm


Hi. From I run this commands:
echo “export JAVA_HOME=/opt/jdk1.8.0_51” >
/etc/profile.d/jre.sh
echo “export JRE_HOME=/opt/jdk1.8.0_51/jre” >>
/etc/profile.d/jre.sh
echo “export PATH=$PATH:/opt/jdk1.8.0_51
/bin:/opt/jdk1.8.0_51/jre/bin” >> /etc/profile.d
/jre.sh

I am getting this when I open the terminal

bash: $’\342\200\234export’:order not found


This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

20 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

How this could affects?


Thanks a lot

AMIR BAHMANYARI  REPLY TO AMIR

August 11, 2016 at 11:27 pm


Works perfectly as is. Put your env. vars in
$HOME/.bashrc (if bash is the preferred shell).
And you are all set.

JUAN CARLOS PAZ H  REPLY TO JUAN

July 21, 2016 at 3:31 am


Thanks , Seguí estos pasos en un sistema
operativo oracle Linux y todo fue correcto
muchas gracias me ahorro mucho tiempo

HAYAM  REPLY TO HAYAM

July 6, 2016 at 2:39 pm


Hi, this is an amazing post, and I benefited a lot !
But I met a problem. After installing, i checked
the version and it was successful. However, I
wanted to use the java 1.8 on system boot, and
as you suggested I put the last three commands
in the “/etc/environment” file. However, after I
did that, my machine is not starting (my machine
is a CentOS machine created with Cloudera
training vm with help of virtualbox), and giving
the following error:

Starting jexec servicesDevice, “eth0” does not


exist

Do you know what is wrong ? Can you please


reply ? Thanks !

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

21 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Could any one advise on how to sort out the


envionment paths properly on Centos 7? Putting
them as written in the article in /etc/environment
messes up the path meaning normal commands
are missing from /bin/.

ANDRE  REPLY TO ANDRE

August 14, 2016 at 6:12 pm


Yes I also have this issue.

ANNA  REPLY TO ANNA

June 29, 2016 at 3:34 pm


Thank you. This article was really helpful.

One difference: setting the variables in


/etc/environment file almost disabled the bash
shell on my CentOS 7. So I defined them in
/etc/profile.d/custom.sh, it works.

It was the line with “$PATH” that had spoiled


/etc/environment.
I used a command “/bin/sudo mc” to edit
/etc/environment again and fix the problem.

JEREMY  REPLY TO JEREMY

June 27, 2016 at 2:57 pm


Thanks for the awesome instructions! I ran into
one issue that someone else may have already
mentioned, but I did not see it. On ubuntu
Alternatives has been replaced with update-
alternatives. hope that saves someone a minute
or two.

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

22 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Thanks

PKPDEVELOPER  REPLY TO PKPDEVELOPER


June 19, 2016 at 7:58 am
Thanks Great Tutorial.Perfect

ASHOK  REPLY TO ASHOK

June 13, 2016 at 12:22 pm


This is a very good article. Concise and proper
steps to setup java on any Linux box. Make a
shell script with all the above commands and run
it every-time you need to setup java

KEVIN EMERY  REPLY TO KEVIN

March 4, 2016 at 5:40 am


This was rather useful, thank you

J  REPLY TO J

February 23, 2016 at 12:19 am


I removed the step of setting environment file
which was empty on my machine, because
adding those lines to environment file caused
serious problem (path lost).

SRIRAM  REPLY TO SRIRAM

January 19, 2016 at 7:38 am


Helped me in setting up on linode VPS when all
other tutorials failes. Simple, hats off rahul

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

23 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

January 1, 2016 at 8:04 am


Excellent nicely explained the steps. thanks.

ADEMIAN  REPLY TO ADEMIAN

December 21, 2015 at 10:17 pm


Now, you have to change: download.oracle.com
by edelivery.oracle.com

RAHUL  REPLY TO RAHUL

December 23, 2015 at 6:58 am


Hi Ademian,

Yes edelivery.oracle.com is also working


but it still redirecting (302) to
download.oracle.com.

ASHUTOSH  REPLY TO ASHUTOSH

November 4, 2015 at 1:57 pm


I tried on ubuntu 14 and it worked.
only deviation”
I wrote
export JAVA_HOME=/opt/jdk1.8.0_66
export JRE_HOME=$JAVA_HOME/jre
export
PATH=$PATH:$JAVA_HOME/bin:$JRE_HOME/bin
into ~/.profile

CHRIS  REPLY TO CHRIS

August 26, 2015 at 4:52 pm


Install is the easy part, but can anyone note the
reason why you can no longer perform a “yum
update jdk” with version 1.8. I have noticed that

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

24 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Where 1.7 was formatted like so: jdk-1.7.0_80

Version 1.8 is now formatted like this: jdk1.8.0_60

This does not allow for a yum update in CentOS or Red Hat.

Thanks for any leads on this. It’s a real pain to manually


update. Though I see a benefit in that you would not “yank
out” the current version out from under your running java
applications. It does appear to make the upgrade safer, but
manual too.

Thanks,

MARK SMITH  REPLY TO MARK

August 21, 2015 at 8:31 am


For me, putting the “export PATH” stuff in
/etc/environment causes all users to get thrown
out when logging into the GUI.
Instead, do this:
echo “export JAVA_HOME=/opt/jdk1.8.0_51” >
/etc/profile.d/jre.sh
echo “export JRE_HOME=/opt/jdk1.8.0_51/jre” >>
/etc/profile.d/jre.sh
echo “export PATH=$PATH:/opt/jdk1.8.0_51
/bin:/opt/jdk1.8.0_51/jre/bin” >> /etc/profile.d
/jre.sh

ANKUR  REPLY TO ANKUR

September 2, 2015 at 1:58 pm


Hi Mark,

I too put the “export PATH” stuff in


/etc/environment and tried to restart my
machine.
Since then i am not able to login back
into my Ubuntu machine. ;-(

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

25 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

So that i can apply the changes suggested in your


post.

PAUL OFFORD
October 17,  REPLY TO PAUL
2015 at 2:24 pm
Hi,

I had this problem too with


Centos 7. The reason is that if
you put the entries in
/etc/environment it messes up
the PATH environment setting
which includes removing
reference to /bin.

To recover do the following:

1. Ctl-Alt-F2 to switch to a
command line console
2. Login with your account
details – you’ll get errors as the
shell script runs but don’t worry
for the moment
3. Enter the command
PATH=$PATH:/bin
4. Enter the command startx
5. Once the desktop appears
open a terminal session
6. Enter the command su –
5. Enter your root password at
the prompt
6. Again, enter PATH=$PATH:/bin
7. Enter the command gedit
/etc/environment
8. Delete all lines in the file and
save
9. Restart Centos

Best regards…Paul

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

26 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

August  REPLY TO SACHIN


5,
2017 at 9:34 am
Thank a lot Paul

DAWOOD
 REPLY TO DAWOOD
August 7, 2017 at 2:11 am
Hi, i messed up my centos
6 machine. i have the
same problem. but i try to
do what you have
explained here, the
instruction # 4 does not
work. it says -bash:
comand not found.

am really having a terrible


time

FHERPIE  REPLY TO FHERPIE

September 13, 2016 at 6:08 pm


Hi everyone I would to know how resolve
this:

bash: $’\342\200\234export’: order not


found
bash: $’\342\200\234export’: order not
found
bash: $’\342\200\234export’: order not
found
[evconsul8@localhost ~]$

This happens from that I “installed java


or detroyed with java my pc” I don’t
know why:
I have done this:
echo “export JAVA_HOME=/opt
/jdk1.8.0_101” > /etc/profile.d/jre.sh
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

27 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

echo “export PATH=$PATH:/opt/jdk1.8.0_101


/bin:/opt/jdk1.8.0_101/jre/bin” >> /etc/profile.d
/jre.sh
according to Mark Smith user. All run fine. after
Reboot I get that message in my terminal.
I am afraid. Because I don’t know if this affects
only to java or all my apps in mi machine Centos7

PETER  REPLY TO PETER

August 5, 2015 at 11:42 am


I cannot install to Centos 6.X.

I got the following error message:


# java -version
-bash: /usr/bin/java: cannot execute binary file

It is file permission problem or something else?

RAHUL  REPLY TO RAHUL

August 5, 2015 at 1:11 pm


Hi Peter,

Did you executed alternatives


commands properly ?

XAVO  REPLY TO XAVO

July 23, 2016 at 6:17 pm


I cannot install to Centos 6.X.
even I executed alternatives cmd
properly

I got the following error


message:
# java -version
-bash: /usr/bin/java: cannot

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

28 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

ANKIT  REPLY TO ANKIT

July 15, 2015 at 6:48 am


nice, not sure about export part but rest is
helpfull

KAMAL  REPLY TO KAMAL

June 23, 2015 at 6:40 am


Thanks a lot

BMIL  REPLY TO BMIL

May 29, 2015 at 9:45 pm


export PATH=$PATH:/opt/jdk1.8.0_45/bin:/opt
/jdk1.8.0_45/jre/bin
Also put all above environment variables in
/etc/environment file for auto loading on system
boot.

export is not working, when you put it in


/etc/environment file

export is shell command and /etc/environment


process only static variables
variable=value

REYES  REPLY TO REYES

May 7, 2015 at 5:34 pm


I followed yout guifr but I didn’t manage to install
Java on my server so I asked my hosting provider
(RoseHosting)to install Java for me. Thank you.

FELIX  REPLY TO FELIX

April 25, 2015 at 1:28 am


This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

29 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

Unrecognized option: –version


Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

Please help!

RAHUL  REPLY TO RAHUL

April 25, 2015 at 3:04 am


HI Felix,

Make sure you are using single hyphen (


– ) with option -version.

ANKUJ  REPLY TO ANKUJ

April 23, 2015 at 2:08 pm


Work …centos 6.6
can any one tell me what exactly “alternatives”
command doing here.

TONY  REPLY TO TONY

April 16, 2015 at 1:56 pm


Followed the instructions and it worked like a
charm. Thanks much Rahul.

TAPAS  REPLY TO TAPAS

April 9, 2015 at 4:10 am


Hi Admin,

I have followed your steps but getting following


error when running command ‘java -version’

-bash: /usr/bin/java: /lib/ld-linux.so.2: bad ELF


This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

30 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

RAHUL  REPLY TO RAHUL

April 9, 2015 at 4:13 am


Hey Tapas,

You have downloaded wrong java


archive as your system architecture.
Check your system architecture using
command below and download correct
java archive.

uname -m

OSCAR  REPLY TO OSCAR

May 10, 2016 at 10:04 pm


a little late, but for anyone having this
error maku sure you used the sudo
command, so:
sudo wget –no-cookies –no-check-
certificate –header “Cookie:
gpw_e24=http%3A%2F
%2Fwww.oracle.com%2F;
oraclelicense=accept-securebackup-
cookie” “http://download.oracle.com
/otn-pub/java/jdk/8u77-b03/jdk-8u77-
linux-x64.tar.gz”

SMITH  REPLY TO SMITH

February 3, 2015 at 2:00 pm


Working nice…. thanks for easy steps…..

JONATHAN WILLIS  REPLY TO JONATHAN

January 21, 2015 at 11:15 pm


Following these instructions on CentOS 6 I get
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

31 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

or directory

RAHUL  REPLY TO RAHUL

April 9, 2015 at 4:16 am


Hi Jonathan,

You have downloaded wrong java


archive as your system architecture.
Check your system architecture using
command below and download correct
java archive.

uname -m

JONATHAN WILLIS  REPLY TO JONATHAN

January 21, 2015 at 11:14 pm


Following these instructions on CentOS 6 I get
this error:

http://tecadmin.net/install-java-8-on-centos-rhel-
and-fedora/

JAY  REPLY TO JAY

January 7, 2015 at 1:31 pm


Hello sir, Im trying to install the latest java on my
VPS to run a simple .jar file and the 1st step “tar
xzf jdk-8u25-linux-x64.tar.gz” returns

# tar xzf jdk-8u25-linux-x64.tar.gz


tar (child): jdk-8u25-linux-x64.tar.gz: Cannot
open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

32 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

GNU/Linux. I tried installing via both SSH and terminal of


the VPS itself. Both returned the same result, what have I
done wrong? Any help would be greatly appreciated.

KENT  REPLY TO KENT

December 27, 2014 at 6:05 pm


Thank you for this clear, easy-to-follow guide!
With it I quickly installed Java 8 update 25.

RAHUL  REPLY TO RAHUL

April 9, 2015 at 4:18 am


Thanks Kent

DAVID+  REPLY TO DAVID+

December 22, 2014 at 10:02 pm


Yo no pude usar el mismo comando y use este
“update-alternatives” y solo así pude lograrlo.

CYNDY LOOPER  REPLY TO CYNDY

December 9, 2014 at 11:12 am


Thanks alot i used it to install it on 32 bit CEntos
6.5 successfully.
WHen i tried to set up the environment variables
. I got no report whatsoever after running your
code. Hope i got it correctly?

ARDHAN  REPLY TO ARDHAN

November 16, 2014 at 9:24 am


This work… thanks a lot

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

33 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

ALEJANDRO
November 1, 2014 at 1:56  REPLY TO ALEJANDRO
pm
This is a great concise article, working fine to
centOs 6.5, thanks a lot.

CHRIS  REPLY TO CHRIS

October 28, 2014 at 9:57 am


This is a great concise article. Thank you.

FELIPE1982  REPLY TO FELIPE1982

October 28, 2014 at 6:40 am


you can append `-O jdk-8u25-linux-x64.tar.gz` to
your wget line so that it renames it appropriately.

KENT  REPLY TO KENT

October 24, 2014 at 10:19 pm


This helped me with RedHat Linux 6. Thank you!

YING  REPLY TO YING

October 15, 2014 at 2:23 am


Thanks for the instructions first. I followed all the
steps on CentOS. However, I got No such file or
directory after typing “java -version”. Any idea
what might have caused it?

BRAD  REPLY TO BRAD

July 16, 2015 at 4:35 am


Ying, I had the same issue. I followed the
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

34 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

version of java with the same results. Finally I


traced it to (I think) to the alternative command. It
seems it could not creating the symbolic link
correctly between “/etc/alternatives” and
“/opt/jdk1.8.0_45/bin/java”.
I deleted the existing link “”/etc/alternatives/java”
and then recreated it:

ln -s /opt/jdk1.8.0_45/bin/java java

and now the command “java -version” displays:


java version “1.8.0_45”
Java(TM) SE Runtime Environment (build 1.8.0_45-
b14)
Java HotSpot(TM) Server VM (build 25.45-b02,
mixed mode)

MAZHAR  REPLY TO MAZHAR

September 22, 2014 at 12:43 pm


Thanks a lot, very useful article.

ROB  REPLY TO ROB

September 14, 2014 at 10:33 am


Great article thanks

MAURICIO  REPLY TO MAURICIO

August 29, 2014 at 4:31 pm


Working fine to centOs 6.5, thanks a lot.

MUSTA  REPLY TO MUSTA

August 28, 2014 at 1:05 am


This work for Fedora 20?

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

35 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

RAVIKIRAN PATIL
August 20, 2014 at 3:25 pm  REPLY TO RAVIKIRAN
Thank you so much Rahul Kumar……. This
article is the best article that I found.

LEO  REPLY TO LEO

April 30, 2014 at 4:18 pm


Thank you so much.

Maybe useful for other readers:


– On a vanilla fedora (or at least on my system),
‘alternatives’ doesn’t seem to be in the path, so
the full path has to be specified:
sudo /usr/sbin/alternatives –install /usr/bin/java
java /opt/jdk1.8.0_05/bin/java 2
sudo /usr/sbin/alternatives –config java

– In case folks are not familar, the export


commands can go into ~/.bash_profile , but
careful not to overwrite your existing “PATH”,
instead append to it. This is an example of my
~/.bash_profile
# .bash_profile

# Get the aliases and functions


if [ -f ~/.bashrc ]; then
. ~/.bashrc

# User specific environment and startup


programs

PATH=$PATH:$HOME/.local/bin:$HOME
/bin:$HOME/Dropbox/Apps/Bash_path_linux/:/opt
/jdk1.8.0_05/bin:/opt/jdk1.8.0_05/jre/bin

export JAVA_HOME=/opt/jdk1.8.0_05
export JRE_HOME=/opt/jdk1.8.0_05/jre
export PATH

Hope it helps.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

36 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

January 7, 2015 at 1:30 pm


Hello sir, Im trying to install the latest
java on my VPS to run a simple .jar file
and the 1st step “tar xzf jdk-8u25-linux-
x64.tar.gz” returns

# tar xzf jdk-8u25-linux-x64.tar.gz


tar (child): jdk-8u25-linux-x64.tar.gz:
Cannot open: No such file or directory
tar (child): Error is not recoverable:
exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now

Running “uname -a” returns , which I


presume is 64bit, Im using Centos 6. #1
SMP Mon Aug 11 18:47:39 MSK 2014
x86_64 x86_64 x86_64 GNU/Linux. I
tried installing via both SSH and terminal
of the VPS itself. Both returned the same
result, what have I done wrong? Any
help would be greatly appreciated.

RAHUL  REPLY TO RAHUL

April 9, 2015 at 4:18 am


Hi Jay,

It looks jdk-8u25-linux-x64.tar.gz
is not available at current
directory. Make sure the file
exists there with correct name.

SUMIT SAHAY
 REPLY TO SUMIT
September 14, 2018 at 10:16
am
Hi Rahul,

I am trying to install jenkins on my


centos vm instance but unable to do
so as its need java 8 and the java
version in my system is 1.7. Now, I
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

37 of 38 10/18/18, 12:04 PM
How To Install Java 8 (JDK 8u181) On CentOS/R... https://tecadmin.net/install-java-8-on-centos-rhel-...

couple of times “jre-8u181-linux-


All rights reserved. © 2013-2018 TecAdmin.net.
x64.rpm” and wheneverThisI site uses cookies. By using this website you
am trying
agree our term and services
to execute this rpm file, like below,
sudo yum install jre-8u181-linux-

This website uses cookies to improve your experience. We'll assume you're ok with this, but you can

opt-out if you wish. Accept Reject Read More

38 of 38 10/18/18, 12:04 PM

You might also like