Java19 to java 17 lts in mac M1 using brew - java

I installed openjdk19 by brew install java
I want to uninstall this version and reinstall openjdk 17 lts version
how to do that?

to uninstall package you can use one of the commands:
brew uninstall packageName
in your case:
brew uninstall java
The remove Homebrew package command looks like this:
brew remove packageName
in your case:
brew remove java
To install java 17, it is necessary to add version:
brew install openjdk#17
Here is brew documentation how to do it:
Homebrew doc
And also there is answer how to install Java 17 :
macOS - How to install Java 17

what Rustam suggested you is the right thing. I wanted to add that you can use jenv for having more than one java installed and easy switching of the java versions instead of removing it. You can setup global or local (folder specific) java version.
You can find more information here https://www.jenv.be/
Basically
brew install jenv
echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(jenv init -)"' >> ~/.zshrc
List the versions you have
jenv versions
system
1.8
17.0
* 11.0
11.0.11
openjdk64-1.8.0.292
openjdk64-17.0.11
After that you can choose one from the installed using this command
jenv global openjdk64-17.0.11

Related

How to brew install java?

I'd like to setup java on a new OS X machine, and prefer to use brew for OS X package management. How can I install latest java using brew?
Turns out java has been moved into brew core recently, so the correct command as of August 2022 is:
brew install java
Then check your installation by running
java --version
If the result does not looks like this:
openjdk 18.0.2 2022-07-19
OpenJDK Runtime Environment Homebrew (build 18.0.2+0)
OpenJDK 64-Bit Server VM Homebrew (build 18.0.2+0, mixed mode, sharing)
but like this:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
Then you also need to create a symlink for the system Java wrappers to find this JDK:
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk.jdk
As an add-on to the accepted answer: to install a certain version of Java, e.g. version 11, run:
brew install openjdk#11
And symlink it:
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk \
/Library/Java/JavaVirtualMachines/openjdk-11.jdk
I had to sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
If you want to install the Oracle version of java's SDK with homebrew, use the following command:
brew install --cask oracle-jdk
If you don't care, then use the accepted answer by #Tim Fulmer to get the OpenJDK version
brew install java
run
brew reinstall openjdk
and it will display the following which shows your file path:
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
openjdk is keg-only, which means it was not symlinked into /usr/local,
because macOS provides similar software and installing this software in
parallel can cause all kinds of trouble.
If you need to have openjdk first in your PATH, run:
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> /Users/gerarddonnelly/.bash_profile
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
I then ran the code below, which I took from the output above:
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
The other issue I had was that Elasticsearch was not recognising my JAVA version. To fix that I added the following line to my .bash_profile
EXPORT JAVA_HOME=$(/usr/libexec/java_home)
then I ran
source ~/.bash_profile
to refresh my profile.
After that it worked.
Hope this helps.
Assembled from the answers here and How to set or change the default Java (JDK) version on macOS?:
You can use brew to install multiple java versions and run a command to switch between the versions as required.
Example
Install two java versions (change java versions as pleased):
brew install openjdk#19
brew install openjdk#8
Use the following command to see the installed versions:
/usr/libexec/java_home -V
you should see the two versions specified in the response (if not, read further to create a symlink). Now you can select the java version using:
export JAVA_HOME=`/usr/libexec/java_home -v 8`
verify selected version:
java -version
you can further export the JAVA_HOME variable in your shell init file as speciifed in the attached SOF thread.
Now, in case you do not see the java version in /usr/libexec/java_home as expected and the version selection of that missing version is not working, you might need to add a symlink:
Executing brew info openjdk#the-missing-java-versionshould return the location of the installed version and will specify a symlink command that you should run for the system to find the SDK. The response text look something similar to:
...For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#17/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-17.jdk...

How to install specific Java version using Homebrew?

I am looking to install Java on Mac using Homebrew. This works fine using the command
brew cask install java.This installs the latest stable version which is currently - 1.8.0_141
However how can I install a specific version for example 1.8.0_131.
Install homebrew
/usr/bin/ruby -e "$(curl -fsSL
https://raw.githubusercontent.com/Homebrew/install/master/install)"
Update homebrew if already installed:
brew update
allow brew to lookup versions
brew tap homebrew/cask-versions
list available java versions
brew search java
Optional: to find out the minor version of java
brew info --cask java8
install java 8 (or any other version available)
brew install --cask java8
Raising Sean Breckenridge's comment as an answer to increase visibility:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew tap homebrew/cask-versions
brew cask install homebrew/cask-versions/adoptopenjdk8
There is no longer cask named "java8".
run brew update command make sure that brew is update to date.
then check brew by following command... to make sure brew works fine
brew doctor
if its has any issue you have to fix that first ...
Then if you want to install specific version run following command ..
brew install java11
in my case it's java11 you can check java available version on java website.
Then go for location
/Library/Java/JavaVirtualMachines/openjdk-11.jdk
and make sure jdk file is there...
if there is not any folder just run the following command in terminal...
sudo ln -sfn /usr/local/opt/openjdk#11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
change the version after #11 according to your required jdk version. its gonna tell system about java runtime.
you can check java version by following command.
java --version

