How to change java version on windows

Java on Windows: switching to a specific Java version/ runtime

This post show how to have multiple Java runtime environments on your PC and switch between them on Windows so that a particular program uses the version that you want it to.

Background

Due to Java SE Platform licensing changes by Oracle, developers have turned to alternatives such as OpenJDK. The AdoptOpenJDK site provides Prebuilt OpenJDK Binaries for Free (the main line on their landing page) and as you will see, there are numerous versions that you could use:

  • JDK 8 Long-term Support ( LTS )
  • JDK 11 LTS
  • JDK 16 (the latest)
  • Each of these could be 32-bit or 64-bit versions and you can choose the JVM that you run (Hotspot vs OpenJ9)

In short, there are options and there are times when you want to run something with a specific version of the JVM or you want to test something with multiple JVMs.

Installing and switching between multiple Java versions

The method that I follow is that I have a folder D:\apps where I put different applications tools that I want to use. Under this, I create a folder called jdk and use that as the main holding folder for all the different JDK / JVM that I want to use. I personally prefer not installin each JVM / JDK into my computer any more but to use them ‘without installation’.

Head on over to the releases page at AdoptOpenJDK to get the package you need. Start by changing the platform to Windows as shown below.

Next, pick the JDK (the full Java Development Kit) or the smaller JRE (Java Runtime Environment) and download the ZIP file version. Remember x86 means it’s the 32-bit version and x64 means that it’s the 64-bit version. If you have a modern (relatively new) Windows 10 PC, it’s almost certainly running the 64-bit version of Windows and will therefore support both the versions. In that case, the x64 is preferable though you may have some programs that don’t work correctly on the 64-bit version and need the 32-bit version.

Once you have downloaded the version (or versions) that you want to get, unzip the package. In my case, I unzip it to d:\apps\jdk so that I have all the JDKs/ JREs in one place. After unzipping, I change the folder names to be something like jdk-11.0.11_x64 and jdk-11.0.11_x86 so that I can easily tell which folder has the 64-bit and which one has the 32-bit.

Читайте также:  Stdclass to array php laravel

Running a program with Java basically requires you to do: $ java . and for this to work, it needs two things to be in place:

  • The Java version that you want to run must be the first Java installation on the path (so that Windows can find it)
  • The environment variable JAVA_HOME must be set to the installation that you want to use

So, for switching Java versions, you need to do this:

set JAVA_HOME=d:\apps\jdk\jdk-11.0.11_x86\ path=d:\apps\jdk\jdk-11.0.11_x86\bin;%PATH% 

The first line sets the JAVA_HOME and the second one moves the x86 version of the JDK / JRE to the path. Note that the JAVA_HOME points to the main directory where the whole installation is, and the path must be to the /bin folder under the JAVA_HOME so that java.exe can be found. After you do this, you should see this:

$ java -version openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9) OpenJDK Client VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode) 

To switch to a different version, you just need to set both those items correctly again. For example, in my case, I would do:

$ path=d:\apps\jdk\jdk-11.0.11_x64\bin;%PATH% $ set JAVA_HOME=d:\apps\jdk\jdk-11.0.11_x64\ $ java -version openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9) OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode) 

(Notice how the last line shows 64-Bit Server VM since it’s now running the 64-bit VM)

It’s not as convenient as using pik to switch Ruby versions on Windows but I imagine it would be a good idea to write something like pik for this. Also, I did not search if there are tools that let you do this easily but there might well be something.

That’s all there is to it. I noted this down mainly for myself since I need to do this occasionally. If it helps you, that’s great! Please leave a comment if there is something else that you think we should add into the post.

Источник

How to Change Java Version on Windows: Step-by-Step Guide

Learn how to easily switch between multiple versions of Java on Windows by setting the environment variable JAVA_HOME and configuring the Java Runtime Environment settings. Troubleshoot any issues that may arise with this step-by-step guide.

  • Setting the Environment Variable JAVA_HOME
  • Configuring the Java Runtime Environment Settings
  • How to switch between the multiple Java versions(JDK) in windows 10
  • Changing the JDK from the Command Line
  • Switching Java Versions on the Command Line
  • Troubleshooting Java on Windows
  • Other helpful code samples for changing Java version in terminal windows
  • Conclusion
  • How to change Java version via terminal?
  • How do I change Java from 1.8 to 11?
  • How to change Java_home in Windows 10 command prompt?
  • How do I check Java version in terminal windows?
Читайте также:  Java heap memory used to

Java is a popular programming language that has been used for many years. As technology continues to evolve, so does Java. This means that there are multiple versions of java available, and users may need to switch between them for different projects. In this blog post, we will provide a step-by-step guide on how to change the version of Java on Windows, either through the control panel or command line. We will also troubleshoot any issues that may arise during the process.

Setting the Environment Variable JAVA_HOME

