Maven error with Java 6 on OS X: “Unsupported major.minor version 51.0”

If you encounter the error below with Java 6 on OS X, make sure you’re using Maven 3.2.5 or older.

$ mvn
Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/cli/MavenCli : Unsupported major.minor version 51.0
  at java.lang.ClassLoader.defineClass1(Native Method)
  at java.lang.ClassLoader.defineClassCond(
  at java.lang.ClassLoader.defineClass(
  at Method)
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClassFromSelf(
  at org.codehaus.plexus.classworlds.strategy.SelfFirstStrategy.loadClass(
  at org.codehaus.plexus.classworlds.realm.ClassRealm.unsynchronizedLoadClass(
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
  at org.codehaus.plexus.classworlds.realm.ClassRealm.loadClass(
  at org.codehaus.plexus.classworlds.launcher.Launcher.getMainClass(
  at org.codehaus.plexus.classworlds.launcher.Launcher.launchEnhanced(
  at org.codehaus.plexus.classworlds.launcher.Launcher.launch(
  at org.codehaus.plexus.classworlds.launcher.Launcher.mainWithExitCode(
  at org.codehaus.plexus.classworlds.launcher.Launcher.main(

Maven error in OS X: “Maven already installed, it’s just not linked”

If you use Homebrew on OS X and you come across the error below, just:

  1. $ rm -rf /usr/local/Cellar/maven
  2. $ brew install maven
  3. $ mvn -version
  4. That’s it!

$ brew install maven
Updating Homebrew...
==> Auto-updated Homebrew!
Updated 2 taps (caskroom/cask, caskroom/versions).

Warning: maven-3.5.0 already installed, it's just not linked.