2

this is the current image in terminal

I have been doing some research on how to install Java jre and jdk on correct PATH. I lack the comprehension when coming to understand what others would instruct on to change path in the terminal. even after several trial. I would still get an error.

How can I properly install Java and have it run so I can run my Java IDE.

7
  • 2
    Did you try just downloading the jdk dmg file and installing it? adoptopenjdk.net Commented May 18, 2020 at 17:44
  • 1
    There isn't much to research, so: how did you install it? (did you download it, if so where and how did you then process with that download; did you use homebrew; did you do something else...?) Commented May 18, 2020 at 17:45
  • I am trying to install eclipse. I do have jre install and jdk. Commented May 19, 2020 at 3:53
  • @Mike'Pomax'Kamermans I should have been more specific. I have no problem with windows, its just os x i have trouble with. I have macbook os x maverick, macbook late 2008, I can't get the el capitan os. I installed like any other programs. it never asked where to installed on to my macbook. Commented May 19, 2020 at 4:08
  • Can you check the output from ls -l /usr/bin/java. Since java_home works, I wonder if your 'java' simlink is pointed at the wrong thing or doesn't exist. Both can give you a command not found. Commented May 19, 2020 at 7:27

4 Answers 4

4

In 2022, you can use just brew

brew install openjdk

and maybe you need to update PATH env:

export PATH="/usr/local/opt/openjdk/bin:$PATH"

…and for the future give a try to sdkman, is better than brew

curl -s "https://get.sdkman.io" | bash

then open a new shell and try list to see what you could install ;-)

sdk list java 

At time of writing you could use:

sdk install java 17.0.1-tem
Sign up to request clarification or add additional context in comments.

Comments

3

I have been doing some research on how to install Java jre and jdk on correct PATH.

JRE has been discontinued since Java 11. Since you are talking about Java 14, there is no JRE for it. You just need to install (and configure, if required) JDK.

Use the following command and then check java -version:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home"
export PATH="$PATH:$JAVA_HOME/bin"

Note that it will work only for your current session i.e. java -version won't work in another terminal window.

To set JAVA_HOME permanently, do as follows:

$ cd ~
$ vi .bash_profile  

Write the following line into .bash_profile file, save and quit:

export JAVA_HOME="/Library/Java/JavaVirtualMachines/adoptopenjdk-14.jdk/Contents/Home"
export PATH="$PATH:$JAVA_HOME/bin"

Then refresh (read and execute .bash_profile)

$ source .bash_profile

And finally test

$ echo $JAVA_HOME
$ java -version

Note: Also, This thread may be useful to you.

Comments

1

Installer updates paths automatically

I have always found that after using an installer to install a Java implementation on macOS, the correct paths are already set for me. No additional configuration needed.

After the installer is done, in a terminal app run:

java --version

…to verify your newly installed Java implementation.

IDE uses its own JVM

You said:

have it run so I can run my Java IDE.

Be aware that some IDEs such as IntelliJ come bundled with their own Java implementation. So your downloaded JVM would not actually be running your IDE. This internal JVM is used to run the IDE itself.

This JVM could be used to run your app in development, as I recall. But you likely will want to download and install a JVM of a version (and possibly vendor) akin to what will be used in production.

Within your IDE settings, project settings, and build-tool settings (Maven, Gradle, etc.), you can tell the IDE what external JVM to use to run your app. Meanwhile the IDE continues to run itself using its own internally-bundled JVM.


Here is a flowchart I made to help explain the various implementations. All but the last two of these vendors likely provide an installer app for your Mac.

If you have no reason to choose a particular vendor, I suggest using AdoptOpenJDK, a cooperative effort supported by many in the Java community including most (if not all) of these vendors listed here.

For more info, read the important posting: Java Is Still Free.

Flowchart guiding you in choosing a vendor for a Java 11 implementation

Comments

0

The easiest way to determine what java installations you currently have installed is by running:

/usr/libexec/java_home

This will return the default Java jdk you currently have installed. You could also run:

java -v

Which will show you the current version of the first JDK that your path encounters.

If you would like to view all Java JDK versions that you have installed, you can run the first command mentioned with the -V (verbose) flag, and it will list the paths to all you have installed.

If you have multiple versions installed, you can amend your $PATH variable inside either .bashrc or .bash_profile. (Note these are the files for my system, macOS, but the profile files may be different for Linux installations, I simply do not know). There is a convention you can read about regarding where you should do it.

Quite simply, if the version you do NOT want is the one that appears when you run java -v or which java then you must add the path to the desired JDK to your $PATH as mentioned.

In order to view your current path, you can run echo $PATH

In order to amend your path you will add a command similar to the following to one of the bash profile files for your system:

export PATH=$PATH:/[NEW_PATH]

or

export PATH=[DESIRED_PATH]:$PATH

The first command adds to the end of your path, the second adds to the beginning.

Most likely you may want to add the path to your desired JDK in the beginning of your existing $PATH variable.

Obviously, be very careful with changing your path, you don't want other programs to break, so make sure you simply add the desired JDK path in front of your original variable, so that the only related program, java, has a change.

6 Comments

This is a big post for not having a clue what the user tried. I'll be impressed if it helps.
I had the time, if they have more specifics they can always ask or input. Maybe it'll help someone other than the poster.
the issue is when i check for java -version, I got command not found. the only java I have installed is the jdk 14.01 and the recent java jre 8.251
Please make sure you are running either java -v or java --version . If you use a whole word flag with a single dash it will not work.
@antong either one provided me with a version. it say "command not found"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.