Java on Linux doesn't need to be installed as root. You can install as many different Java versions you want on Linux, either in separate user accounts or in a single account.
I do it all the time (switching from one Java version to another) to test on various versions of the JVM.
Changing your Java version can be as simple as this:
Copy... $ which java
/home/b/jdk1.5.0_22/bin/java
... $ export PATH=/home/b/jdk1.6.0_25/bin:$PATH
... $ which java
/home/b/jdk1.6.0_25/bin/java
To fetch an old version, go to the "Oracle Java Archive" page (Google if link becomes broken):
http://www.oracle.com/technetwork/java/archive-139210.html
Then pick your poison. I download the .bin, chmod +x it and then I extract the Java version I want from the .tgz.
Then I simply set the PATH and I'm usually good to go.
I run my IDE (IntelliJ IDEA) using one Java version, I typically compile using another JDK and I test on several JVMs.
All this from the same user account.
So it's not as if you had to install "one" Java version on a Linux system...
Now, concretely, if I were you, I'd simply remove all traces from Java while being root, and then I'd download the old version I need from the Oracle Java Archive.
Answer from TacticalCoder on Stack OverflowJava on Linux doesn't need to be installed as root. You can install as many different Java versions you want on Linux, either in separate user accounts or in a single account.
I do it all the time (switching from one Java version to another) to test on various versions of the JVM.
Changing your Java version can be as simple as this:
Copy... $ which java
/home/b/jdk1.5.0_22/bin/java
... $ export PATH=/home/b/jdk1.6.0_25/bin:$PATH
... $ which java
/home/b/jdk1.6.0_25/bin/java
To fetch an old version, go to the "Oracle Java Archive" page (Google if link becomes broken):
http://www.oracle.com/technetwork/java/archive-139210.html
Then pick your poison. I download the .bin, chmod +x it and then I extract the Java version I want from the .tgz.
Then I simply set the PATH and I'm usually good to go.
I run my IDE (IntelliJ IDEA) using one Java version, I typically compile using another JDK and I test on several JVMs.
All this from the same user account.
So it's not as if you had to install "one" Java version on a Linux system...
Now, concretely, if I were you, I'd simply remove all traces from Java while being root, and then I'd download the old version I need from the Oracle Java Archive.
like tactical coder said, you can install as many versions as you want, to switch the current version just run:
Copysudo update-alternatives --config java
And select the desired version.
If you wish, run it for javac and javaws:
Copysudo update-alternatives --config javac
sudo update-alternatives --config javaws
Source: https://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre
Downgrade java from version 8 to 7 - Stack Overflow
centos - How to yum downgrade to a specific version of packet like jdk? - Unix & Linux Stack Exchange
How do I downgrade JDK?
linux - How can I change Java version 1.7 to 1.8 in Ubuntu? - Stack Overflow
Use the -target flag to generate bytecode for earlier version. E.g. javac -target 1.5 FooBar.java.
There's no need to downgrade.
At least for Oracle's JDK (not sure about OpenJDK): install either the oracle-java7-set-default or the oracle-java8-set-default package, depending on which java version you want to be the default on your system.
You can get it from: http://ppa.launchpad.net/webupd8team/java/ubuntu (including the actual Oracle JDKs) See: https://launchpad.net/~webupd8team/+archive/java
Alternatively you could set the PATH and JAVA_HOME environment variables e.g. in /etc/environment
That said, when you compile you could specify the source and target level to 1.7, which would generate Java SE 7 compatible bytecode also when using JDK 8. But note it won't check if you're using some API not available in Java SE 7.
For this reason I recommend to use always the JDK version you target rather than doing some cross-compiling (which would need some additional extra steps to do it right).
Note however that you can install several JDK versions on your systems. IDEs usually let you choose which one you want to use during development.
I installed JDK with the Ubuntu Software application which selected JDK-16.0.2, and I need to downgrade to version 11.
sdkman is a good Open source version manager for Java. It provides commands to search & install multiple versions of Java and switch between versions with
sdk use java 1.8.363-open
It can also manage other tools like Maven.
you can set the envirnoment variable to java 1.8 using this method Edit the /etc/profile
sudo gedit /etc/profile
Add these lines in the end
JAVA_HOME=/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export JRE_HOME
export PATH
like mentioned in this answer
How to set Java environment path in Ubuntu
Install the version you need ,
# cd /<place you want java installed>/
# wget --no-cookies --no-check-certificate --header "Cookie: gpw_e24=http%3A%2F%2Fwww.oracle.com%2F; oraclelicense=accept-securebackup-cookie" "http://download.oracle.com/otn-pub/java/jdk/<version>/jdk-<version>-linux-x64.tar.gz"
# tar xzf jdk-<version>-linux-x64.tar.gz
Install Java with alternatives,
# cd /<place java install>/jdk1.6.0_17/
# alternatives --install /usr/bin/java java /opt/jdk1.6.0_17/bin/java 2
# alternatives --config java
Then select the version want
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* + 1 /opt/jdk1.6.0_38/bin/java
2 /opt/jdk1.6.0_17/bin/java
Enter to keep the current selection[+], or type selection number:
Enter 2
Try downloading and installing the specific version from Java downloads, then change the Java home path.
First, there is no need to "downgrade"; multiple simultaneous versions are supported. You can install Java 6, something like
sudo apt-get install openjdk-6-jdk
Then you can do something like (depending on platform)
export INSTALL4J_JAVA_HOME="/usr/lib/jvm/java-6-openjdk-amd64"
If you find what command you used, you might be able to get other help, like if the command was broken, or may need other packages.
You probably just need to install openjdk-6-jre like Elliot said, but just in case, you might as well.



