Ubuntu - Default Java, Oracle JDK not detected as installed - java

I have an ubuntu installation with Oracle JDK 1.8.0_141 was installed using the below guide.
https://www.digitalocean.com/community/tutorials/how-to-manually-install-oracle-java-on-a-debian-or-ubuntu-vps
tar was extracted to /opt/jdk and below commands used to set java as default.
update-alternatives --install /usr/bin/java java /opt/jdk/jdk1.8.0_05/bin/java 100
update-alternatives --install /usr/bin/javac javac /opt/jdk/jdk1.8.0_05/bin/javac 100
java -version command works fine after these has been completed.
But when I try to install maven using apt-get it tries to install default-jre rather than using this installed version.
Any idea where can I change this default behavior.
Thanks

This was solved after setting the kava alternative
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk/jdk1.8.0_144/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/jdk/jdk1.8.0_144/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/jdk/jdk1.8.0_144/bin/javaws" 1
It still install the default jdk when installing maven. But uses oracle jdk when building.
Thanks for the wikihow page : https://www.wikihow.com/Install-Oracle-Java-JDK-on-Ubuntu-Linux

Related

Uninstall Oracle Java from Ubuntu 18.04

I had installed Oracle Java following the steps described in this link.
But now I want to remove this version of Java as I am using OpenJDK for a project, how can I remove oracle java now from my Ubuntu 18.04 system?
First, you delete the link:
sudo update-alternatives --remove "java" "/usr/lib/jvm/jdk[version]/bin/java"
sudo update-alternatives --remove "javac" "/usr/lib/jvm/jdk[version]/bin/javac"
sudo update-alternatives --remove "javaws" "/usr/lib/jvm/jdk[version]/bin/javaws"
Then, you can delete the package:
sudo rm -r /usr/lib/jvm/jdk[version]
Credit to https://askubuntu.com/questions/117543/how-to-remove-oracle-jdk/

About Java 7 installation

I am trying to install Java 7 on my Ubuntu 14.04 system. I have downloaded the package in oracle, jdk1.7.0_80, which contains all the tools in bin folder.
Here comes my question. I want to switch the version of my tools to match the tools in bin folder in jdk1.7.0_80. Like java, jar and javac, whenever there exists a tool in /usr/bin, OS will automatically map the tool to my jdk bin folder. Does anyone has idea on this?
Thanks,
Xianan
Here is how you should install java alternatives
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_45/bin/java" 1
sudo update-alternatives --set java /usr/local/java/jdk1.7.0_45/bin/java
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_45/bin/javac" 1
sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_45/bin/javac
If you need full JRE with the web plugin you can use
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_45/bin/javaws" 1
sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_45/bin/javaws
You can check whats available and switch between installed java versions using
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Install Java 5 in Ubuntu 12.04

I need to install Java 5 in my Ubuntu 12.04. Can't do it by apt-get anymore.
Downloaded the .bin from
http://www.oracle.com/technetwork/java/javasebusiness/downloads/java-archive-downloads-javase5-419410.html
and installed it.
Still, the option for jdk 1.5 doesn't appear after I do:
sudo update-alternatives --config java
What am I doing wrong? How should I do it?
Thanks.
Looks like you got it wrong.
For using update-alternatives you have to inform it that you got a new java version:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jre1.7.0_40/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_40/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jre1.7.0_40/bin/javaws" 1
And set that version as the default one:
sudo update-alternatives --set java /usr/local/java/jre1.7.0_40/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_40/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jre1.7.0_40/bin/javaws
Also, you may want to edit you /etc/profile to add java to the PATH, although maybe the Oracle installer already did that for you.

Java not visible when using oracle self extracting installer for ubuntu