Even though JRE 8 is installed on my MAC -" No Java Runtime present,requesting to install " gets displayed in terminal

Even though JRE 8 is installed on my MAC OS Yosemite 10.10.3,while running the Android present in tools in sdk - the error - " No Java Runtime present,requesting to install " gets displayed in terminal- how do i solve this issue?
I wanted to install Xamarin test recorder - after installing they
asked me to install Android sdk
SDK is downloaded in Library/Developer/Xamarin/android-sdk
Now when I run Android present in tools folder - I get the error -
No Java run time
I've installed JRE 8 with get the verified
java version from their site
Can someone please help!!
You have to install the full JDK, not only the JRE.
I had the same issue and solved by installing JDK.
Please use this link to download the latest JDK version 19.
After installing openjdk with brew and runnning brew info openjdk I got this
And from that I got this command here, and after running it I got Java working
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
2021 solution
TL;DR
brew install temurin
Details
On an M1 Mac/Apple Silicon (running Big Sur), I had already openjdk installed. As signaled in a previous answer by Mohammed, openjdk is keg-only with brew, and hence requires adding a symlink.
After following this, it solved the No Java Runtime present error, but rJava was complaining about missing libjvm.dylib and that existing libraries were for the wrong architecture:
.onLoad failed in loadNamespace() for 'rJava', details:
call: dyn.load(jvm, FALSE)
error: unable to load shared object '/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib':
dlopen(/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib, 10):
no suitable image found. Did find:
/opt/homebrew/Cellar/openjdk/16.0.2/libexec/openjdk.jdk/Contents/Home/lib/server/libjvm.dylib:
mach-o, but wrong architecture
Installing Eclipse Temurin (previously AdoptOpenJDK) (and removing the previously created symlink in /Library/Java/JavaVirtualMachines/openjdk.jdk) immediately solved both issues seamlessly.
Just run brew install temurin and everything should be OK.
I didn't need the full JDK, I just needed to make JRE work and none of the other answers provided above worked for me.
Maybe it used to work, but now (1st Jul 2018) it isn't working. I just kept getting the error and the pop-up.
I eventually solved this issue by placing the following JAVA_HOME export in ~/.bash_profile:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
Hope this helps someone.
I'm running Mac OS High Sierra.
I just had to do the following on Mac:
brew install openjdk
sudo ln -sfn /opt/homebrew/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
export JAVA_HOME="/Library/Java/JavaVirtualMachines/openjdk.jdk/Contents/Home"
java --version
If you came across the error when tried to generate a jks file (keystore), so try adding
/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool
before running the command, like so:
/Applications/Android\ Studio.app/Contents/jre/Contents/Home/bin/keytool -genkey -v -keystore ~/key.jks -keyalg RSA -keysize 2048 -validity 10000 -alias key
Since it sounds like your JAVA_HOME variable is not set correctly, follow the instructions for setting that.
Setting JAVA_HOME environment variable on MAC OSX 10.9
I would imagine once you set this, it will stop complaining.
Maybe someone is still having the same issue. You can install openjdk using homebrew, and then add the new JDK bin directory to the front of your path:
cd ~
brew install openjdk
echo 'export PATH="/usr/local/opt/openjdk/bin:$PATH"' >> .bash_profile
source .bash_profile
Pre-Requisite:
I already had java11 installed on my machine using brew.
Step-1: brew info java11
output:
/opt/homebrew/Cellar/openjdk#11
USER1-MacBook-Pro JavaVirtualMachines % brew info java11
openjdk#11: stable 11.0.12 (bottled) [keg-only]
Development kit for the Java programming language
https://openjdk.java.net/
/opt/homebrew/Cellar/openjdk#11/11.0.12 (670 files, 273.0MB)
Poured from bottle on 2021-10-09 at 13:07:04
From: https://github.com/Homebrew/homebrew-core/blob/HEAD/Formula/openjdk#11.rb
License: GPL-2.0-only
==> Dependencies
Build: autoconf ✔
==> Requirements
Build: Xcode ✘
==> Caveats
For the system Java wrappers to find this JDK, symlink it with
sudo ln -sfn /opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk-11.jdk
openjdk#11 is keg-only, which means it was not symlinked into /opt/homebrew,
because this is an alternate version of another formula.
If you need to have openjdk#11 first in your PATH, run:
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
For compilers to find openjdk#11 you may need to set:
export CPPFLAGS="-I/opt/homebrew/opt/openjdk#11/include"
==> Analytics
install: 44,188 (30 days), 149,578 (90 days), 433,845 (365 days)
install-on-request: 19,074 (30 days), 63,262 (90 days), 187,286 (365 days)
build-error: 0 (30 days)
Step-2: Append openJDK path to existing path.
echo 'export PATH="/opt/homebrew/opt/openjdk#11/bin:$PATH"' >> ~/.zshrc
Step-3: Source existing shell or open new terminal to validate changes
source ~/.zshrc
Step-4: Check path is added
which java
output: /opt/homebrew/opt/openjdk#11/bin/java
Step-5:
java --version
openjdk 11.0.12 2021-07-20
OpenJDK Runtime Environment Homebrew (build 11.0.12+0)
OpenJDK 64-Bit Server VM Homebrew (build 11.0.12+0, mixed mode)
working by following command
export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"
TL;DR
For JDK 11 try this:
To handle this problem in a clean way, I suggest to use brew and jenv.
For Java 11 follow this 2 steps, first :
JAVA_VERSION=11
brew reinstall jenv
brew reinstall openjdk#${JAVA_VERSION}
jenv add /usr/local/opt/openjdk#${JAVA_VERSION}/
jenv global ${JAVA_VERSION}
And add this at end of your shell config scripts ~/.bashrc or ~/.zshrc
export PATH="$HOME/.jenv/bin:$PATH"
eval "$(jenv init -)"
export JAVA_HOME="$HOME/.jenv/versions/`jenv version-name`"
Problem solved!
Then restart your shell and try to execute java -version
Note: If you have this problem, your current JDK version is not existent or misconfigured (or may be you have only JRE).
In 2022:
No need to download Java anymore, once Android Studio is installed.
Even though Java 11 is embedded with Android Studio now, on Mac sometimes this problem arises and the Java runtime is not found.
So, I have solved this problem by doing these two steps:
In Android Studio go to File > Project Structure. If, under the SDK entry, you can see there is no default SDK selected, but a text in red "No SDK", click on it and you will find an SDK / JDK list, select one of them. Thats it.
Make sure you run Android Studio from Application Folder.
For this copy the Android Studio launcher to the Application folder. Then in the Finder, go to the Application folder. Right-click on it. Click on "Show package contents", then navigate up to jre folder. Copy the folder and paste it into your home folder.
Now setup the path from the terminal: you can create a folder named java_jre, and the path must be set to jre/contents/Home :
Noors-Mac-mini:bin noorhossain$ export JAVA_HOME="/Users/noorhossain/java_jre/jre/Contents/Home"
// now checking the version :
Noors-Mac-mini:bin noorhossain$ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
I solved the problem by installing oracle-sdk with brew.
brew install oracle-jdk --cask
In 2022, only if Android studio is installed:
Check if JDK is installed in Android studio. In Android Studio go to File > Project Structure. Under the SDK entry, if there is no default JDK selected, select from the list, or if there isn't any, add JDK and then apply to install.
After the JDK is installed in Android studio, you just need to add the JDK path directly from your Android Studio. Run the below command in the terminal and that's it.
echo 'export JAVA_HOME="/Applications/Android Studio.app/Contents/jre/Contents/Home"' >> ~/.zshrc
Now, check if it's working.
❯ java -version
openjdk version "11.0.11" 2021-04-20
OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
OpenJDK 64-Bit Server VM (build 11.0.11+0-b60-7772763, mixed mode)
No need to install any package from brew or create any symlink. The Java is already embedded with the Android studio and we can use this directly for our system.
In newer versions of OS X (especially Yosemite, EL Capitan), Apple has removed Java support for security reasons.
To fix this you have to do the following.
Download Java for OS X 2015-001 from this link: https://support.apple.com/kb/dl1572?locale=en_US
Mount the disk image file and install Java 6 runtime for OS X.
After this you should not be seeing any of the below messages:
- Unable to find any JVMs matching version "(null)"
- No Java runtime present, try --request to install.
This should resolve the issue for the pop-up shown below:
Below is worked for me on macos mojave 10.14.6 version
I installed current jdk(https://www.oracle.com/java/technologies/javase-downloads.html)
Then do respectively;
vim .bash_profile
add "export JAVA_HOME=$(/usr/libexec/java_home)" to bash_profile
source .bash_profile
it is done. And you can check the version with java -version command.
If you are having this issue for the same reason that I am, I can tell you why it is happening. I just don't know how to fix it yet.
Here it is:
I am using JDK version 1.8 on MacOS Big Sur. I do not want to have to install a later version of the JDK because all my projects run on 1.8. But here's the thing.... On the command line
java -version
Returns this:
openjdk version "1.8.0_302"
OpenJDK Runtime Environment (build 1.8.0_302-bre_2021_08_14_21_34-b00)
OpenJDK 64-Bit Server VM (build 25.302-b00, mixed mode)
but a slightly different command (version prefixed with 2 dashes instead of 1)
java --version
returns this error:
Unrecognized option: --version
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This is because Java 8 uses single dash version, all JDKs after use double dash.
So the machine, when looking for JAVA_HOME, is also using double dashes and getting the error.
just run this
sudo ln -sfn /usr/local/opt/openjdk/libexec/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
I have Mojave 10.14.6 and the only thing that did work for me was:
setting JAVA_HOME to the following:
export JAVA_HOME=/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home
source .bash_profile (or wherever you keep your vars, in my case .zshrc)
Hope it helps! You can now type java --version and it should work
It's worth noting that with my current version of SQLDeveloper (21.2.1), there's another way to specify the JDK location. In my case, I was able to open up ~/.sqldeveloper/21.2.1/product.conf and set the JavaHome directive to the appropriate directory. I use jabba for JDK version management, and this path was something like ~/.jabba/jdk/amazon-corretto#1.8.292-10.1/Contents/Home. Needless to say, just setting that config value and restarting SQLDeveloper left me with a running copy again. This should work with any version of SQLDeveloper given the product.conf file exists inside your user's .sqldeveloper directory appropriate for the version you are using.
install JDK it will work ,
here is the jdk link to download .
link: https://www.oracle.com/technetwork/java/javase/downloads/jdk13-downloads-
5672538.html

I install java7 and java8 using Jenv. Then, run "jenv global oracle64-1.8.0.121", I get error saying that it's not installed

On my Mac-pro OS-X Yosemite, I install java7 and java8 using Jenv.
$ brew cask install java8
$ brew cask install java7
Then execute the "jenv add" commands as followed for each java:
$ sudo jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home/
oracle64-1.7.0.80 added
I can see both at /Users/xxxxx/.jenv/versions
$ ls -lrt
lrwxr-xr-x 1 root staff 64 Feb 1 13:42 oracle64-1.8.0.121 ->
/Library/Java/JavaVirtualMachines/jdk1.8.0_121.jdk/Contents/Home
lrwxr-xr-x 1 root staff 63 Feb 1 13:49 oracle64-1.7.0.80 ->
/Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk/Contents/Home
But when I try to set java8 as global, it says that java8 is not installed.
$ jenv global oracle64-1.8.0.121
jenv: version `oracle64-1.8.0.121' not installed
Did I miss anything here? How can I fix this issue?
I have the same problem. I solved this by edited the file /Users/[YourName]/.java-version myself. For example, I entered oracle64-1.8.0.121 as the first line in this file.
For me, I discovered that jenv creates soft links for various 'versions' it controls, but it wouldn't create the soft link without the .0. So if something wants java 11, and my team somehow uses 11 as the jenv version, I wouldn't have 11... I would have 11.0
I resolved this by adding a soft link for the number I needed under:
~/Users/<my_home>/.jenv/versions
Use following steps
depoddar-mac:inbound depoddar$ jenv versions
* system (set by /Users/depoddar/.jenv/version)
1.7
1.7.0.80
1.8
1.8.0.333
11.0
11.0.15
17.0
17.0.3
openjdk64-11.0.15
openjdk64-17.0.3
oracle64-1.7.0.80
oracle64-1.8.0.333
depoddar-mac:inbound depoddar$ jenv global oracle64-1.8.0.333
depoddar-mac:inbound depoddar$ jenv version
oracle64-1.8.0.333 (set by /Users/depoddar/.jenv/version)
depoddar-mac:inbound depoddar$ jenv versions
system
1.7
1.7.0.80
1.8
1.8.0.333
11.0
11.0.15
17.0
17.0.3
openjdk64-11.0.15
openjdk64-17.0.3
oracle64-1.7.0.80
* oracle64-1.8.0.333 (set by /Users/depoddar/.jenv/version)
For the new viewers who are struggling to install/set java 8 in jenv :
can follow

Change JDK version from 1.8 to 1.6

I want ot change my jdk versiob from 1.8 to 1.6 but how do have to do this?
I read this post How to set or change the default Java (JDK) version on OS X? which is what I think the solution, but when I am goign to 'C:\Program Files\Java' there are only two folder, one jdk1.8.0_65 and jdk1.8.0_73 there is no jdk1.6 so how and where can I get this there?
Install the Java version you want to use.
You can use jenv, it is like a Java environment manager. It is super easy to use and clean
For Mac, follow the steps:
brew install jenv
git clone https://github.com/gcuisinier/jenv.git ~/.jenv
Installation: If you are using bash follow these steps:
$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
$ exec $SHELL -l
Add desired versions of JVM to jenv:
jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
jenv add /System/Library/Java/JavaVirtualMachines/1.8.0.jdk/Contents/Home
Check the installed versions:
jenv versions
Set the Java version you want to use by:
jenv global oracle64-1.6.0

Categories