Installing JDK8 on linux (debian/ubuntu)

So how do I install JDK8 on debian etc these days when there seems to be some mess with Oracle licensing and linux package managers?

Found some nice instructions at https://www.digitalocean.com/community/tutorials/how-to-manually-install-oracle-java-on-a-debian-or-ubuntu-vps

To summarize:
Download the .tar.gz file for linux from Oracle website such as http://www.oracle.com/technetwork/java/javase/downloads, and we unzip that to some nice and shiny directory. Suggested on the above link is /opt/jdk, so do to this

first we upgrade to superuser privileges to avoid need to sudo all the time

sudo su

which apparently switches to root user (su is for switching user, with no param it is root), then we do

mkdir /opt/jdk
tar -zxf jdk-8u20-linux-x64.tar.gz -C /opt/jdk

to unpack the jdk distribution to /opt/jdk

now the above link suggests to do this

update-alternatives –install /usr/bin/java java /opt/jdk/jdk1.8.0_20/bin/java 100
update-alternatives –install /usr/bin/javac javac /opt/jdk/jdk1.8.0_20/bin/javac 100

which should install alternatives for java and javac commands with priority 100. Apparently the system should use these priorities to pick one of the alternatives over the other. This did not quite work well on my system as I found there was another version already installed with even higher priorities etc. And I would need to tune this and whatever.. So to fix it here is what I did

update-alternatives –list java

which gave me this

/opt/jdk/jdk1.8.0_20/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

as I did not need JDK7 the fix is simply this

update-alternatives –remove java /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java

after which “java -version” gives me jdk8 finally. and repeat for javac.. after system update this seems to re-install JDK7 so this is not necessarily a long term fix, but better to remove JDK7 completely, fix the priorities or whatever. But fixed it for me for now..

note: even if no java is installed before, the update-alternatives seems to work. whee

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s