Because programmers can’t get enough caffeine
There are several ways to install Java. This is the one that worked for me.
WARNING: The version that comes installed on Apple Macs can be obsolete.
CAUTION: Do not delete the default version. But if you did, to re-install Java 6 for OS X 2014-001, it can be obtained from https://support.apple.com/kb/DL1572?locale=en_US
Which Java You Got?
On a Terminal open to any folder:
To see what JRE you have already installed:
A sample response:
java version "1.8.0_06-ea" Java(TM) SE Runtime Environment (build 1.8.0_06-ea-b13) Java HotSpot(TM) 64-Bit Server VM (build 23.2-b04, mixed mode)
PROTIP: Developers use the JDK rather than the JRE (Runtime Environment), see what version of the Java Compiler is installed:
A sample response:
If it’s not installed, MacOS prompts you to install the JDK. Clever. But don’t do it if you want the Oracle version.
Click More Info….
That’s a capital V.
The response on my machine:
Matching Java Virtual Machines (4): 1.8.0_45, x86_64: "Java SE 8" /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home 1.7.0_65, x86_64: "Java SE 7" /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home 1.6.0_65-b14-466.1, x86_64: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home 1.6.0_65-b14-466.1, i386: "Java SE 6" /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home /Library/Java/JavaVirtualMachines/jdk1.8.0_45.jdk/Contents/Home
PROTIP: In OSX, all known JVM’s are located at:
The $JAVA_HOME environment variable is used by Groovy, Grails, Spring Boot, and others:
See what derivative program such as Maven uses:
The sample response:
Apache Maven 3.3.9 (bb52d8502b132ec0a5a3f4c09453c07478323dc5; 2015-11-10T09:41:47-07:00) Maven home: /usr/local/Cellar/maven/3.3.9/libexec Java version: 1.8.0_74, vendor: Oracle Corporation Java home: /Library/Java/JavaVirtualMachines/jdk1.8.0_74.jdk/Contents/Home/jre Default locale: en_US, platform encoding: US-ASCII OS name: "mac os x", version: "10.11.5", arch: "x86_64", family: "mac"
command -v java
If you get this:
Latest Version of Oracle Java
PROTIP: Hold off downloading the java .dmg installer file, as described at https://java.com/en/download/help/mac_install.xml
WARNING: Oracle installs an annoying Ask Toolbar, sometimes without asking.
Oracles docs on installing the JDK:
Use an internet browser to
Multiple Versions of JDK
Click the “Download” button for the JDK (not the JRE).
NOTE: Downloads of the JDK contains the JRE.
Install Jenv to manage multiple Versions of Java
PROTIP: If you’re a developer, you’ll likely need to manage different versions of Java needed by different apps. Much like NPM for Node and rbenv for Ruby.
Install Jenv by specifying the location URL:
brew install https://raw.githubusercontent.com/entrypass/jenv/homebrew/homebrew/jenv.rb
The long response:
==> Auto-updated Homebrew! Updated Homebrew from fa19447 to 7c5e149. Updated 3 taps (homebrew/core, homebrew/dupes, pivotal/tap). ==> New Formulae lean-cli libdivecomputer ==> Updated Formulae antigen konoha prometheus cogl kyua qbs fabio libfreenect rapidjson ffmpeg libgit2-glib rclone ffmpegthumbnailer mkvtoolnix rebar gawk mpv repo git-fresh mypy sngrep git-lfs ncdu swiftlint giter8 nghttp2 tailor gssh open-mpi the_platinum_searcher homebrew/dupes/ed openvpn tile38 homebrew/dupes/tcl-tk osh tippecanoe infer pcap_dnsproxy tor jlog pivotal/tap/pivnet-cli vegeta joe ponyc yle-dl ######################################################################## 100.0% ==> Cloning https://github.com/gcuisinier/jenv.git Cloning into '/Users/mac/Library/Caches/Homebrew/jenv--git'... remote: Counting objects: 122, done. remote: Compressing objects: 100% (75/75), done. remote: Total 122 (delta 8), reused 94 (delta 5), pack-reused 0 Receiving objects: 100% (122/122), 29.04 KiB | 0 bytes/s, done. Resolving deltas: 100% (8/8), done. Checking connectivity... done. Note: checking out '76268a9b90248f260037137ac9212db9ba1e72c6'. You are in 'detached HEAD' state. You can look around, make experimental changes and commit them, and you can discard any commits you make in this state without impacting any branches by performing another checkout. If you want to create a new branch to retain commits you create, you may do so (now or later) by using -b with the checkout command again. Example: git checkout -b
==> Checking out tag 0.2.0-201404260 ==> Caveats Add 'jenv init' to your shell to enable shims and autocompletion. $ echo 'eval "$(jenv init -)"' >> ~/.bash_profile Fish shell export functions are available at /usr/local/Cellar/jenv/0.2.0-201404260/fish Bash completion has been installed to: /usr/local/etc/bash_completion.d zsh completion has been installed to: /usr/local/share/zsh/site-functions ==> Summary 🍺 /usr/local/Cellar/jenv/0.2.0-201404260: 70 files, 61K, built in 2 seconds </pre> The destination of the install is different than standard Java install:
Cloning into '/Users/mac/Library/Caches/Homebrew/jenv--git'...
Do what the jenv message says and activate jenv by adding this to the bottom of the file activated when a Terminal shell window starts:
echo 'eval "$(jenv init -)"' >> ~/.bash_profile
To see if jenv can run, list its version and commands:
The desired response is like this:
[ ] Some useful jenv commands are: commands List all available jenv commands local Set or show the local application-specific Java version global Set or show the global Java version shell Set or show the shell-specific Java version rehash Rehash jenv shims (run this after installing executables) version Show the current Java version and its origin versions List all Java versions available to jenv which Display the full path to an executable whence List all Java versions that contain the given executable See `jenv help ' for information on a specific command. For full documentation, see: https://github.com/hikage/jenv#readme </pre> TROUBLESHOOTING: If you get this:
/usr/local/bin/jenv: line 25: cd: /Users/mac/.jenv: No such file or directory /usr/local/Cellar/jenv/0.2.0-201404260/libexec/jenv: line 25: cd: /Users/mac/.jenv: No such file or directory /usr/local/Cellar/jenv/0.2.0-201404260/libexec/jenv---version: line 17: cd: /Users/mac/.jenv: No such file or directoryRather than using instructions at https://github.com/gcuisinier/jenv#gettings-started
to git clone https://github.com/gcuisinier/jenv.git ~/.jenv The response:
Cloning into '/Users/mac/.jenv'... remote: Counting objects: 874, done. remote: Total 874 (delta 0), reused 0 (delta 0), pack-reused 874 Receiving objects: 100% (874/874), 362.88 KiB | 199.00 KiB/s, done. Resolving deltas: 100% (367/367), done. Checking connectivity... done.PROTIP: Installing using clone means that you would have to manually check whether a new version is available, then manually do the upgrade. So instead of doing that, forget the ~/.jenv folder and do this:
Use Homebrew’s directories rather than ~/.jenv add to the bottom of your profile file:
To enable shims and autocompletion add to the botton of your profile file:
if which jenv > /dev/null; then eval "$(jenv init -)"; fi
To see what jenv recognizes:
The response if none if brew cask was not installed:
* system (set by /usr/local/var/jenv/version)
Install Java GUI using brew cask, and
--forceto update sub-versions:
sudo brew update && brew cask install java --force
==> Downloading http://download.oracle.com/otn-pub/java/jdk/8u45-b14/jdk-8u45-ma Warning: The default Caskroom location has moved to /usr/local/Caskroom. Please migrate your Casks to the new location and delete /opt/homebrew-cask/Caskroom, or if you would like to keep your Caskroom at /opt/homebrew-cask/Caskroom, add the following to your HOMEBREW_CASK_OPTS: --caskroom=/opt/homebrew-cask/Caskroom For more details on each of those options, see https://github.com/caskroom/homebrew-cask/issues/21913. ==> Caveats This Cask makes minor modifications to the JRE to prevent issues with packaged applications, as discussed here: https://bugs.eclipse.org/bugs/show_bug.cgi?id=411361 If your Java application still asks for JRE installation, you might need to reboot or logout/login. Installing this Cask means you have AGREED to the Oracle Binary Code License Agreement for Java SE at http://www.oracle.com/technetwork/java/javase/terms/license/index.html ==> Downloading http://download.oracle.com/otn-pub/java/jdk/8u102-b14/jdk-8u102- ==> Verifying checksum for Cask java ==> Running installer for java; your password may be necessary. ==> Package installers may write to any location; options such as --appdir are i Password: ==> installer: Package name is JDK 8 Update 102 ==> installer: Upgrading at base path / ==> installer: The upgrade was successful. 🍺 java was successfully installed!
TROUBLESHOOTING: If you get stuck on “verifying…” during the installation process of Java on Mac El Capitan, it’s probably because of “rootless”. See http://osxdaily.com/2015/10/05/disable-rootless-system-integrity-protection-mac-os-x/
Jenv for several Java versions
The point of jenv is to add additional versions, such as back version JDK 7:
jenv add /Library/Java/JavaVirtualMachines/jdk1.7.0_65.jdk/Contents/Home
Add JDK 8:
jenv add /Library/Java/JavaVirtualMachines/jdk1.8.0_101.jdk/Contents/Home
List the libraries jenv knows about:
Highlight, copy and paste the version you want to use.
To configure global version:
jenv global oracle64-220.127.116.11
system oracle64-18.104.22.168 * oracle64-22.214.171.124 (set by /Users/wilsonmar/.jenv/version)
Open JDK is the open-sourced implementation of the JRE spec, at http://openjdk.java.net is at JVM 7.
But it is still not ready for “prime time” on Mac as installation is a dirty affair.
Open JDK’s install page at http://openjdk.java.net/install/ shows apt-get (for Debian, Ubuntu) and yum (for Red Hat, CentOS, Oracle Linus, Fedora).
http://blog.shelan.org/2015/03/how-to-build-open-jdk-9-on-mac-osx.html on Yosemite
Download source using Mercurial to a new folder “openjdk9”:
hg clone http://hg.openjdk.java.net/jdk9/jdk9 openjdk9 cd ./openjdk9
Note JDK 9 is under active development.
http://hg.openjdk.java.net/jdk8/jdk8 work stopped at 2014-03-04.
Install XQuartz for X Window System that runs on OSX:
brew install Caskroom/cask/xquartz
brew cask list
NOTE: Downloaded /Library/Caches/Homebrew/xquartz-2.7.9.dmg was 7.9K
xquartz staged at ‘/opt/homebrew-cask/Caskroom/xquartz/2.7.9’ (73M)
- cd to the .tar.gz directory containing the configure file for Make to use.
XQuartz fixes an error in this command:
Install apple-gcc42 the Apple C compiler.
Install ccache compiler cache.
brew install ccache
Make a symlink /usr/bin/gcc -> /usr/local/Cellar/apple-gcc42/4.2.1-5666.3/bin/gcc-4.2 (same for g++)
If you’re at Mavericks Apply patches: 1, 2, 3, 4.
if you’re at Mavericks Comment out NS_AVAILABLE(10_9, NA) in line 16 of /System/Library/Frameworks/Foundation.framework/Headers/NSUserNotification.h
Built image should be available at build/macosx-x86_64-normal-server-release/jdk/
Test JDK Build
https://mihail.stoynov.com/2015/01/29/building-openjdk-9-on-a-osx-or-any-linux/ shows JDK 9 install using ccache, mercurial (hg), jtreg “testing harness”, and Webrev to diff code
More on OSX
This is one of a series on Mac OSX:
- MacOS Versions
- MacOS Keyboard tricks
- MacOS Hardware and accessories
- 1password on MacOS
- MacOS Setup automation with Ansible
- Text editors and IDEs on MacOS
- Utilities for MacOS
- MacOS Configuration dotFiles
- MacOS Homebrew installers
- Backups on MacOS
- Windows on Apple MacOS
- PHP on MacOS
- Java on MacOS
- Maven on MacOS
- Ruby on MacOS
- Python on MacOS
- Node on MacOS installation