Jump to content
  • How To Select Which Version of Java to Use in Linux (+ Video Tutorial)

    aum

    • 297 views
    • 2 minutes
     Share


    • 297 views
    • 2 minutes

    Which version of Java should you use in Linux? Learn how to easily switch between different versions with a tutorial from Jack Wallen.

     

     

    You will probably come across a situation where you have to work with different versions of Java; when Linux is your development platform, you can easily switch between them. For instance, if a project requires Java 17, you can switch to that. When your next project requires Java 18, you can quickly make the switch. Let me show you how.

     

    First, we’re going to install Java 17 and Java 18, so you can see how the switching is done.

     

    1.  To install Java 17, open a terminal window and issue this command:


    sudo apt-get install openjdk-17-jdk openjdk-17-jre -y


    2.  After that installation completes, let’s install Java 18 with this command:


    sudo apt-get install openjdk-18-jdk -y


    Now Java 17 and Java 18 are installed on your machine, ready to help you build your projects.

     

    3.  To switch between Java versions, issue this command:


    update-alternatives --config java


    This will present you with a list of the different versions of Java you have installed. Each version will be associated with a number, starting with 0.

     

    4.  If you want to switch to Java 18, locate and type the associated number for Java 18 and hit Enter on your keyboard. The system will set Java 18 as the current version. You can verify the switch with the following command, where you should see Java 18 listed:


    java --version


    And that’s all there is to switching between versions of Java on Linux. You can install as many versions as you like and switch between them for different projects on the fly.

     

    Source


    User Feedback

    Recommended Comments

    There are no comments to display.



    Join the conversation

    You can post now and register later. If you have an account, sign in now to post with your account.
    Note: Your post will require moderator approval before it will be visible.

    Guest
    Add a comment...

    ×   Pasted as rich text.   Paste as plain text instead

      Only 75 emoji are allowed.

    ×   Your link has been automatically embedded.   Display as a link instead

    ×   Your previous content has been restored.   Clear editor

    ×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...