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
2

Bitnami developer here. Please find below the steps required to install Java 7 JDK on your system and modify the Bitnami environment for changes to take effect. As an extra step before starting to modify your system, I recommend you to create a server backup.

  • Install Java 7 JDK on your system by running the commands below. It should be installed at /usr/lib/jvm/java-7-openjdk-amd64

    sudo apt-get update
    sudo apt-get install openjdk-7-jdk
    
  • Create a backup of the files that you need to modify

    cp /home/bitnami/.bashrc /home/bitnami/.bashrc.bck
    sudo cp /opt/bitnami/scripts/setenv.sh /opt/bitnami/scripts/setenv.sh.bck
    sudo cp /opt/bitnami/apache-tomcat/scripts/ctl.sh /opt/bitnami/apache-tomcat/scripts/ctl.sh.bck
    sudo cp /opt/bitnami/apache-tomcat/bin/setenv.sh /opt/bitnami/apache-tomcat/bin/setenv.sh.bck
    
  • Set PATH and LD_LIBRARY_PATH environment variables to point to the Java 7 installation directory adding the lines below at the end of the /opt/bitnami/scripts/setenv.sh file

    # Set PATH and LD_LIBRARY_PATH for Java 7
    PATH="/usr/lib/jvm/java-7-openjdk-amd64/bin:/opt/bitnami/sqlite/bin:/opt/bitnami/java/bin:/opt/bitnami/php/bin:/opt/bitnami/mysql/bin:/opt/bitnami/apache2/bin:/opt/bitnami/common/bin:$PATH"
    export PATH
    LD_LIBRARY_PATH="/usr/lib/jvm/java-7-openjdk-amd64/lib:/opt/bitnami/sqlite/lib:/opt/bitnami/mysql/lib:/opt/bitnami/apache2/lib:/opt/bitnami/common/lib:$LD_LIBRARY_PATH"
    export LD_LIBRARY_PATH
    
  • Modify the JRE_HOME variable from JRE_HOME=/opt/bitnami/java to JRE_HOME=/usr/lib/jvm/java-7-openjdk-amd64 in file /opt/bitnami/apache-tomcat/scripts/ctl.sh

  • Modify the JAVA_HOME variable from JAVA_HOME=/opt/bitnami/java to JAVA_HOME=/usr/lib/jvm/java-7-openjdk-amd64 in both /opt/bitnami/scripts/setenv.sh and /opt/bitnami/apache-tomcat/bin/setenv.sh files

  • Restart all the Bitnami services using the ctlscript.sh script

    sudo /opt/bitnami/ctlscript.sh restart
    
  • Load the environment and check the Java version by running the commands below

    . /opt/bitnami/scripts/setenv.sh
    java -version
    
  • Visit the Apache Tomcat manager application to check the Java version currently running. You should see a "Server Information" section similar to the one below

Additionally, you can modify the /home/bitnami/.bashrc file for the new environment to be automatically loaded every time that you connect to your server by adding the line below to the end of the file

    . /opt/bitnami/scripts/setenv.sh

Best regards,

Gonzalo

Discussions

Downgrade java from version 8 to 7 - Stack Overflow
I have installed Java 1.8 from Oracle on Ubuntu because I though it would be best, newest version compatible with previous ones. But it is not. javac 1.8 produces bytecode runnable only on the java-8- More on stackoverflow.com
๐ŸŒ stackoverflow.com
April 27, 2014
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 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
linux - How can I change Java version 1.7 to 1.8 in Ubuntu? - Stack Overflow
My Ubuntu machine have installed both java 1.7 and 1.8. But when I checked Java version it shows version Java 1.7 as the snapshot below. When I check Java alternative version I can see "java-8- 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 - Their current build needs Java 8 to work. I followed various instructions online as to how to do this but none of them work: http://tipsonubuntu.com/2016/07/31/inst ... x-mint-18/ Is there not a simple way using the Package Manager to downgrade Java version? Thanks! Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
๐ŸŒ
Ubuntu Shell
ubuntushell.com โ€บ change-java-version
How to Change Java Version on Ubuntu (CLI and GUI)
November 16, 2025 - Discover a step-by-step guide to change the default version of Java using the CLI and GUI methods on the Ubuntu system.
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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
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 ๐Ÿ‘๐Ÿป

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
๐ŸŒ
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.
๐ŸŒ
Gitopscentral
gitopscentral.in โ€บ how-to-downgrade-java-on-ubuntu-kali-linux
How to downgrade java on ubuntu/kali linux ยซ GitopsCentral
sudo apt-get update sudo apt-get install openjdk-8-jdk ยท This will install java jdk8, but we need to make a selection for default version of java among the existing versions i.e; between jdk10 & jdk8.
๐ŸŒ
Red Hat
access.redhat.com โ€บ solutions โ€บ 29617
How to use yum/dnf to downgrade or rollback some package updates? - Red Hat Customer Portal
May 1, 2025 - Thus, downgrading a system to minor version (ex: RHEL8.5 to RHEL8.4 or RHEL7.9 to RHEL7.8) is not recommended as this might leave the system in an undesired state. If this operation is attempted, it is strongly recommended to only do so with working system backups in place. In general, use the yum history option is intended for small update rollbacks. Please read the following guides for additional information: How to use yum history to roll back an update in Red Hat Enterprise Linux?