Table of Contents
Scenario
Suppose that you try to start an Eclipse installation, and it fails returning exit code 8, 13, etc. , something like “java terminated exit code 8“.
This is usually caused due to the version of Java used by the environment that it is incompatible with the version of the Eclipse installation.
Another situation comes to happen when the available java is that you wish.
THE FLASH SOLUTION
If you like things very fast, here is the summary (or follow below the detailed information):
– installs or fix cmds:
sudo apt-get install default-jdk
sudo update-alternatives –config java
sudo apt-get purge default-jdk
– reboot if necessary
– check with:
sudo apt-get install default-jdk
java -version
whereis java
How to handle java’s environment?
We shall think about two situations.
We may have no java installed or not.
If you have already install java, go to “SET AND RESET JAVA ENV” section.
DISCOVERING YOUR ENVIRONMENT
Type:
java -version
Check if there are other alternatives:
sudo update-alternatives –config java
There is only one alternative in link group java (providing /usr/bin/java): /usr/lib/jvm/java-11-openjdk-amd64/bin/java Nothing to configure. update-alternatives: warning: forcing reinstallation of alternative /usr/lib/jvm/java-11-openjdk-amd64/bin/java because link group java is broken update-alternatives: warning: not replacing /usr/bin/java with a link
This output shows just one option, but If there are more options will return the a list.
INSTALLING FRESH JAVA
At least three options:
- Using apt, the default installation method on Debian distributions.
- Manually, by download of a tar file.
- If a framework like Eclipse, you may download it with an installer.
Using apt (apt-get) command
The apt command usually installs the Open-JDK java.
Command:
sudo apt-get install default-jdk
Sometimes it is necessary to use Oracle’s versions due to compatibilities issues.
I usually install them manually, but it may be used apt-get when you add the source into /etc/apt/sources.list.
In these cases, the documentation will lead you.
I rarely use this.
Manual installation
A very good solution and very flexible. Easy and fast that enables to work with many different types.
Download the tar file and extract its content.
Move its content to another directory, other than the “Download” dir.
Create the command to use that version. For instance:
nano myCmd
“$JAVA_PATH/bin/java” -jar myApp.jar
chmod 775 myCmd
To run:
./myCmd
Framework With Installer
The installer will do everything.
Just follow the instructions.
SET AND RESET JAVA ENV
Here comes when things get more interesting and where the issues happen.
The tools to discover your java env:
Which installation is working to run “java” command:
java -version
When you have no idea where the installations may be:
whereis java
Which options do the environment have?
sudo update-alternatives –config java
#SWITCHING THE ENVIRONMENT’S JAVA VERSION
When the comand
sudo update-alternatives –config java
works, it is easy. Just get the option you desire.
#MANUAL SWITCH
Sometimes, the environment has some issue and things don’t go as you expect requiring some radical procedures, they are:
Install the default java, even though you do not wish it.
sudo apt-get install default-jdk
Test using the commands:
java -version
sudo update-alternatives –config java
The 1st cmd must return the same version as default and the second shall show at least one option.
WHEN THINGS DON’T HAPPEN AND HOW TO FIX
Uninstall the default java previously installed:
sudo apt-get purge default-jdk
sudo apt update
Force removing the java appointment:
sudo rm /usr/bin/java
Reinstall java default:
sudo apt-get install default-jdk
Retest.
If it fails, try one more.
If it still fails, reboot the system and repeat the installation and uninstallation procedures and reboot again.
If successful, you shall get this:
sudo ls -al /usr/bin/java
lrwxrwxrwx 1 root root 22 Jan 5 19:45 /usr/bin/java -> /etc/alternatives/java
sudo ls -al /etc/alternatives/java
lrwxrwxrwx 1 root root 43 Jan 5 19:45 /etc/alternatives/java -> /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Well, and if still fails, there is still one workaround.
Use the absolut path to call java. Ex.:
JAVA_HOME/bin/java -version
NOTE:
WRONG: this way doesn’t work:
ln -s /home/portables_d/jdk1.6.0_30_64/bin/java java630
java630 -version
Returns:
java630 -version
java630: error while loading shared libraries: libjli.so: cannot open shared object file: No such file or directory
alsdias@vmvd20 $ /home/portables_d/jdk1.6.0_30_64/bin/java -java
RIGHT: this way works:
/home/portables_d/jdk1.6.0_30_64/bin/java -version
Returns:
Java(TM) SE Runtime Environment (build 1.6.0_30-b12) Java HotSpot(TM) 64-Bit Server VM (build 20.5-b03, mixed mode)
Brazilian system analyst graduated by UNESA (University Estácio de Sá – Rio de Janeiro). Geek by heart.