Skip to main content
AI
  • Get started with AI

    • Red Hat AI

      Accelerate the development and deployment of enterprise AI solutions.

    • AI learning hub

      Explore learning materials and tools, organized by task.

    • AI interactive demos

      Click through scenarios with Red Hat AI, including training LLMs and more.

    • AI/ML learning paths

      Expand your Red Hat OpenShift AI knowledge using these learning resources.

    • AI quickstarts

      Focused AI use cases designed for fast deployment on Red Hat AI platforms.

    • No-cost AI training

      Foundational Red Hat AI training.

  • Featured resources

    • Red Hat OpenShift AI
    • Open source AI for developers
    • AI product application development
    • Open source-powered AI/ML for hybrid cloud
    • AI and Node.js cheat sheet

Red Hat AI Factory with NVIDIA

Red Hat AI Factory with NVIDIA is a co-engineered, enterprise-grade AI solution for building, deploying, and managing AI at scale across hybrid cloud environments.

Learn
  • Self-guided

    • Documentation

      Find answers, get step-by-step guidance, and learn how to use Red Hat products.

    • Learning paths

      Explore curated walkthroughs for common development tasks.

    • Guided learning

      Receive custom learning paths powered by our AI assistant.

    • See all learning
  • Hands-on

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

    • Interactive labs

      Learn by doing in these hands-on, browser-based experiences.

    • Interactive demos

      Click through product features in these guided tours.

  • Browse by topic

    • AI/ML
    • Automation
    • Java
    • Kubernetes
    • Linux
    • See all topics
  • Training & certifications

    • Courses and exams
    • Certifications
    • Skills assessments
    • Red Hat Academy
    • Learning subscription
    • Explore training
Build
  • Get started

    • Red Hat build of Podman Desktop

      A downloadable, local development hub to experiment with our products and builds.

    • Developer Sandbox

      Spin up Red Hat's products and technologies without setup or configuration.

  • Download products

    • Red Hat Enterprise Linux
    • Red Hat AI
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products
  • Featured

    • Red Hat build of OpenJDK
    • Red Hat JBoss Enterprise Application Platform
    • Red Hat OpenShift Dev Spaces
    • Red Hat Developer Toolset
  • References

    • E-books
    • Documentation
    • Cheat sheets
    • Architecture center
Community
  • Get involved

    • Events
    • Live AI events
    • Red Hat Summit
    • Red Hat Accelerators
    • Community discussions
  • Follow along

    • Articles & blogs
    • Developer newsletter
    • Videos
    • Github
  • Get help

    • Customer service
    • Customer support
    • Regional contacts
    • Find a partner

Join the Red Hat Developer program

Download Red Hat products and project builds, access support documentation, learning content, and more.

ConsoleDocsSupport Search
New For you

Recommended

We'll recommend resources you may like as you browse. Try these suggestions for now.

  • Product downloads
  • Cheat sheets
  • Red Hat Developer learning portal
  • Developer blog
  • E-books
  • Developer Sandbox
Log in

Get more with a Red Hat Developer account

  • Product downloads
  • Console access
  • Event registration
  • Training & trials
Explore more account benefitsLog in or register

A subscription may be required for some services.

Contact us

How to run the correct Java version after an update

