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 Overflow
Top answer
1 of 6
15

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.

2 of 6
13

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

Top answer
1 of 1
3

You have two options ahead of you:

  1. You can uninstall JDK-16.0.2, then install OpenJDK 11 and have just that implementation on your system
  2. You can install OpenJDK 11 and use update-alternatives to specify which version you want to be treated as default

This answer will focus on the second option, though you can modify it to work for the first.

  1. Open a Terminal (if one is not already open) or SSH into the server you're installing Java onto
  2. Install the default Java runtime. For Ubuntu 20.04, this is version 11.0.11:
    sudo apt install default-jre
    
    If you want to be absolutely certain of the version, you can also specify the version:
    sudo apt install openjdk-11-jre-headless
    
  3. Install the default Java Development Kit:
    sudo apt install default-jdk
    
  4. Confirm the versions:
    java -version
    
    This should give you something like:
    openjdk version "11.0.11"
    OpenJDK Runtime Environment (build 11.0.11+9-post-Ubuntu-3ubuntu1)
    OpenJDK 64-Bit Server VM (build 11.0.11+9-post-Ubuntu-3ubuntu1, mixed mode, sharing)
    
    Also check the compiler:
    javac -version
    
    Which will give you something like:
    javac 11.0.11
    
  5. Set version 11 as the default for the system:
    sudo update-alternatives --config java
    
    This will give you an output similar to:
    There are 2 choices for the alternative java (providing /usr/bin/java).
    
      Selection    Path                                         Priority   Status
      --------------------------------------------------------------------------------
      0            /usr/lib/jvm/java-16-openjdk-amd64/bin/java   1111      auto mode
      1            /usr/lib/jvm/java-16-openjdk-amd64/bin/java   1111      manual mode
    * 2            /usr/lib/jvm/java-11-openjdk-amd64/bin/java   1091      manual mode
    
    Press <enter> to keep the current choice[*], or type selection number:
    
    You can also do this for the compiler with:
    sudo update-alternatives --config javac
    
  6. Confirm your JAVA_HOME variable is correct:
    sudo vi /etc/environment
    
    Note: Feel free to use any text editor that you prefer. The use of vi here is more a force of habit than an endorsement. Locate the JAVA_HOME variable and ensure it's set correctly:
    JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
    
    Reload your sources:
    source /etc/environment
    
    Verify the variable is set:
    echo $JAVA_HOME
    
    You should see:
    /usr/lib/jvm/java-11-openjdk-amd64
    

That's all there is to it 👍🏻

Discussions

