install java on mac os x - java

i have macbook pro and have set java and java home. now it says that your JAVA_HOME is not set correctly. i want to completely remove java and install it again. how can i do this?
Thanks.

Put export JAVA_HOME=$(/usr/libexec/java_home) in your .profile and java_home will be set correctly.

This sounds like a Java based tool like ant or maven not being able to locate the JDK.
It does not mean you have to reinstall Java (which by the way is pretty hard for OS X) but that you should set your environment variables properly.
For a one shot, just set
export JAVA_HOME=/Library/Java/Home
in your shell, and then run ant or maven in your shell.

Related

"No Java runtime present, requesting install" for Ghidra Installation

Trying to run Ghidra, which require me to download Java runtime and development kit (JDK) and put it on the path. I extracted the JDK and got the bin.
However, I'm not really sure how to do the following steps:
Open ~/.bashrc with an editor of your choice. For example: vi ~/.bashrc
Do I need to download vim for this? I tried inputting this in homebrew and got nothing but a INSERT at the bottom. And when I type step 2 in it it didn't work as well.
At the very end of the file, add the JDK bin directory to the PATH variable:
export PATH=/bin:$PATH
I'm using a Macbook and it would be appreciated if someone can guide me through the process! Thanks :)
After a typical installation of Java/JDK it should already be on the path.
You can verify this by opening the Terminal app and typing in java -version.
If you did a non-standard installation I suggest using homebrew to install the JDK.
Then there should be no reason to update your ~/.bashrc file.
As regards to the editor - use whatever you like.
If you know how to use vim, you can definitely try it - it should be preinstalled on macOS (just type vim in the Terminal).

How do I install an earlier version of Java SDK on OSX

I have the Java 1.8.0_45 SDK installed on OSX Yosemite (10.10.4), but because of a bug in this release I need to go back to 1.8.0_25
I have downloaded and installed the earlier version (1.8.0_25) but even after a reboot java -versionstill shows 1.8.0_45.
I don't really understand where Java resides on OSX, but how can I get my system back so it uses 1.8.0_25
Try and add this to your ~/.bashrc
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
You can have multiple JRE/JDK's installed, by changing this path, you can specify which one you use each time you open a new shell.
Here is what I use in my .bashrc
JAVA_VERSION=7
JAVA_7_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_75.jdk/Contents/Home
JAVA_8_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_40.jdk/Contents/Home
tmp="JAVA_${JAVA_VERSION}_HOME"
export JAVA_HOME=${!tmp}
export PATH=${!j}/bin:$PATH
Here, you can simply change the 7 to an 8.
This will change the JAVA_HOME, and append the bin directory to your path for general use from the command line.
note you may beed to change your java home's according to the specific release versions installed on your machine.
Ah found it, suprisingly easy:
macbook:JavaVirtualMachines paul$ cd /Library/Java/JavaVirtualMachines
macbook:JavaVirtualMachines paul$ ls
jdk1.7.0_40.jdk jdk1.7.0_45.jdk jdk1.8.0.jdk jdk1.8.0_05.jdk jdk1.8.0_20.jdk jdk1.8.0_25.jdk jdk1.8.0_45.jdk
macbook:JavaVirtualMachines paul$ sudo rm -fr jdk1.8.0_45

mac os how can i be sure that java_home variable is there in the system path

I am downloading some apache components, and in the official documentation they wrote:
Make sure that JAVA_HOME is set to the location of your JDK
I do have java installed and my eclipse is working good, but how can I know if this java_home variable is in the path?
Open the terminal on your mac (easiest way to open terminal, type terminal in spotlight search). Run "printenv" command on terminal. It will show all the environment variables set on your mac. You can find out there if JAVA_HOME is set.

Change java version (Mac)

