Where is java installed on my mac? - java

I am having trouble finding where java is installed on my mac. I am trying to downgrade from java 1.8 to java 1.7.
When I run the command /usr/libexec/java_home it returns /Library/Java/JavaVirtualMachines/jdk1.8.0_11.jdk/Contents/Home
but the trouble is when I go to the Library folder there is no Java folder. I've tried navigating there in terminal and it says -bash: cd: Java: No such file or directory
How can I get the Java folder to show? I was thinking maybe it is hidden. Or what other commands can I use that will point me to where Java is installed?

Try:
which java
This should give you the path of the java binary. It might be a link to another file, which you'll be able to check with:
ls -l `which java`

In your case Java doesn't seem to have been removed completely.
Go to /Library/PreferencePanes/JavaControlPanel.prefPane and remove it from command line. You might need sudo access.
Also remove the JavaAppletPlugin from /Library/Internet\ Plug-Ins/JavaAppletPlugin.plugin
Again sudo access is necessary

Related

java how to check version being used by 'jar launcher.app' on Mac OS

I have several .jar files that run successfully when opened with Mac's built in 'Jar Launcher' (Version 15.0.1) but when ran from terminal they error out.
Looking online the error messages might be down to the incorrect version of Java being linked to the terminal version, so I'd like to check if the options set for 'Jar Launcher' and the Java used within terminal are the same.
Does there exist any way to do this?
This question is two years old, but as there is no answer to it, I thought I'd put my two cents here since I've had issues myself, and have made some observations.
It seems that the Jar Launcher doesn't necessarily use the same JVM version as the one shown by the command /usr/libexec/java_home: If there is a JRE /Library/Internet Plug-Ins/JavaAppletPlugin.plugin, then the Jar Launcher will use it and ignore anything in /Library/Java/JavaVirtualMachines.
I've solve my problem of version mismatch between the Jar Launcher and the terminal by removing the JRE:
Go to /Library/Internet Plug-Ins.
Remove the JavaAppletPlugin.plugin directory by executing the rm command as a root user or by using the sudo tool.
Go to /Library/PreferencePanes.
Remove JavaControlPanel.prefpane by executing the rm command as a root user or by using the sudo tool.
Source: https://docs.oracle.com/javase/9/install/installation-jdk-and-jre-macos.htm

Error: JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java when i run gradle command in terminal

I am working in Ubuntu 16.04. I need to install gradle and the gradle is installed when i checked with sudo apt list --installed command but when i use gradle -version command it shows the following error,
JAVA_HOME is set to an invalid directory: /usr/lib/jvm/java-8-oracle/jre/bin/java
In sudo vim /etc/environment file,
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64/"
http_proxy="http://username:password#IP:port no/"
https_proxy="https://IP:port no/"
ftp_proxy="ftp://IP:port no/"
I don't know where i made mistakes. Please help me.
Thanks.
On a 64bit openSuse 64 42.1 box;
readlink -f $(which java)
provided;
/usr/lib64/jvm/java-1.8.0-openjdk-1.8.0/jre/bin/java
But;
export JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-openjdk
is the path that worked and allowed java emulator to run.
So i think we have to manually browse our file system and see what path to choose.
Today I faced this problem. I am using the default java that comes with your linux distro (so in my case, linux mint).
$ whereis java
This command gave me
java: /usr/bin/java /usr/share/java
So, I opened /user/bin. There was a link to Java. I right clicked it and selected follow original link. This lead me to /usr/lib/jvm/java-11-openjdk-amd64/bin/java.
So now that I know where this java is, I opened my .bashrc file, and edited the JAVA_HOME.
So for my case,
## My Custom variables
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
This solved the problem.
Now if you are using some other java (say you downloaded from oracle and extracted the zip file ...), then you have to add that location. So for example, if your java is in /home/user/.sdkman/candidates/java/current, then
export JAVA_HOME=/home/user/.sdkman/candidates/java/current
export PATH=$JAVA_HOME/bin:$PATH
I see a mismatch. In your enviornment file the JAVA_HOME is set to "/usr/lib/jvm/java-8-openjdk-amd64/" and your mentioned that the error that you got relates to the JAVA_HOME as "/usr/lib/jvm/java-8-oracle/jre/bin/java"
If you JAVA is really installed in /usr/lib/jvm/java-8-oracle directory, then you need to ensure that the JAVA_HOME is set to that directory. And also your PATH reflects $JAVA_HOME/bin in it.
I typically install Oracle JDK/JRE separately in a separate directory such as /usr/local/jdk1.8.0 etc.
check the jvm installtion folder from Files
eg : /usr/lib/jvm/java-12-oracle
then in terminal run sudo nano /etc/environment and add the line
JAVA_HOME="/usr/lib/jvm/java-12-oracle"
Then open terminal and run
export JAVA_HOME="/usr/lib/jvm/java-12-oracle"

Where is the brew app stored in a Mac?

