1

I understand that this question has been asked exhaustively and do not mind if it is marked as a duplicate, but I am having a little trouble setting Java up. When I follow this post, number six says that

After extraction you must see a folder named jdk1.8.0_51

However with the new JDK (at time of writing 8u66), when I extract the file, I just have one binary file. How do I set it up?

7
  • Why are you simply not using "apt-get install openjdk-8-jdk"? – Max Kulik Dec 22 '15 at 14:58
  • @MaxKulik My internet is down at my place, and will only be back on Friday. – Kency Bond Dec 22 '15 at 15:04
  • There is a project that I'd like to finish up as well. – Kency Bond Dec 22 '15 at 15:32
  • what is the binary file you have? I just downloaded 1.8.0_65 tar.gz and it extracted the directory like your instructions. I seem to remember that some of them where installers along the way. So in that case you would have to set the file executable and run it. – Eddie Dunn Dec 22 '15 at 15:39
  • @EddieDunn I download the 64bit JDK and I only find a tar file that has the same name as the archive I just extracted. If I execute it (like so: ./jdk-8u66.... etc I get a bash error. Did you download the 32bit JDK? – Kency Bond Dec 22 '15 at 15:48
13

Installing Java Offline

Find out whether you are running a 32 bit or a 64 bit OS:

uname -m

x86_64: 64 bit kernel

i686: 32 bit kernel

Go to the Oracle Java SE website and decide which version you want to install:

JDK: Java Development Kit. Includes a complete JRE plus tools for developing, debugging, and monitoring Java applications.

Server JRE: Java Runtime Environment. For deploying Java applications on servers. Includes tools for JVM monitoring and tools commonly required for server applications.

Accept the license and copy the download link into your clipboard. Remember to choose the right tar.gz (64 or 32 bits). Use wget to download the archive into your server:

wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u5-b13/jdk-8u5-linux-x64.tar.gz

Oracle does not allow downloads without accepting their license, therefore we needed to modify the header of our request. Alternatively, you can just download the compressed file using your browser and manually upload it using a SFTP/FTP client.

Always get the latest version from Oracle's website and modify the commands from this tutorial accordingly to your downloaded file.

Installing Oracle JDK

The /opt directory is reserved for all the software and add-on packages that are not part of the default installation. Create a directory for your JDK installation:

sudo mkdir /opt/jdk

and extract java into the "/opt/jdk" directory:

sudo tar -zxf jdk-8u5-linux-x64.tar.gz -C /opt/jdk

Verify that the file has been extracted into the /opt/jdk directory.

ls /opt/jdk

Setting Oracle JDK as the default JVM

In our case, the java executable is located under /opt/jdk/jdk1.8.0_05/bin/java . To set it as the default JVM in your machine run:

update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100

and

update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100

Verify your installation

Verify that java has been successfully configured by running:

update-alternatives --display java

and

update-alternatives --display javac

The output should look like this:

java - auto mode
link currently points to /opt/jdk/jdk1.8.0_05/bin/java
/opt/jdk/jdk1.8.0_05/bin/java - priority 100
Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/java'.

javac - auto mode
link currently points to /opt/jdk/jdk1.8.0_05/bin/javac
/opt/jdk/jdk1.8.0_05/bin/javac - priority 100
Current 'best' version is '/opt/jdk/jdk1.8.0_05/bin/javac'.

Another easy way to check your installation is:

java -version

The output should look like this:

java version "1.8.0_05"
Java(TM) SE Runtime Environment (build 1.8.0_05-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.5-b02, mixed mode)

(Optional) Updating Java

To update Java, simply download an updated version from Oracle's website and extract it under the /opt/jdk directory, then set it up as the default JVM with a higher priority number (in this case 110):

update-alternatives --install /usr/bin/java java /opt/jdk/jdk.new.version/bin/java 110
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk.new.version/bin/javac 110

You can keep the old version or delete it:

update-alternatives --remove java /opt/jdk/jdk.old.version/bin/java
update-alternatives --remove javac /opt/jdk/jdk.old.version/bin/javac

rm -rf /opt/jdk/jdk.old.version
3
  • I should have added this, but in your case you will have to visit the Java site given in step one and re-download the correct version on a computer that has a working Internet connection. – Max Kulik Dec 22 '15 at 19:08
  • I wonder if he got it...? – Max Kulik Dec 28 '15 at 7:54
  • Using this mehtod, should I set JAVA_HOME and JRE_HOME to /opt/jdk/jdk.version/ ? – Mehrdad Salimi Aug 14 '19 at 18:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.