How do I downgrade JDK?
$ sudo apt remove openjdk-16-jdk $ sudo apt update && sudo apt install openjdk-11-jdk More on reddit.com
🌐 r/linux4noobs
9
7
August 30, 2021
centos - How to yum downgrade to a specific version of packet like jdk? - Unix & Linux Stack Exchange
I know it's sudo yum downgrade - but always can't find the packet. for example sudo yum --showduplicates list java-1.7.0-openjdk Installed Packages java-1.7.0- More on unix.stackexchange.com
🌐 unix.stackexchange.com
How to downgrade from java11 to java8?
Try running these commands: wget -qO - https://adoptopenjdk.jfrog.io/adoptopenjdk/api/gpg/key/public | apt-key add - add-apt-repository --yes https://adoptopenjdk.jfrog.io/adoptopenjdk/deb/ apt-get update -y && apt-get install -y adoptopenjdk-8-hotspot More on reddit.com
🌐 r/Crostini
10
6
October 24, 2020
java - How to downgrade JDK? - Stack Overflow
Also, you should bear in mind that ... downgrade the Java version for other things. This answer suggests setting the variable in the neo4j startup script instead, so it only applies to neo4j. 2021-10-05T08:42:11.123Z+00:00 ... I didn't know that. Many thanks 2021-10-05T08:46:50.417Z+00:00 ... Save this answer. ... Show activity on this post. For linux users run ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Linux Mint Forums
forums.linuxmint.com › board index › main edition support › software & applications
[SOLVED] How to downgrade Java version - Linux Mint Forums
April 24, 2019 - To the best of my knowledge, the ... be able to install openjdk8-jre from the official software repositories. - You might use Synaptic package manager, search for openjdk8-jre and install it. Afterwards you should be able to switch the default Java version from 10 to ...
🌐
Brainly
brainly.com › computers and technology › high school › how do you downgrade the java version in rhel 7?
[FREE] How do you downgrade the Java version in RHEL 7? - brainly.com
September 30, 2023 - For example, if you previously had Java 8 installed and wanted to downgrade to Java 7, you would first execute 'sudo yum remove java-1.8.0-openjdk*', followed by 'sudo yum install java-1.7.0-openjdk'. After installation, running 'java -version' should confirm that Java 7 is now in use. These steps are widely documented in the official RHEL documentation and various Linux tutorials that explain package management using 'yum', which is specific to RHEL-based distributions.
🌐
Gitopscentral
gitopscentral.in › how-to-downgrade-java-on-ubuntu-kali-linux
How to downgrade java on ubuntu/kali linux « GitopsCentral
In this blog post I am going to show you how to downgrade java and javac on ubuntu/kali linux. Some applications will require older version of java; For instance, I had to downgrade from openjdk 10 to openjdk 8 because Jenkins doesn’t support openjdk 10.
Find elsewhere
🌐
Stack Exchange
unix.stackexchange.com › questions › 660261 › how-to-yum-downgrade-to-a-specific-version-of-packet-like-jdk
centos - How to yum downgrade to a specific version of packet like jdk? - Unix & Linux Stack Exchange
sudo yum downgrade java-1.7.0-openjdk-1:1.7.0.201-2.6.16.0.el6_10 No package java-1.7.0-openjdk-1:1.7.0.201-2.6.16.0.el6_10 available. Nothing to do ... ? How about yum install java-1.7.0-openjdk-1.7.0.201-2.6.16.0.el6_10 .........
🌐
Baeldung
baeldung.com › home › installation › removing old versions of java and installing new versions on linux
Removing Old Versions of Java and Installing New Versions on Linux | Baeldung on Linux
January 14, 2025 - In this tutorial, we’ll walk through the process of identifying outdated Java versions. We’ll also see how to remove them and install new ones on a Linux system to stay on the latest and most secure release.
Top answer
1 of 1
8

Download

Go to official java download page, scroll down to the bottom of the page until you see Previous Releases. Click Download

Choose Java SE 7 on the next page and you will see web-page where you can choose specific Java version. If you unsure what to choose, choose Development Kit - it will cover all your needs

Now you will get this page. And you see something like screenshot below. Choose tar.gz depending on your architecture, I highlighted two of them that fits Ubuntu:

Oracle may ask you to sign up before download


Installation

Now you have file jdk*.tar.gz. Here is great manual about installing java. I took out the instruction and changed it a little bit.

  • Uncompress .tar.gz

    tar -xvf jdk*

The JDK package is extracted into jdk.xxx directory. Check carefully this folder name, because we will use it the next step. I'm assuming that path to this new extracted folder is path_to_jdk_folder and folder name is folder_name, you should manually change it before executing commands below.

Usually it is:

path_to_jdk_folder - /home/c0rp/Downloads/jdk1.7.0

folder_name - jdk1.7.0

  • Installing

Run sudo update-alternatives --list java to check if you have configured java already.

$ sudo update-alternatives --list java
/usr/lib/jvm/jdk1.6.0_45_x586/bin/java
/usr/lib/jvm/jdk1.7.0_21/bin/java
/usr/lib/jvm/jdk1.8.0/bin/java

If it is saying update-alternatives: error: no alternatives for java run this set of commands. Don't forget replace path_to_jdk_folder and folder_name:

sudo mkdir /usr/lib/jvm
sudo mv path_to_jdk_folder /usr/lib/jvm/folder_name
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/folder_name/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/folder_name/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/folder_name/bin/javaws" 1
sudo chmod a+x /usr/bin/java
sudo chmod a+x /usr/bin/javac
sudo chmod a+x /usr/bin/javaws

