Mac OS Setup for Java Developers
In this post I will go through the steps for setting up a very basic Java development environment on Mac OS, based on homebrew, cask and jenv.
1. Tools of trade
- Homebrew - Command line package manager for Mac OS X.
- Cask - Extends
brew
by adding support for multiple applications, including commercial ones. - jEnv - Manage multiple Java versions easily.
2. Basics
2.1. A Better Terminal
The Terminal application distributed with Mac OS X is great - customizable UI, supports multiple tabs, great OS integration (easy copy & paste), etc.
However it does have a major downside - by default, the support for colors in
ls
is disabled. You can enable it by adding the following lines in your
.bash_profile
:
export CLICOLOR=1
export LSCOLORS=gxBxhxDxfxhxhxhxhxcxcx
This configuration assumes you’re using a black background for your terminal. If you prefer to use a different color scheme, feel free to use a generator like this one.
2.2 Install Homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
2.3 Install Cask
Another one liner,
brew install caskroom/cask/brew-cask
2.4 Install jEnv
jEnv is a command line tool to help you forget how to set the JAVA_HOME
environment variable. It can be installed through brew
brew install jenv
You will also need to update your .bash_profile
with the following lines (you
can read more details in the output of brew install jenv
):
export JENV_ROOT=/usr/local/opt/jenv
eval "$(jenv init -)"
2.5 Pick Your Java Version
You can view the available Java versions by querying Cask:
brew cask search java7
You can view more details about a Java version using brew cask info
:
brew cask info java
To install a Java version,
brew cask install java7
2.6 Use jEnv to switch between Java versions
First, you will need to tell jEnv which Java versions you would like to manage:
jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home/
You can view the managed Java versions using:
jenv versions
You can switch globally to anoter Java version using
jenv global 1.6
For more details, be sure to check the Official jEnv Documentation.