Assuming you use bash shell and installed Java with the Oracle installer, you could add the following to your .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home) export PATH=$JAVA_HOME/jre/bin:$PATH
This would pick the correct JAVA_HOME
as defined by the Oracle installer and will set it first in your $PATH
making sure it is found.
Also, you don’t need to change it later when updating Java.
EDIT
As per the comments:
Making it persistent after a reboot
Just add those lines in the shell configuration file. (Assuming it’s bash
)
Ex: .bashrc
, .bash_profile
or .profile
(for ubuntu)
Using a custom Java installation
Set JAVA_HOME
to the root folder of the custom Java installation path without the $()
.
Ex: JAVA_HOME=/opt/java/openjdk
Related Posts:
- Eclipse/Maven error: “No compiler is provided in this environment”
- How is “mvn clean install” different from “mvn install”?
- Lombok and Maven
- Why Maven project is tied to J2SE-1.5 by default?
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- Unable to create requested service [org.hibernate .engine.jdbc.env.spi.JdbcEnvironment]-MySQL
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- org.hibernate.HibernateException: Access to DialectResolutionInfo cannot be null when ‘hibernate.dialect’ not set
- unused import statement for used ones in IntelliJ IDEA
- Maven: Failed to read artifact descriptor
- What exactly is a Maven Snapshot and why do we need it?
- Cannot change version of project facet Dynamic Web Module to 3.0?
- Spring Maven clean error – The requested profile “pom.xml” could not be activated because it does not exist
- Maven error : Could not find or load main class org.codehaus.plexus.classworlds.launcher.Launcher
- JAVA_HOME should point to a JDK not a JRE
- No compiler is provided in this environment. Perhaps you are running on a JRE rather than a JDK?
- How are “mvn clean package” and “mvn clean install” different?
- java.lang.VerifyError: Inconsistent stackmap frames at branch target 421
- How to resolve Unable to load authentication plugin ‘caching_sha2_password’ issue
- “The import org.springframework cannot be resolved.”
- How to set JAVA_HOME in Linux for all users
- “Source folder is not a Java project” error in eclipse
- Configure active profile in SpringBoot via Maven
- Maven build Compilation error : Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project Maven
- Maven dependency update on commandline
- Could not transfer artifact org.apache.maven.plugins:maven-surefire-plugin:pom:2.7.1 from/to central (http://repo1.maven.org/maven2)
- How do I enable index downloads in Eclipse for Maven dependency search?
- Problem with gif with transparent background
- Search for words with telephone numbers from 2-3-4 tree
- Difference between Inheritance and Composition
- What is the reason behind “non-static method cannot be referenced from a static context”? [duplicate]
- Java string to date conversion
- Creating a “logical exclusive or” operator in Java
- Cannot make a static reference to the non-static method fxn(int) from the type Two [duplicate]
- How can I use pointers in Java?
- JavaFX – Exception in Application start method?
- What is IllegalStateException?
- Long vs Integer, long vs int, what to use and when?
- Java Using Nodes with LinkedList
- When is the @JsonProperty property used and what is it used for?
- Why is there no SortedList in Java?
- How does a Breadth-First Search work when looking for Shortest Path?
- Java: using switch statement with enum under subclass
- Java way to check if a string is palindrome
- No String-argument constructor/factory method to deserialize from String value (”)
- Where can i get BigClip? [closed]
- What is the /= operator in Java?
- Gradle does not find tools.jar
- Constructor cannot be applied to given types?
- How to use VisibleForTesting for pure JUnit tests
- What is the easiest/best/most correct way to iterate through the characters of a string in Java?
- How can I list the available Cipher algorithms?
- ADK vs JDK vs SDK difference?
- round up to 2 decimal places in java?
- com.sun.jdi.InvocationException occurred invoking method
- How can I check whether an array is null / empty?
- How to solve javax.net.ssl.SSLHandshakeException Error?
- org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name ‘demoRestController’
- What causes java.lang.IncompatibleClassChangeError?
- Add an object to an Array of a custom class
- What does java.lang.Thread.interrupt() do?
- Missing method body, or declare abstract in Java
- java code is showing error. ( ‘;’,expected) [closed]
- How can I edit a .jar file?
- java.lang.ClassNotFoundException: sun.jdbc.odbc.JdbcOdbcDriver Exception occurring. Why?
- This Activity already has an action bar supplied by the window decor?
- Convert hex string to int
- Orphaned Case Error in Java
- Proxy Error 502 : The proxy server received an invalid response from an upstream server
- Java double.MAX_VALUE?
- how to do a system pause in java for debugging?
- Immutable class?
- Regular Expressions on Punctuation
- How to make a countdown timer in Java
- (Java) Tic-Tac-Toe game using 2 dimensional Array
- Incompatible types List of List and ArrayList of ArrayList
- Dice Rolling java program
- int cannot be converted to int []
- Joda DateTime to Timestamp conversion
- break statement in “if else” – java
- Why use getters and setters/accessors?
- How to use a Do-while loop that continuously prompts a user?
- Java equivalent of unsigned long long?
- Getting “unixtime” in Java
- How do I break out of nested loops in Java?
- How do I convert this for loop into a while loop?
- Java switch statement: Constant expression required, but it IS constant
- Resolving File paths – ‘File not found’ error in Eclipse
- Simple Coin Toss using random class in Java. The do while loop doesn’t seem to generate random results
- What’s so special about 0x7f?
- Append a single character to a string or char array in java?
- Preventing a Java class from being instantiated and inherited
- Collision Detection between two images in Java
- What does .pack() do?
- String is immutable. What exactly is the meaning?
- How do I autoindent in Netbeans?
- What is an attribute in Java?
- MessageBodyWriter not found for media type=application/json
- Conversion from Long to Double in Java
- Failed to find Java VM