I'm trying to install a package using Brew, via my Java app (ie no terminal is used).
While my install command works as expected in the terminal, it doesn't work on my Java app. The error is error=2, No such file or directory, so I'm guessing the keyword brew is not recognized.
I'm running my command like this from Java: Runtime.getRuntime().exec("brew install somepackage").
Now I'm trying to find the path to brew so that I could try this: Runtime.getRuntime().exec({"/some/path/to/brew", "install somepackage"}).
My problem is that I don't know where brew is stored in my mac.
Anyone knows?
Thanks
you can run
which brew
on your command line to see the path to your brew binary.
It defaults to /usr/local/bin/brew.
The reason that the call from java does not work is probably caused by the unchanged PATH variable within java, that you changed in your ~/.bash_profile to include /usr/local/bin

Mac launcher script for Java app

I need to launch a Jar file with a portable JRE. It works on Windows thanks to launch4j, it works on Ubuntu thanks to me, but not on Mac ..... and I can't test it.
The path tree of application:
abcmap/
launcher.command
bin/
abcmap.jar
jre/
bin/
java
Thinking it's like Unix system, I tried this (without specify bash):
./bin/jre/bin/java -Xms512m -Xmx1024m -jar ./bin/abcmap.jar
But this error appear:
MacBook-Pro:~ frcstnt$ /Applications/abcmap-mac/abcmap.command;
exit;
/Applications/abcmap-mac/abcmap.command: line 1:
bin/jre/bin/java: No such file or directory
logout
All files are rwx for all,
All files are UTF8 without BOM
I tried to change end of line to Unix and to "Old Mac" with Notepad++,
Archives are available on my website:
http://abc-map.fr/download/
https://translate.google.fr/translate?hl=fr&sl=fr&tl=en&u=http%3A%2F%2Fabc-map.fr%2F
Someone can help me please?
Edit: I think my problem is in the launcher, maybe encoding or bad command ?
Edit: Thanks to the Wim's answer it works. This is the script:
#!/bin/bash
SCRIPTDIR=$(dirname $0)
cd $SCRIPTDIR
${SCRIPTDIR}/bin/jre/bin/java -jar ${SCRIPTDIR}/bin/abcmap.jar
The path ./bin/jre/bin/java will be resolved relative to the current directory, not relative to the location of the command file. Try what happens if you run the command from the directory where the command is located.
I think I've found thanks to Wim Deblauwe. I use this:
#!/bin/bash
SCRIPTDIR=$(dirname $0)
cd $SCRIPTDIR
${SCRIPTDIR}/bin/jre/bin/java -jar ${SCRIPTDIR}/bin/abcmap.jar
Find the script dir, go to this dir and start operations.
It seems like you maybe don't even have the Java Runtime Evironment installed. You should try running java -version or at least java -h or java --help.
If you output is something like the following:
java: command not found
You should download and install the latest JRE and try again.
If, however, you see your java version, try first using cd to go to the directory of your jarfile and then use:
java -jar -otheroptionshere jarfile.jar
I hope this helps! Tell me, if you still got issues.

How to set JAVA_HOME environment variable on Mac OS X 10.9?

