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
Related
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
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...
Good morning guys,
trying to install the Pygame library on my MacBook Pro...
I encountered some issues that I'm sure you're able to help me with!
First of all I installed the last Python version (3.7.4)
Than I tried to install via pip the Pygame library, but the process
was unsuccessful due to the lack of a Java JKD 13.
I downloaded and installed the last JDK 13 version (Jdk-13_osx-x64)
and this process appeared to be successful.
Trying again to finally install the Pygame library an error occurred:
Unable to locate an executable at "/Library/Java/JavaVirtualMachines/jdk-13.jdk/Contents/Home/bin/apt
Can anyone of you guys help me???
Thanks prior!
For Python and Java developers using macOS, I personally recommend installing Python and Java through HomeBrew.
Before you can start your journey as a software developer, you should install Xcode and xcode-select first which is mandatory.
You can install Xcode from Mac AppStore and xcode-select through the following command:
xcode-select --install
After installing the prerequisites, you can install HomeBrew via:
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
Which is referenced from here
After you've installed HomeBrew you can install Python3 and AdoptopenJDK via the following command:
brew install python3
brew cask install adoptopenjdk
AdoptopenJDK is an open source JDK recommended by myself other than Oracle JDK.
Apt used to be a command coming with the Java Development Kit around Java 6.
Java 6 is also the latest 32-bit version provided by Apple but that doesn’t run on the newest version of Mac OS.
I think you should look for a newer version of pygame compatible with your system.
I'm attempting to install JDK 8 Update 121.pkg on a Mac running macOS Sierra 10.12.3.
The installer produces the following error message, see screenshot:
"The installation failed... Contact the software manufacturer for assistance."
How would I contact Oracle? Or is there a better fix?
I would recommend you use Homebrew and a tool like jenv to manage the different Java versions on OSX:
brew cask install java
brew install jenv
OSX needs its outdated system-default Java for the occasional task, so you don't want to go replacing it outright.
I need to install octave with java 8 support, via homebrew, on OS X 10.12.2. I did brew install octave --with-docs, and it seemed to compile normally. I can start octave, but it lacks java support, which I need. From the octave console:
>> javaMethod('getProperty','java.lang.System','java.version')
error: javaMethod: support for Java was unavailable or disabled when Octave was built
>> octave_config_info ("features").JAVA
ans = 0
The only warning during the brew install was:
==> make install
Warning: homebrew/science/octave dependency gcc was built with a different C++ standard
library (libstdc++ from clang). This may cause problems at runtime.
I have previously installed: xcode and command line tools; brew update && brew upgrade; brew install gcc; brew install Caskroom/cask/java (and then command line java -version returns: "1.8.0_112"); and command line /usr/libexec/java_home returns: /Library/Java/JavaVirtualMachines/jdk1.8.0_112.jdk/Contents/Home
The only info that google finds is about how to compile withOUT java. The default is to compile with java, so I am suspecting that brew is not aware of the java 1.8 that is installed (despite it being installed by brew earlier today, and accessible by command line, and via /usr/libexec/java_home).
Apparently the process changed recently and the wider documentation has not caught up (that I could find).
Solution: You now need to brew install octave --with-java to get java support.
Now in octave I get:
>> javaMethod('getProperty','java.lang.System','java.version')
ans = 1.8.0_112