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. 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 JAVAHOME environment variable. I have no idea what to do. I tried following some of these guides and didn't get very far.
And I'm very sure this one made me create a now useless file: youtube.com/watch?v=-cASjkF94dc 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.
![Mac Mac](/uploads/1/2/5/6/125638157/831990469.png)
Setting multiple paths to JAVA_HOME in Ubuntu. Ask Question. Does the order of exporting and setting the variables matter? Is rebooting required? – Genadinik Apr 11 '11 at 16:38 @Genadinik if you run env what does it show for JAVA_HOME and CLASSPATH? – DerfK Apr 11 '11 at 18:03. The Java Preferences application. Recent versions of Java on OS X install an application “Java Preferences” into /Applications/Utilities. It allows you to select the preferred version by dragging it to the top of the list. There is one list for applets, and one list for applications and the command line.
If this is the case, use ':recover' or 'vim -r /Users/Erwin/.bashprofile' to recover the changes (see ':help recovery'). If you did this already, delete the swap file '/Users/Erwin/.bashprofile.sw p' to avoid this message.
Can some Mac expert out there help me in fixing this and setting Java environment step by step?
I know it has been a while for this question, but I just wanted to share the following piece of information that I came across today. You can use /usr/libexec/javahome -v to get the path you need for JAVAHOME. For instance, to get the path to the 1.7 JDK you can run /usr/libexec/javahome -v 1.7 and it will return the path to the JDK. In your.profile or.bashprofile just add export JAVAHOME=`/usr/libexec/javahome -v ` and you should be good.
Alternatively, try and convince the maintainers of java tools you use to make use of this method to get the version they need. To open '.bashprofile' type the following in terminal: nano /.bashprofile and add the following line to the file: export JAVAHOME=`/usr/libexec/javahome -v ` Press CTRL+X to exit the bash. Press 'Y' to save changes. To check whether the path has been added, type following in terminal: source /.bashprofile echo $JAVAHOME. Besides the settings for bash/ zsh terminal which are well covered by the other answers, if you want a permanent system environment variable for terminal + GUI applications (works for macOS Sierra; should work for El Capitan too): launchctl setenv JAVAHOME $(/usr/libexec/javahome -v 1.8) (this will set JAVAHOME to the latest 1.8 JDK, chances are you have gone through serveral updates e.g. Javac 1.8.0101, javac 1.8.0131) Of course, change 1.8 to 1.7 or 1.6 (really?) to suit your need and your system.