I want to install the oracle jdk 6 in ubuntu for all users using the self extracting installer at oracles website (jdk-6u37-linux-x64.bin)
This is what i do step by step:
1- Download the jdk-6u37-linux-x64.bin
2- Create a folder in the unix system resources and move the downloaded file there
sudo mkdir -p /usr/local/java
sudo mv /home/sfrj/Downloads/jdk-6u37-linux-x64.bin /usr/local/java
3- Make the file executable
sudo chmod 700 jdk-6u37-linux-x64.bin
4. Execute the installer
sudo ./jdk-6u37-linux-x64.bin
5. Remove the installer(Don't need it anymore)
sudo rm jdk-6u37-linux-x64.bin
6. Create a symbolic link
sudo ln -s jdk1.6.0_37 /usr/local/java/latest
7. Edit the file /etc/environment
JAVA_HOME="/usr/local/java/jdk1.6.0_37"
JRE_HOME="/usr/local/java/jdk1.6.0_37/jre"
PATH="/usr/local/java/jdk1.6.0_37/bin:\/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
8. Reload the environment file
source /etc/environment
So far so good, after all that and without closing the terminal I type: java -version
and I see this:
java version "1.6.0_37" Java(TM) SE Runtime Environment (build
1.6.0_37-b06) Java HotSpot(TM) 64-Bit Server VM (build 20.12-b01, mixed mode)
The problem is, when close the terminal, open it again and type the command java -version again, I see this:
The program 'java' can be found in the following packages:
* default-jre
* gcj-4.6-jre-headless
* gcj-4.7-jre-headless
* openjdk-7-jre-headless
* openjdk-6-jre-headless
Try: sudo apt-get install <selected package>
I am confused:
-Why is this?
-Did I install the jdk correctly?
-What is missing?
I want to install it this way, without using apt-get, so please don't answer to me use apt-get install...
-Why is this?
You are not setting your path in a way which is reloaded automatically.
-Did I install the jdk correctly?
There is two ways of installing it. For the self unpacking version this is correct.
-What is missing?
Your environment is not set correctly.
This is my online guide. There are a few differences, and it works for me.
JDK Installation - Ubuntu
Debian style linux distros have the alternative mechanism for this kind of problems. They link /usr/bin/java to /etc/java which in turn is linked to the correct binary.
sudo update-alternatives --install /usr/bin/java java /usr/local/java/jdk1.6.0_37/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/local/java/jdk1.6.0_37/bin/javac 1
sudo update-alternatives --install /usr/bin/javaws java /usr/local/java/jdk1.6.0_37/bin/javaws" 1
sudo update-alternatives --install /usr/bin/jar jar /usr/local/java/jdk1.6.0_37/bin/jar 1
sudo update-alternatives --config java
sudo update-alternatives --config javac
sudo update-alternatives --config jar
sudo update-alternatives --config javaws
You may want to repeat this for the other commands like wsimport. Have a look at https://help.ubuntu.com/community/Java. There are also other options listed like using a PPA, but if you strictly don't want to use apt-get, this is not an option.
These scripts will help you install sun's jdk on Ubuntu. Works great.

installing sun-java6-jdk on ubuntu 10.04 64 bit os

I am trying to setup build enviroment for android on my ubunt10.04 machine. For that i want to install sun-java6-jdk as mentioned in source.andoid.com .
$ sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
$ sudo apt-get update
$ sudo apt-get install sun-java6-jdk
But now I am getting the error as no package for sun-java6-jdk.
so I want to know how to install suitable jdk for android build set up.
you could install sun jdk for Ubuntu 10.04 in the same way as 10.10. The steps for installing java in 10.10 is described in http://java.dzone.com/articles/sun-java-6-ubuntu-1004-1010
here's the steps of installing sun jdk, taken from that article:
add-apt-repository ppa:sun-java-community-team/sun-java6
apt-get update
apt-get install sun-java6-jdk
update-java-alternatives -s java-6-sun
in case the repository mentioned above not available anymore, here is a manual-ish alternative in installing JDK: http://codingforme.wordpress.com/2012/05/14/installing-oracle-java-jdk-6-or-7-on-ubuntu-12-04/
Sun JDK was dropped from Ubuntu due to licensing nonsense: http://news.softpedia.com/news/Canonical-Will-Remove-Java-From-Ubuntu-241147.shtml . Use openjdk instead.
Although there is a ppa here https://launchpad.net/~sun-java-community-team/+archive/sun-java6 that lets you install the SunJDK, it's very out-of-date and looks abandoned.
Download jdk-6u45-linux-x64.bin from Oracle repository and execute the below code
chmod u+x jdk-6u45-linux-x64.bin
./jdk-6u45-linux-x64.bin
sudo mv jdk1.6.0_45 /opt
sudo update-alternatives --install "/usr/bin/java" "java" "/opt/jdk1.6.0_45/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/opt/jdk1.6.0_45/bin/javac" 1
sudo update-alternatives --install "/usr/lib/mozilla/plugins/libjavaplugin.so" "mozilla-javaplugin.so" "/opt/jdk1.6.0_45/jre/lib/amd64/libnpjp2.so" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/opt/jdk1.6.0_45/bin/javaws" 1
MORE ON : http://peesquare.com/blogs/install-sun-java-6-on-ubuntu-10-04-12-04-12-10-13-04-13-10-both-32-bit-and-64-bit-system/
In my case, I'd rather download the required JDK directly from Sun's homepage. Once you download and unzip it, then all you need to do is simply adding an environment variable, JAVA_HOME. That's it. It is very simple and works regardless of ubuntu version.

Categories