I have 2 java versions on my computer:
/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
/System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
The 1.6.0 is set to default. How can I make my java programs to run 1.7?
Tried to add:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
to my .zshrc file. But this seems to only change the path for my terminals java command.
Also tried to change the HOME symlink like this:
cd /Library/Java
mv Home Home-1.6
ln -s /Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home/ Home
This had no effect at all.
Also tried java changer software:
http://www.guigarage.com/2013/02/change-java-version-on-mac-os/
But no effect.
Any idea how to start java programs like .app and .jar files with the 1.7 version by just clicking on them?
I believe OS X (at least 10.8) uses the following paths:
JRE: /System/Library/Frameworks/JavaVM.framework/Versions/Current
JDK: /System/Library/Frameworks/JavaVM.framework/Versions/CurrentJDK
Those are symlinks, which you can update to point to your 1.7 installation.
You can verify this fairly easily:
a) run which java to check which java executable is being executed. In theory, that should be /usr/bin/java.
b) run ls -la on your java executable, which should tell you where it points (/System/Library/Frameworks/JavaVM.framework/Versions/Current/Commands/java
on my machine).
I think this should sort your .jar execution issue. If your Java application is wrapped in a .app, I believe it's a bit more complex: if memory serves, the version of java used will depend on the JavaApplicationStub being used by the .app.
$ edit ~/.profile
#Java 1.8
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.8.0_20.jdk/Contents/Home
export PATH=${PATH}:${JAVA_HOME}
$ java -version
java version "1.8.0_20-ea"
here are the steps:
http://ukitech.blogspot.com/2014/04/switching-version-of-java-on-mac.html
You can always add into your profile both on Mac or Linux. Just create if doesn't exist ~/.profile file and there this line:
export JAVA_HOME=/Library/Java/JavaVirtualMachines/jdk1.7.0_07.jdk/Contents/Home
This should work .zshrc as well as .bash_profile are loaded only when terminal window is openned and profile when your graphical environment starts up.

Running Ant with JDK 1.6 on Mac OS X

I am having a problem running Ant with JDK 1.6 on Mac OS X. Even though Java application versions is set to Java SE 6 in OS X's Java Preference, executing java -version in Terminal also shows java version "1.6.0_07", Ant still seems to use JDK 1.5 to be using JDK 1.5 as it does not see JDK 1.6 classes when compiling my code.
I understand that Ant relies on JAVA_HOME environment variable to specify which JDK to use. However, I do not quite understand how this variable can be set on Mac OS X.
Hence, my question is how to make Ant runs with JDK 1.6 on Mac OS X. If the correct way is still to set JAVA_HOME environment variable, how to set the variable on OS X.
The JAVA_HOME environment variable is set in your home directory's .profile file. (/Users/ejel/.profile ?) Edit it and set it to what you want it to be. E.g.:
export JAVA_HOME=/System/Library/Frameworks/JavaVM.framework/Versions/1.6/Home
From this point onward, every time you open a new terminal window it will have JAVA_HOME set to this new value. It will not have changed with any existing open windows.
If you are truly aghast to putting this in the profile, or if it conflicts with other software, the export statement could always be run in the terminal manually or go into a script (eg: setj6ev.sh) that is run once before you start running ant tasks.
I've added the line
export JAVA_HOME=`/usr/libexec/java_home`
To my .zshrc file, it seems to do the trick (.bash_profile or whatever if you use bash).
Ted, using the Java Preferences app doesn't change the CurrentJDK symlink in /System/Library/Frameworks/JavaVM.framework/Versions, which is what Ant will use if the JAVA_HOME environment variable isn't set. Thus, you can either change that symlink manually or set the JAVA_HOME environment variable, but if you do neither, then Ant won't use the correct JDK.
You can see the version of the jdk that Ant is using by issuing an <echo message="${ant.java.version}"/> in your build.xml file.
Explicitly setting the JAVA_HOME variable in your .profile/.bashrc/.zshrc isn't actually the recommended way to do it on the mac. There are programs that I've seen get hosed up with an explicitly set JAVA_HOME to a particular version (grails 1.1 with some spring resources for example).
The correct way to set the version of Java that you want to use is to use the /Application/Utilities/Java Preferences.app application.
In there, you drag the version of java that you want to use to the top. This will enable that version for all applications (both those run from the command line and those launched through GUI processes).
You can test the current version by running this from the command line:
java -version
I don't actually like the way that the mac handles the entire set of java symlinked directories and files. It's not obvious and people often screw it up.
See the apple developer page on this for more details.
I try everything, and only one thing works for me : unlink CurrentJDK, and link to 1.6 :
cd /System/Library/Frameworks/JavaVM.framework/Versions
sudo unlink CurrentJDK
sudo ln -sF "1.6" CurrentJDK
Finally I get :
java -version
java version "1.6.0_22"
I hope this help.
You may need to open a new command prompt instance so that the shell can pick up any changes to the environment variables.

Categories

Resources