If there is no errors and your java list is not empty, run this set of commands. Don't forget replace path_to_jdk_folder and folder_name:

LNUM=$[$(update-alternatives --list java | wc -l) + 1]
sudo mv path_to_jdk_folder /usr/lib/jvm/folder_name
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/folder_name/bin/java" "$LNUM"
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/folder_name/bin/javac" "$LNUM"
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/folder_name/bin/javaws" "$LNUM"
  • Run

    sudo update-alternatives --config java
    

You will see output similar to the one below - choose the number of new jdk1.7.0 (folder_name) - for example 2 in this list (unless you have have never installed Java in your computer in which case a sentence saying There is nothing to configure will appear):

    $ sudo update-alternatives --config java
    There are 3 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
  0            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      auto mode
  1            /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java   1071      manual mode
  2            /usr/lib/jvm/jdk1.7.0/bin/java                   1         manual mode
* 3            /usr/lib/jvm/jdk1.8.0/bin/java                   1         manual mode

Press enter to keep the current choice[*], or type selection number: 2
update-alternatives: using /usr/lib/jvm/jdk1.8.0/bin/java to provide /usr/bin/java (java) in manual mode

Repeat the above for:

sudo update-alternatives --config javac
sudo update-alternatives --config javaws

Check installation

java -version
🌐
Reddit
reddit.com › r/crostini › how to downgrade from java11 to java8?
r/Crostini on Reddit: How to downgrade from java11 to java8?
October 24, 2020 -

I have spent around 2 weeks now scouring all over the web trying to find out how to install it without it giving some stupid error like "E: Unable to locate package openjdk-8-jdk" and it not getting detected by the system. I have manged to install open-java8 on sdk, but the system does not detect it. I need java8 for minecraft as older modded versions of the game are really buggy in java11 and crash at start. How can I install and downgrade to java8, and for an linux application for minecraft, be able to see it?

🌐
LinuxQuestions.org
linuxquestions.org › questions › linux-newbie-8 › downgrading-java-1-6-to-java-1-4-a-880296
[SOLVED] Downgrading Java 1.6 to Java 1.4
Hi all I need to downgrade my java version from 1.6 to 1.4 for some reasons (trust me , it's necessary) so , can someone provide me some info how i
🌐
Wordpress
kuntalchandra.wordpress.com › 2019 › 06 › 24 › ubuntu-16-downgrade-java-9-to-8
Ubuntu 16: Downgrade Java 9 to 8 | Implementing Brute force
June 24, 2019 - Though the reversion is easy but I was having an issue to point to the default version. Note to me- How I reverted: $ sudo add-apt-repository ppa:webupd8team/java $ sudo apt update; sudo apt ...
🌐
Red Hat
access.redhat.com › solutions › 7068103
How can downgrade the JAVA version from 1.8.0_401 to 1.8.0_351 ? - Red Hat Customer Portal
Customer is not being able to see the jdk 1.8_351 version, They're looking for a guidance on where they can download it. They are going to do the RPM Install.
🌐
FOSS Linux
fosslinux.com › home › linux distributions › debian & ubuntu › ubuntu › how to switch java versions in ubuntu
How to Switch Between Java Versions in Ubuntu
April 24, 2026 - This guide covers the hardened protocols for identity-level Java management in 2026. Ubuntu, following the Debian standard, manages multiple versions of the same tool via the update-alternatives system.
🌐
Ubuntu Shell
ubuntushell.com › change-java-version
How to Change Java Version on Ubuntu (CLI and GUI)
November 16, 2025 - To install the G Alternative on Ubuntu, simply use the following command: ... Choose Java from the Groups section (from the left pane), then select the desired version of Java you wish to set as the default from the available options.
🌐
Techwalla
techwalla.com › tech support › how to
How to Downgrade Java | Techwalla
November 16, 2018 - After you do that, go to Oracle's Older Java Archive, where you'll see a list of download files. When you click on a file, you are directed to a page where you can get Java for Mac, Windows or Linux.