The JAVA_HOME environment variable is used to specify the location of the Java Development Kit (JDK). This is necessary for the system to know where to look for the JDK when it is needed. Here are the steps to set the environment variable:

  1. Navigate to the System Properties window by right-clicking on “This PC” and selecting “Properties.”
  2. Click on the “Advanced system settings” link on the left side of the window.
  3. Click on the “Environment Variables” button at the bottom of the window.
  4. Under “System Variables,” click on “New” and enter “JAVA_HOME” as the variable name and the path to the JDK as the variable value.
  5. Click “OK” to save the changes and close the window.

Configuring the Java Runtime Environment Settings

The Java Runtime Environment (JRE ) is what allows Java programs to run on a computer. To configure the JRE settings, follow these steps:

  1. Navigate to the Java Control Panel in the Windows Control Panel.
  2. Click on the “Java” tab and then click on “View.”
  3. Users can then select the desired version of Java and click “OK” to save the changes.
  4. If the desired version of Java is not listed, users can click on “Add” and select the path to the JDK.

How to switch between the multiple Java versions(JDK) in windows 10

In this Video i am going to show how to switch or manage the multiple Java versions of jdk Duration: 2:19

Changing the JDK from the Command Line

Sometimes it may be necessary to change the JDK from the command line. Here are the steps to do this:

  1. Open the command prompt by pressing the Windows key + R and typing “cmd” in the Run box.
  2. Use the command “set path= ;%path%” to set the path to the new JDK and add it to the system’s path variable.
  3. Users can then confirm that the new version of Java is being used by typing “java -version” in the command prompt.

Switching Java Versions on the Command Line

The command “setjdk” can be used to switch Java versions on the command line. Here are the steps to do this:

  1. Download the setjdk script from the internet.
  2. Open the command prompt and navigate to the directory where the script is located.
  3. Run the command “setjdk ” to switch to the desired Java version.
Читайте также:  Центральная предельная теорема python

Additionally, a registry edit can be used to switch the JDK version on Windows 10 cmd. Here are the steps to do this:

  1. Open the registry editor by typing “regedit” in the search box.
  2. Navigate to “HKEY_LOCAL_MACHINE\SOFTWARE\JavaSoft\Java Development Kit.”
  3. Change the value of “CurrentVersion” to the desired version.

Troubleshooting Java on Windows

If users experience issues changing the Java version on Windows, they can troubleshoot by using the command “java -version” on the command prompt. If the correct version of Java is not being used, users can check the $PATH and CLASSPATH environment variables. Silent (unattended) Java installation can also be arranged using command-line installation and the base file name jre-8u05-windows-i586.exe.

Other helpful code samples for changing Java version in terminal windows

In Java , for instance, changer version java terminal code sample

 export JAVA_HOME=`/usr/libexec/java_home -v 1.8` 

Conclusion

Changing the version of Java on Windows can be done easily through the control panel or command line. By setting the environment variable JAVA_HOME and configuring the Java Runtime Environment settings, users can switch between multiple versions of Java. Troubleshooting can be done using the command “java -version” on the command prompt and by checking the $PATH and CLASSPATH environment variables. With this guide, users can effectively change the version of Java on their Windows operating system.

Источник

How to Change Java Runtime

wikiHow is a “wiki,” similar to Wikipedia, which means that many of our articles are co-written by multiple authors. To create this article, 9 people, some anonymous, worked to edit and improve it over time.

This article has been viewed 51,867 times.

Most of the time as java developer, one of the first thing you do to set up on you new computer is java environment. This is basically telling your cmd (windows) terminal (mac or Linux) where to find the java.

java / javac (the compiler) is all under your java installation directory.

We assume that you have successfully downloaded and installed the JDK or JRE. If you are a developer we suggest you to download the latest JDK (Java Developer Kit).

On Windows

Image titled Change Java Runtime Step 1

Image titled Change Java Runtime Step 2

Image titled Change Java Runtime Step 3

Image titled Change Java Runtime Step 4

Image titled Change Java Runtime Step 5

Image titled Change Java Runtime Step 6

Image titled Change Java Runtime Step 7

Image titled Change Java Runtime Step 8

Linux

Image titled Change Java Runtime Step 9

Image titled Change Java Runtime Step 10

Image titled Change Java Runtime Step 11

  • . .bash_profile or . .bashrc (note that you have a space) this tells your terminal to load the updated file in current terminal so you get the newly created java in your path

Image titled Change Java Runtime Step 12

Expert Q&A

Tips

You Might Also Like

Run a .Jar Java File

Check Your Java Version in the Windows Command Line

Use Easy Windows CMD Commands to Check Your Java Version

Set Java Home

How to Set JAVA_HOME for JDK & JRE: A Step-by-Step Guide

Do Division in Java

How to Do Division in Java (Integer and Floating Point)

Compile and Run Java Program by Notepad

How to Compile and Run Java Programs Using Notepad++

Источник

Оцените статью