I just purchased a brand new MacBook Pro.
This is my first MAC ever and I'm still trying to get the hang of navigating my way around.
Anyway, I'm also new to Java and I've been practicing on my Windows PC before it permanently died.
Now that I'm on this MAC, I installed my JDK and now I need to set the JAVA_HOME environment variable.
I have no idea what to do.
I tried following some of these guides and didn't get very far.
Mkyong.com : How to set JAVA_HOME variable in Mac OSX
YouTube : How to set environment variables on mac, linux, solaris, rhel
YouTube : How to Set Environment Variables in Mac
I was able to locate the terminal and I think I created some multiple files. I'm getting messages like this:
(1) Another program may be editing the same file.
If this is the case, be careful not to end up with two
different instances of the same file when making changes.
Quit, or continue with caution.
(2) An edit session for this file crashed.
If this is the case, use ":recover" or "vim -r /Users/Erwin/.bash_profile"
to recover the changes (see ":help recovery").
If you did this already, delete the swap file "/Users/Erwin/.bash_profile.sw p"
to avoid this message.
Can somebody tell how to set Java in Mac OSX environment step by step?
If you're using bash, all you have to do is:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.bash_profile
If you're using zsh (which probably means you're running macOS Catalina or newer), then it should instead be:
echo export "JAVA_HOME=\$(/usr/libexec/java_home)" >> ~/.zshrc
In either case, restart your shell.
If you have multiple JDK versions installed and you want it to be a specific one, you can use the -v flag to java_home like so:
echo export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" >> ~/.bash_profile
I just spent 2 hours setting this variable. The other answers did not work properly for me. I'm using macOS Catalina 10.15.4.
First, find your actual Java SDK Home directory:
/usr/libexec/java_home
Manually navigate there to make sure you don't have any mistakes due to incorrect versions, etc. For me, this was:
/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Next, edit your terminal's profile. If you're using zsh, this will be:
vim ~/.zshrc
If you're not using zsh, this will be:
vim ~/.bash_profile
Inside, add the following new line anywhere in the file:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home
Restart your terminal app (or source ~/.bash_profile), and it should work properly.
I did it by putting
export JAVA_HOME=`/usr/libexec/java_home`
(backtics) in my .bashrc. See my comment on Adrian's answer.
Set $JAVA_HOME environment variable on latest or older Mac OSX.
Download & Install install JDK
First, install JDK
Open terminal check java version
$ java -version
Set JAVA_HOME environment variable
Open .zprofile file
$ open -t .zprofile
Or create . zprofile file
$ open -t .zprofile
write in .zprofile
export JAVA_HOME=$(/usr/libexec/java_home)
Save .zprofile and close the bash file & then write in the terminal for work perfectly.
$ source .zprofile
Setup test in terminal
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-13.0.1.jdk/Contents/Home
In Mac OSX 10.5 or later, Apple recommends to set the $JAVA_HOME variable to /usr/libexec/java_home, just export $JAVA_HOME in file ~/. bash_profile or ~/.profile.
Open the terminal and run the below command.
$ vim .bash_profile
export JAVA_HOME=$(/usr/libexec/java_home)
save and exit from vim editor, then run the source command on .bash_profile
$ source .bash_profile
$ echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/1.7.0.jdk/Contents/Home
It is recommended to check default terminal shell before set JAVA_HOME environment variable, via following commands:
$ echo $SHELL
/bin/bash
If your default terminal is /bin/bash (Bash), then you should use #Adrian Petrescu method.
If your default terminal is /bin/zsh (Z Shell), then you should set these environment variable in ~/.zshenv file with following contents:
export JAVA_HOME="$(/usr/libexec/java_home)"
Similarly, any other terminal type not mentioned above, you should set environment variable in its respective terminal env file.
If you are using Zsh, then try to add this line in ~/.zshrc file & restart terminal.
export JAVA_HOME=$(/usr/libexec/java_home)
I got it working by adding to ~/.profile. Somehow after updating to El Capitan beta, it didnt work even though JAVA_HOME was defined in .bash_profile.
If there are any El Capitan beta users, try adding to .profile
Since I'm using openjdk managed with sdkman, I added
sudo ln -sfn /path/to/my/installed/jdk/openjdk.jdk /Library/Java/JavaVirtualMachines/openjdk.jdk
Adding this to your system lets java_home recognize your installed version of Java even when its not installed via standard packages
I checked my /Library/Java/JavaVirtualMachines/
directory and found the version to be jdk1.8.0_321.jdk/Contents/Home
and added this directly to my .bash_profile:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_321.jdk/Contents/Home
but it's still complaining after sourcing the .bash_profile:The operation couldn’t be completed. Unable to locate a Java Runtime that supports apt.
In the latest Mac, you have to add the Set $JAVA_HOME environment variable in .zprofile. Here, we simple way to open it. Press ⌘ + Shift + . from keyboard. Just open it and add the $JAVA_HOME environment variable as explained here:
JAVA 11 via Homebrew - tested on macos Ventura 2022
.zshrc
export JAVA_HOME=/opt/homebrew/opt/openjdk#11/libexec/openjdk.jdk/Contents/Home
For Mac M1
Download & Install install JDK
Open terminal check java version
java -version
Now create a file
touch .zprofile
Open the file
open -t .zprofile
Add the below line
export JAVA_HOME=$(/usr/libexec/java_home)
I resolved it on macOS Monterey by using the option provided by Google
Under Gradle JDK, choose the Embedded JDK option.
https://developer.android.com/studio/intro/studio-config#:~:text=A%20copy%20of%20the%20latest,use%20for%20your%20Android%20projects.
I'm able to solve this issue by setting JAVA_HOME in .bash_profile file
export JAVA_HOME=/usr/local/opt/openjdk#17
Note:
I installed openjdk version 17 using 'brew'. I got this location from brew console. I'm using 'bash' instead of 'zsh' in my mac.
Open Terminal.
Confirm you have JDK by typing “which java”. ...
Check you have the needed version of Java, by typing
“java -version”.
Set JAVA_HOME using this command in Terminal: export
JAVA_HOME=/Library/Java/Home.
echo $JAVA_HOME on Terminal to confirm
the path.
More simply on a mac terminal with a modern OSX
$ vim ~/.zshrc
Type "a" to being editing, and then paste (ctrl + v):
$ JAVA_HOME=/usr/libexec/java_home
then hit "escape" and type exactly ":wq" in order to write to the file and quit vim mode.
Finally, when out of vim mode and back in your terminal, type
$ source ~/.zshrc
This will refresh so that your terminal is aware of the changes.
IMPORTANT * If you don't "source" the file, you won't see the changes in this terminal session.
Check the changes by typing
$ echo $JAVA_HOME
and you should see /usr/libexec/java_home
Quick Guide for M1
Add java sdk into your m1
check version
java --version
Get all java versions installed in ur mac
/usr/libexec/java_home -V
Execute for Java path from library
/usr/libexec/java_home
(specify java version if you have multiple version, In my case -v17.0.5
/usr/libexec/java_home -v17.0.5
Mac>User>'YourUserName/Home'>.zshrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk-17.0.5.jdk/Contents/Home

Categories

Resources