Pivotal Labs

Main menu

Skip to primary content
Skip to secondary content
  • About
  • Case Studies
  • Team
    • Executives
    • Locations
      • San Francisco (HQ)
      • Boston
      • Boulder
      • Denver
      • London
      • Los Angeles
      • New York
  • Community
    • Blogs
    • Tech Talks
    • Events
  • Careers
    • Lifestyle
    • Principles & Practices
    • Benefits
    • FAQ
    • Apply
  • Contact
    • Press Room
    • Press Releases
    • In The News
    • Press Kit
  • All
  • Labs
  • Standup
  • Tracker

JAVA_HOME on Mac OS X

Alex Chaffee
Thursday, June 26, 2008

For the millionth time, cause I always forget…

Put this in ~/.bashrc:

export JAVA_HOME=/Library/Java/Home

[UPDATE: or this, which according to Mike Swingler, follows the Java version chosen in Java Preferences:

export JAVA_HOME=`/usr/libexec/java_home`

]

Also, run “sudo visudo” and add the line

Defaults        env_keep += "JAVA_HOME"

or else commands like “sudo gem install” won’t be able to find Java.

Without the above, I got the following error (which seemed to have been run through a baby-talk filter) when running “sudo gem install rjb”:

extconf.rb:44: JAVA_HOME is not setted. (RuntimeError)
  • 0 Shares
  • Share on Facebook
  • Share on Twitter

5 Comments

  1. Cloves Carneiro Jr says:

    You just saved me a couple of hours, thanks for putting this up.

    November 25, 2008 at 12:11 pm

  2. sfdc says:

    wow. that was incredibly useful! thanks so much for the great post.

    December 22, 2008 at 5:27 am

  3. Tyler Clemons says:

    Thanks! This helped tons!

    May 24, 2009 at 5:52 pm

  4. Mike Swingler says:

    You should use the /usr/libexec/java_home command, since it always follows the Java version choosen in Java Preferences.

    July 29, 2009 at 8:45 am

  5. Lennart Jörelid says:

    Hello Alex,

    I usually do these lines within my .bash_profile, to be able to quickly and smoothly switch between java versions on Mac. (This is really nice when wanting to test some code on multiple java versions). When I need to switch JDK, I simply use either of the aliases

    useJdk15
    useJdk16

    The snippets for this in .bash_profile are:

    …

    # Set roots for JDK version switching
    export JAVA_HOME_ROOT=/System/Library/Frameworks/JavaVM.framework/Versions
    export JAVA_15_HOME=${JAVA_HOME_ROOT}/1.5/Home
    export JAVA_16_HOME=${JAVA_HOME_ROOT}/1.6/Home

    …

    # Add JAVA_HOME to the path
    JAVA_HOME=/Library/Java/Home

    # Augment the path
    export PROTO_PATH=/Users/lj/Bin:${M2_HOME}/bin:/usr/local/bin:$PATH:/Users/lj/Bin:${GERONIMO_HOME}/bin:/Library/PostgreSQL/8.3/bin
    export PATH=${PROTO_PATH}:${JAVA_HOME}/bin

    …

    # Manage JDK switching
    function useJdk16()
    {
    # Assign JAVA_HOME
    export JAVA_HOME=${JAVA_16_HOME}

    # Adjust the path
    export PATH=${JAVA_HOME}/bin:${PROTO_PATH}
    }
    function useJdk15()
    {
    # Assign JAVA_HOME
    export JAVA_HOME=${JAVA_15_HOME}

    # Adjust the path
    export PATH=${JAVA_HOME}/bin:${PROTO_PATH}
    }

    # Define the standard JDK when working with the terminal.
    useJdk16 ;

    September 16, 2009 at 1:17 am

Add New Comment Cancel reply

Your email address will not be published.

Alex Chaffee

Recent Posts

  • Code Monkey
  • RubyGems Warningitis Outbreak
  • Upgrading your Rakefile from RSpec 1.3 to RSpec 2
Subscribe to Alex's Feed

Author Topics

ruby (14)
gem (5)
ruby on rails (24)
erector (2)
rspec (4)
activerecord (4)
database (3)
sinatra (1)
postgresql (1)
css (1)
html (1)
git (2)
mac (5)
java (3)
agile (12)
iphone (1)
migrations (1)
fun (5)
dot (1)
graphing (1)
subversion (1)
test (1)
demeter (1)
puzzler (1)
  • About
  • Case Studies
  • Team
  • Community
  • Careers
  • Contact
  • Labs
  • Events

Contact Us

contact@pivotallabs.com
+1 415-77-PIVOT
TwitterLinkedInFacebook

Pivotal Tracker

Tracker is the award-winning agile project management tool that enables real-time collaboration around a shared, prioritized backlog.
Visit pivotaltracker.com >