3

I accidentally upgraded the whole system in ubuntu 14.04.

I am trying to deploy a war file which requires JDK7.

I tried to install JDK7 and use it as default

root:floyd~# update-alternatives --config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Nothing to configure.

but it is not installing as well. It gives following error while trying to install JDK 7.

root@floyd:~# apt-get install openjdk-7-jdk
Reading package lists... Done
Building dependency tree
Reading state information... Done
Package openjdk-7-jdk is not available, but is referred to by another package.
This may mean that the package is missing, has been obsoleted, or
is only available from another source

N: Ignoring file '50unattended-upgrades.ucf-dist' in directory '/etc/apt/apt.conf.d/' as it has an invalid filename extension
E: Package 'openjdk-7-jdk' has no installation candidate

I guess I have two options.

  1. Install JDK7 and use it as default.
  2. Downgrade JDK8 to JDK7.

I think downgrading can be a good option but I am not able to do any of them.

1
  • I recommend having a look at jEnv which lets you easily switch between multiple Java installations.
    – beatngu13
    Commented May 22, 2017 at 22:25

1 Answer 1

13

Installing JRE/JDK in default configuration OpenJDK 7 is installed as default in Ubuntu 12.10 and later. Installing Java whereby apt-get is easy:

sudo apt-get update

java -version

If after execution we have something like: "The program java can be found in the following packages", it means that Java isn't installed. So, we need to to:

sudo apt-get install default-jre

As result, Java Runtime Environment (JRE) will be installed. When we want to install Java Development Kit (JDK), which is needed for compilling Java-app (for example, Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA) we need to do:

sudo apt-get install default-jdk

Now, Java is installed.

Installing OpenJDK 7 (optionally)

sudo apt-get install openjdk-7-jre

After execution Java Runtime Environment (JRE) will be installed. For Java Development Kit (JDK), we execute:

sudo apt-get install openjdk-7-jdk

Installing Oracle JDK (optionally) Oracle JDK is an official JDK but, now, Oracle doesn't support it like default for installation in Ubuntu.

We can install it by apt-get but before we need to execute next commands:

sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update

Later, we have to choose needed version and execute:

For Oracle JDK 6

sudo apt-get install oracle-java6-installer

For Oracle JDK 7

sudo apt-get install oracle-java7-installer

For Oracle JDK 8

sudo apt-get install oracle-java8-installer

For Oracle JDK 9

sudo apt-get install oracle-java9-installer

Managing of Java (optionally) When we have some version Java installed we can choose one of them as default:

sudo update-alternatives --config java

As result we will see something like this:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

We can see it on the screen: enter image description here

The same action we can do to choose the compiler (javac):

sudo update-alternatives --config javac

This command can be used to choose other java componenst, for example, like: keytool, javadoc and jarsigner.

Installing "JAVA_HOME" To be installed **JAVA_HOME**:

sudo update-alternatives --config java

Result like:

There are 2 choices for the alternative java (providing /usr/bin/java).

Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/java-7-oracle/jre/bin/java          1062      manual mode

Press enter to keep the current choice[*], or type selection number:

As we can see the paths for java will be:

/usr/lib/jvm/java-7-oracle
/usr/lib/jvm/java-6-openjdk-amd64
/usr/lib/jvm/java-7-oracle

Now, we need to copy one of the ways and paste it into: /etc/environment:

sudo nano /etc/environment

In the file we are going to add a path(where YOUR_PATH - is path for desired version of java, for example: "/usr/lib/jvm/java-7-oracle"):

JAVA_HOME="/usr/lib/jvm/java-7-oracle"

On the screen:enter image description here

Now, we need to reboot this file:

source /etc/environment

To check it we can:

echo $JAVA_HOME

On the screen:enter image description here

When we have, now, input way("/usr/lib/jvm/java-7-oracle" in our example) it will be means we do it sucessfully. In other way we need to be more attentive and check all these steps once.

4
  • The link you've provided seems to be russian-only.
    – beatngu13
    Commented May 22, 2017 at 22:26
  • I was trying to make the information more comfortable. I think it can be helpful. Also, you can find more information here: askubuntu.com/questions/56104/… Commented May 23, 2017 at 6:59
  • After a day of searching, I could not go for any one the options since there were multiple errors. So, used the backup to get app online. Maybe I will try above suggestion on another virtual server to see how it works. Thanks anyway. Commented May 23, 2017 at 15:41
  • I have checked it on own machine (ubuntu 16.10 and 17.10). It works fine. Commented May 23, 2017 at 17:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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