I used the command brew install openjdk#11 to install Java on my mac. But when I run
java --version, I get the following message:
The operation couldn’t be completed. Unable to locate a Java Runtime.
Please visit http://www.java.com for information on installing Java.
I have a few questions:
How do I install JRE using HomeBrew?
Which JRE version do I need to install?
The answer to your question can be found by running:
brew info openjdk#11
Part of the output is:
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
Related
I want to install Eclipse in my Mac (Yosemite OS Installed). But there is an error popup :
I Check my java configuration and i have 1.7 instaled.
I made the update in System preference > Java
And i know that i have the installation of JAva 8 in my computer because when i type in my terminal this command:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
I have java 1.8
But in my Os use the version 1.7 and not 1.8 what i have to do?
And why it is so difficult to do that, why it is not enough to update via System > Preferences
Thanks for you Help!
I made this via homebrew and it work for me:
brew update
brew cask install java
It is now installed in java_home like the version 1.7
But until the first version is in use.
Now You just have to export to JAVA_HOME variable with this command:
export JAVA_HOME=`/usr/libexec/java_home -v '1.8*'`
And it work
Thanks!
The JavaAppletPlugin.plugin Java is just the JRE, you need the full JDK to run Eclipse (and other Java applications) on a Mac.
So download and install the Java 8 JDK from the official Oracle site
Try this on a terminal window
echo $JAVA_HOME
you might get something like /Library/Java/JavaVirtualMachines/jdk1.8.0_111.jdk/Contents/Home (<-- that's mine, java 8)
Yours might point to Java 7. You can change JAVA_HOME to point to your Java 8 installation by doing
export JAVA_HOME=<path-to-java8-installation>
And then it should work.
(btw: your installation dir for Java 8 looks rather odd. you might want to re-install so that it is on a path that looks like mine above)
Install homebrew
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
See Homebrew homepage here
Install java using homebrew
a. brew update
b. brew tap caskroom/cask
c. brew install brew-cask
d. brew cask install java
See full instructions at (tomysmile/brew-java-and-jenv.md)[https://gist.github.com/tomysmile/a9a7aee85ff73454bd57e198ad90e614]
Install jenv, a java environment manager
brew install jenv
Add jenv to your path - see jenv page above
Add java path using jenv
jenv add /Library/Java/JavaVirtualMachines/your-jdk-version/Contents/Home
Replace your-jdk-version with the version of jdk you have installed on your system
Restart eclipse and that's it
I installed java with homebrew, using the command brew cask install java.
After successfully installing, I typed which java, and the path showed to be /usr/bin/java
When I typed brew cask info java, this showed up:
java: 1.8.0_102-b14 Java Standard Edition Development Kit
/usr/local/Caskroom/java/1.8.0_102-b14 (227.5M)
https://github.com/caskroom/homebrew-cask/blob/master/Casks/java.rb
Contents JDK 8 Update 102.pkg (pkg) Caveats This Cask makes minor
modifications to the JRE to prevent issues with packaged applications,
as discussed here: If your Java application still asks for JRE
installation, you might need to reboot or logout/login.
Installing this Cask means you have AGREED to the Oracle Binary Code
License Agreement for Java SE at
Did I forget to link something?
/usr/bin/java is a symlink.
To see where it points, type ls -la /usr/bin/java
brew cask is installing into /Library/Java/JavaVirtualMachines/jdk1.8.0_something.jdk/Contents/Home
If the previous command ls -la is matching this, you are good.
If not, it means that you previously had another java installation. In this case, you may want to use a tool like jenv to switch between your multiple installs.
To add to #djangofan .. when I did a brew reinstall, I noticed the following message:
==> Pouring openjdk--17.0.1_1.big_sur.bottle.tar.gz
==> Caveats
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/johndoe/.bash_profile
For compilers to find openjdk you may need to set:
export CPPFLAGS="-I/usr/local/opt/openjdk/include"
To his point, I did not install via cask. I assume that when you did the install you got a similar message that you simply did not notice.
I have installed and updated to the latest Version of Java.
I am running OS X 10.11.6 (15G31) on iMac.
The Java Control panel shows the correct verion and shows the link as:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
Executing:
/Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java -version
java version "1.8.0_101"
Shows the correct version.
However, exectuting:
java -version
java version "1.8.0_45"
shows an old version.
Executing:
whereis java
/usr/bin/java
Shows the link as /usr/bin/java
Yet trying to replace the soft link fails:
sudo ln -fs /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java /usr/bin/java
ln: /usr/bin/java: Operation not permitted
Even when using:
sudo bash (ie as root)
Any ideas?
Thanks
-jim
As it says in the folder name, /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java is actually an internet plug-in which is most likely only used for Applets.
The plain java installation on a Mac is located in /System/Library/Frameworks/JavaVM.framework/Versions and this seems to be not updated automatically.
Therefore, you'd need to go to http://java.oracle.com and download and install the current Java version from there (it will update an existing Java8 installation automatically during the installation process). After that, /usr/bin/java will point to the updated version.
I have been following this tutorial, and at step 5, I am getting the following output from GCC:
HelloWorld.c:1:17: error: jni.h: No such file or directory
In file included from HelloWorld.c:3:
HelloWorld.h:15: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
HelloWorld.c:5: error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before ‘void’
I know that he include directories vary from system to system, so I tried to adapt the command accordingly, but I cannot seem to find the correct directory on my system. I am using Ubuntu 10.04LTS.
Open up a terminal and type:
locate jni.h
That should tell you where every file called jni.h is on your system. I am on ubuntu 11.04, and it's located at:
/usr/lib/jvm/java-6-openjdk/include/jni.h
/usr/lib/jvm/java-6-sun-1.6.0.26/include/jni.h
You may also need to get it from the repos:
sudo apt-get install openjdk-6-jdk
should do the trick if you don't have it installed.
jni.h lives with JDK. For me it is: jdk1.6.0_25/include/.
And by default, I don't think Ubuntu would have JDK with development libraries, so download latest JDK version from Oracle and install it somewhere.
Or you can install openjdk as #Leif suggested if it works on 10.04 LTS. Although, I personally, prefer the one from Sun/Oracle.
In Ubuntu 14.04 run:
sudo apt-get install openjdk-7-jdk openjdk-7-jre-lib
Now, you have a headers into /usr/lib/jvm/java-7-openjdk-amd64/include
For OpenJDK 6:
sudo apt-get install openjdk-6-jdk openjdk-6-jre-lib
I am putting together a dev environment for a Java program and after the first try of my Ant build scripts I got this error:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk/lib/tools.jar
While the path to the jdk is correct, the tools.jar really wasn't there. Is it actually supposed to be there or did I get some config/installation thing wrong?
It seems like you can have Java installed in /usr/lib/jvm/java-6-openjdk but only have the JRE, not the JDK. This fixed it for me:
sudo apt-get install openjdk-6-jdk
Note: On CentOS / RHEL installing java-1.x.0-openjdk will not be enough. Also install java-1.x.0-openjdk-devel.
It's there on my machine. I'm running Sun JDK 1.6.0_21 on Windows XP SP3.
Are you sure you have the JDK? Is it possible that you only have the JRE?
On Debian, after installing Ant with apt-get install ant, I've encountered the same error when running it:
Unable to locate tools.jar. Expected to find it in /usr/lib/jvm/java-6-openjdk-amd64/lib/tools.jar
Indeed, there's no mention of any tools.jar anywhere in /usr/lib, although /usr/lib/jvm/java-6-openjdk-amd64 itself does exist.
https://packages.debian.org/search?searchon=contents&keywords=java-6-openjdk-amd64%2Flib%2Ftools.jar
As per the search above, java-6-openjdk-amd64/lib/tools.jar appears to be part of openjdk-6-jdk, which indeed didn't get installed with ant (since it's only marked as suggested (https://packages.debian.org/wheezy/ant)).
apt-get install openjdk-6-jdk
apt install defalut-jdk # this doesn't contain some file, like tools.jar...
apt install openjdk-8-jdk # this contains all files.
On Ubuntu I've just need to install JDK
sudo apt-get install openjdk-7-jdk
..and you can always search for all available versions with
$ sudo apt-cache search openjdk | grep ^openjdk
From the website https://openjdk.java.net/install/ we can read
The openjdk-7-jre package contains just the Java Runtime Environment. If you want to develop Java programs then install the openjdk-7-jdk package.
Try the following:
% sudo apt-get install sun-java6-jdk
% sudo update-alternatives --config java
select the option that has the path
/usr/lib/jvm/java-6-sun/jre/bin/java
Worked for me on an ubuntu 10.4
u can try to put your JAVA_HOME also, as follows:
% sudo export JAVA_HOME=$(readlink -f /usr/bin/javac | sed "s:/bin/javac::")
Installing the jdk-6u45-linux-x64.bin (from the oracle.com site) via unzip does not result in a tools.jar. I guess that file is created by the "make-jpkg" script. Once I did that, and installed the resulting .deb file, everything was fine.
I really hate oracle's lawyers.
Even if you have jdk installed, you'll need to redirect JAVA_HOME to point to it.
Here's one weird trick you can put into your .profile to set JAVA HOME properly, no matter which java you have:
export JAVA_HOME=$(dirname $(dirname $(readlink -e /usr/bin/java)))
# Test for jdk installed above jre
if [ -x $JAVA_HOME/../bin/java ]; then export JAVA_HOME=$(dirname $JAVA_HOME); fi
On Ubuntu I've fixed this problem by installing package
openjdk-7-jre-lib
tools.jar appeared after that.
(I know this is an old post, but comment in hope that it will be helpful for somebody lurking for answer like I was today.)