January 9, 2023
Mohammadi Iram
Related topics:
Java
Related products:
Red Hat Enterprise Linux

    When you try to run a Java program after updating your system's version of Java, you are likely to receive an error message such as the following:

    mvn install
    The JAVA_HOME environment variable is not defined correctly
    This environment variable is needed to run this program
    NB: JAVA_HOME should point to a JDK not a JRE
    

    The source of the problem is probably the setting of your JAVA_HOME environment variable. This article shows you how to fix this problem.

    The reason for the error message

    Java programs need a Java Runtime Environment (JRE) to run. When you program with Java, the JRE is part of the Java Development Kit (JDK). The meanings of these terms follow:

    • Java Runtime Environment (JRE): Java source code is compiled and converted to Java bytecode. If you want to run this bytecode on your platform, you need the JRE to load and interpret the bytecode.
    • Java Development Kit (JDK): This includes a JRE along with a collection of software development tools and libraries to create Java programs that can run on the platform using the JRE.

    The importance of JAVA_HOME

    Your shell finds the proper Java environment through an environment variable called JAVA_HOME. It could point to either a JDK or a JRE. As the error message shown earlier indicates, you should point to your JDK if you have a JDK. When non-developers run Java, they don't need the entire JDK, so they can download a JRE and point JAVA_HOME to that. You can learn more about the Java platform components in the article, What is the Java Runtime Environment.

    When you upgrade Java, the system installs a new JDK, and you need to update JAVA_HOME to point to the new location.

    Environment variables used in the shell are generally defined in a start-up file. This file is located in your home directory and is called .bashrc if you use the Bash shell that is the default on Linux. Note the initial dot in the name .bashrc: this dot means that the file doesn't normally turn up when you display the contents of the directory.

    The .bashrc file is a script that runs when a user logs in. The file itself contains a series of commands to configure the terminal session.

    Check your .bashrc file to see whether it defines JAVA_HOME and what value is assigned to the environment variable. For instance, you can execute this command in the terminal:

    $ more ~/.bashrc

    The line defining JAVA_HOME in the output is as follows:

    export JAVA_HOME=/usr/lib/jvm/java-17-openjdk-17.0.4.1.1–1.fc35.x86_64

    You have to make sure that JAVA_HOME is set correctly, with version details.

    Choosing a JDK

    In the terminal on a Linux system, run the following command:

    $ sudo alternatives --config java

    The output displays the versions of Java currently on the system, as shown in Figure 1. The command also issues a prompt allowing you to choose a version.

    Choose the JDK you want.
    Figure 1: You can choose which JDK you want.

    The version you choose (3 in the figure) contains, within parentheses, a full pathname that you have to assign to your JAVA_HOME environment variable in your .bashrc file. After entering the number that you want to use, press the Enter key to finish the command.

    Updating .bashrc

    The next step is to check the value of JAVA_HOME (or add it, if it is not already present) in the .bashrc file. If .bashrc doesn't match the pathname you choose, you can copy the pathname from the terminal display and paste it into .bashrc as I'll show shortly.

    Figure 2 highlights the JDK path I selected in Figure 1.

    Shows the JDK selected: openjdk-17.0.5.0.8–2.fc35.x86_64.
    Figure 2: The white highlight shows the JDK we have selected on our system, openjdk-17.0.5.0.8–2.fc35.x86_64.

     

    Figure 3 highlights the JDK path in the JAVA_HOME setting in my current .bashrc file.

    Shows an old JDK: openjdk-17.0.4.1.1–1.fc35.x86_64.
    Figure 3: The .bashrc file expects an old JDK, openjdk-17.0.4.1.1–1.fc35.x86_64.

    The paths are different, so I need to update the environment variable in the .bashrc file to match the path offered by the system. Specifically, I need to change the JDK version in the path from openjdk-17.0.4.1.1–1.fc35.x86_64 to openjdk-17.0.5.0.8–2.fc35.x86_64.

    When you save your changes, .bashrc looks like Figure 4.

    Shows the updated .bashrc file.
    Figure 4: The .bashrc file is updated now to expect openjdk-17.0.5.0.8–2.fc35.x86_64.

    Updating the shell

    To reflect the changes in your shell, either close and launch the terminal again or use the following command:

    $ source ~/.bashrc

    In this way, you can easily update your JAVA_HOME environment variable and continue coding in Java.

    Related Posts

    • Install OpenJDK on Windows and Linux

    • Checkpointing Java from outside of Java

    • Introducing the Red Hat build of the OpenJDK Universal Base Images—now in Red Hat Enterprise Linux 8.2

    Recent Posts

    • A day in the life of an NVIDIA H100 on Red Hat OpenShift 5

    • Migrate BuildConfigs to builds for Red Hat OpenShift with one plug-in install

    • Run Red Hat Enterprise Linux CoreOS on NVIDIA BlueField DPUs

    • Agent harness engineering: Separating model capabilities from enforcement

    • What's new for developers in Red Hat Enterprise Linux 10.3 and 9.9

    What’s up next?

    The microservice architectural approach is more than just about technology: It reaches into the foundation of your organization to allow you to build truly scalable, adaptive, complex systems that help a business adapt to rapidly changing competitive markets. In Microservices for Java Developers, you'll get a hands-on introduction to frameworks and containers through a handful of familiar patterns.

    Get the e-book
    Red Hat Developers logo

    Platforms

    • Red Hat AI
    • Red Hat Enterprise Linux
    • Red Hat OpenShift
    • Red Hat Ansible Automation Platform
    • See all products

    Build

    • Developer Sandbox
    • Developer tools
    • Interactive tutorials
    • API catalog

    Quicklinks

    • Learning resources
    • E-books
    • Cheat sheets
    • Blog
    • Events
    • Newsletter

    Communicate

    • About us
    • Contact sales
    • Find a partner
    • Report a website issue
    • Site status dashboard
    • Report a security problem

    Red Hat Developer

    Build here. Go anywhere.

    We serve the builders. The problem solvers who create careers with code.

    Join us if you’re a developer, software engineer, web designer, front-end designer, UX designer, computer scientist, architect, tester, product manager, project manager or team lead.

    Sign me up

    Red Hat legal and privacy links

    • About Red Hat
    • Jobs
    • Events
    • Locations
    • Contact Red Hat
    • Red Hat Blog
    • Inclusion at Red Hat
    • Cool Stuff Store
    • Red Hat Summit
    © 2026 Red Hat

    Red Hat legal and privacy links

    • Privacy statement
    • Terms of use
    • All policies and guidelines
    • Digital accessibility
    Ask AI