Download Oracle Java From The Terminal With wget
Category : How-to
Oracle have a very restrictive license that applies to most of their software downloads which prohibits you from distributing the binaries yourself. What this means, for example, is that you could not download the Java binaries and upload them to your own APT repository for others to use.
There are a few workarounds that exist to help making this install easier, but here we’re going to look at downloading the Java runtime environment (JRE) binaries and installing them all from a command line.
Use wget to download the binaries, so make sure that’s available on your system. If it isn’t, simply apt-get install wget.
One of the important things to note is that the Java version changes over time and therefore the links and commands below may need to be changed to ensure you’re always getting the latest version. Check out the Java Download Page to make sure you have the latest.
wget --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u51-b16/server-jre-8u51-linux-x64.tar.gz
I’m using an minimal version of Debian that doesn’t have the worlds Certificate Authorities installed and therefore wget gives me an error:
ERROR: cannot verify edelivery.oracle.com's certificate, issued by '/C=US/O=GeoTrust, Inc./CN=GeoTrust SSL CA': Unable to locally verify the issuer's authority. To connect to edelivery.oracle.com insecurely, use `--no-check-certificate'.
The fix is to either install the correct CA certificate on the machine or add the no-check-certificate switch to wget to avoid checking the certificate:
wget --no-check-certificate --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/8u51-b16/server-jre-8u51-linux-x64.tar.gz
Once you have the Java archive downloaded you’ll need to create a target folder and extract the downloaded archive with tar:
mkdir /opt/jre tar -zxf server-jre-8u51-linux-x64.tar.gz -C /opt/jre
The last couple of steps are to tell your OS to use the Java binaries you’ve just moved into place.
update-alternatives --install /usr/bin/java java /opt/jre/jdk1.8.0_51/bin/java 1000 update-alternatives --install /usr/bin/javac javac /opt/jre/jdk1.8.0_51/bin/javac 1000
Running anything in Java, or using the -version switch should now use your newly installed binaries.
java -version java version "1.8.0_51" Java(TM) SE Runtime Environment (build 1.8.0_51-b16) Java HotSpot(TM) 64-Bit Server VM (build 25.51-b03, mixed mode)
Leave a Reply