

Just remember to use option -v to set JAVA_HOME to a particular version of JDB, of course, it's only useful if you have multiple JDK installed on your MacBook Pro. You can follow the same steps to set the JAVA_HOME environment variable. In this article, you will learn how to set the JAVA_HOME environment variable in different Mac OS X versions e.g.Īctually, the steps are exactly the same (if you are running on a Mac version greater than 10.6), you don't need to do anything special depending upon your version e.g Mavericks or Yosemite. Since Java is an optional package on the latest version of OS X, starting from OSX 10.7 (Lion), you need to either install Oracle JDK or choose this optional package. In order to use Java from the command line, you also need to define JAVA_HOME or JRE_HOME, many Java-based programs and tools use these environment variables to access Java e.g. In order to run Java, two things are most important, PATH and CLASSPATH. Mac's UNIX-like feature is added advantage because most of the real-world Java servers run on UNIX-based systems e.g. If you have set JAVA_HOME in UNIX then it's exactly similar to that.Īpple's Mac OS X is the second most widely used operating system after Windows and no surprise that many Java programmers use Macbook Pro for Java development. This will append export "JAVA_HOME=\$(/usr/libexec/java_home -v 1.7)" into your bash_profile file.

Install Java 6 for OS X from Apple's website.You can set JAVA_HOME in Mac OS X 10,10 or Yosemite by adding the following command in your ~/.bash_profile file, as shown below:Įxport JAVA_HOME= `/usr/libexec/java_home` (remember backticks)Įcho export "JAVA_HOME= \$(/usr/libexec/java_home -v 1.7)" > ~/.bash_profile.If you prefer downloadable installers, here's where you can download Java from Oracle's website.If brew keeps erroring out for no reason, I suggest running this command. Install Java 12 brew cask install adoptopenjdk12 Install Java 8 brew cask install adoptopenjdk8 The best thing to do is install AdoptOpenJDK. Some projects require an older version of JDK (such as Java 8). Update 10/24/20: java was migrated from homebrew/cask to homebrew/core.Īpproach #2 - Install Directly from AdoptOpenJDK Here are instructions on how to install Homebrew on Mac. Thankfully, it's a single line of code that you paste into the terminal.

Homebrew does not come pre-installed with Mac, so you'll have to install it yourself. Below are the steps required to install Java using Homebrew. Homebrew is a package manager that makes it easy for us to install all sorts of development tools such as MySQL, Mongo, Ruby on Rails, and Java.
