Apt-get won't overwrite the existing java versions.
To switch between installed java versions, use the update-java-alternatives command.
List all java versions:
update-java-alternatives --list
Set java version as default (needs root permissions):
sudo update-java-alternatives --set /path/to/java/version
...where /path/to/java/version is one of those listed by the previous command (e.g. /usr/lib/jvm/java-7-openjdk-amd64).
Additional information:
update-java-alternatives is a convenience tool that uses Debian's alternatives system (update-alternatives) to set a bunch of links to the specified java version (e.g. java, javac, ...).
Apt-get won't overwrite the existing java versions.
To switch between installed java versions, use the update-java-alternatives command.
List all java versions:
update-java-alternatives --list
Set java version as default (needs root permissions):
sudo update-java-alternatives --set /path/to/java/version
...where /path/to/java/version is one of those listed by the previous command (e.g. /usr/lib/jvm/java-7-openjdk-amd64).
Additional information:
update-java-alternatives is a convenience tool that uses Debian's alternatives system (update-alternatives) to set a bunch of links to the specified java version (e.g. java, javac, ...).
Use
sudo update-alternatives --config java
which lists all installed versions with current active one marked and provides dialog to switch:
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path...
------------------------------------------------------------
0 /usr/lib/jvm/java-9-oracle/bin/java...
* 1 /usr/lib/jvm/java-7-oracle/jre/bin/java...
2 /usr/lib/jvm/java-8-oracle/jre/bin/java...
3 /usr/lib/jvm/java-9-oracle/bin/java...
Press <enter> to keep...[*], or type selection number:
Use
export JAVA_HOME="$(jrunscript -e 'java.lang.System.out.println(java.lang.System.getProperty("java.home"));')"
to set $JAVA_HOME from current active version
Noob question. How do I update to Java 22 via terminal?
How do I switch between Java versions?
How do I change default version of java from my terminal?
how can I change the default Java version?
Videos
You can use SDKMan which allow us to do the same, SDKMan is a free to use open-sourced tool which helps us to install and manage parallel versions of around 29 Software Development Kits such as Java, Groovy, Scala, Kotlin and Ceylon. Ant, Gradle, Grails, Maven, SBT, Spark, Spring Boot, Vert.x.
And it also sets the _HOME and PATH environment variables automatically.
You can install SDKMan by running below commands
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
You can list all versions of Java using
$ sdk list java
And you can install different-different Java versions using sdk install command
e.g.
$ sdk install java 9.0.4-open
$ sdk install java 11.0.2-open
And you can switch between them using sdk use and sdk default commands, You can read more about it on my blog How to Install Multiple Versions of Java on the Same Machine.
I type all command in sudo mode
I just remove the link to the current java binary in my system
rm /etc/alternatives/java
Then I set the link to the new binary I want to use
ln -s /usr/lib/jvm/java-17-openjdk-amd64/bin/java /etc/alternatives/java
Re your first question:
possibly you may be confusing that the webupd8 script is 0.5b. That is the version of the script - it doesnt refer to the java version.
Further to the setting of the javac version.
I suspect you need to explicitly give the path of the javac compiler
i.e.
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-6.31-oracle/bin/javac" 1
followed by:
sudo update-alternatives --config javac
With regards to setting up the java chrome plugin.
The master question:
How do I install Oracle JDK 6?
includes this information - since your folder structure is slightly different your link command should be:
ln -s /usr/lib/jvm/java-6.31-oracle/jre/lib/i386/libnpjp2.so ~/.mozilla/plugins/
See this; run
sudo update-java-alternatives --list
to list off all the Java installations on a machine by name and directory, and then run
sudo update-java-alternatives --set [JDK/JRE name e.g. java-8-oracle]
to choose which JRE/JDK to use.
If you want to use different JDKs/JREs for each Java task, you can run update-alternatives to configure one java executable at a time; you can run
sudo update-alternatives --config java[Tab]
to see the Java commands that can be configured (java, javac, javah, javaws, etc). And then
sudo update-alternatives --config [javac|java|javadoc|etc.]
will associate that Java task/command to a particular JDK/JRE.
You may also need to set JAVA_HOME for some applications: from this answer you can use
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:bin/java::")
for JREs, or
export JAVA_HOME=$(readlink -f /usr/bin/java | sed "s:jre/bin/java::")
for JDKs.
SOLVED. Thanks!
Version Ubuntu 24.04.03 LTS, currently on Java 21, need 22 for my Minecraft server but sudo apt install openjdk-22-jdk gives error, unable to locate package. Just apt update just gives you version 21 as that's what seems to be on Ubuntu rn.
I suspect I need to download whatever .tar.gz for java, send it over via FTP, SSH back in and run it somehow but I haven't actually done that before and am not that technically savvy so hoping someone has a clearer tutorial then Google being like just reinstall Ubuntu so there's a GUI.