LoginSignup
5
2

More than 5 years have passed since last update.

homebrewで古いバージョンのmavenをインストールする

Posted at

mavenを使ってたら古いバージョンのmavenが欲しくなった。古いアプリケーションの管理にはよくある話です。
とりあえず、searchで古いバージョンが取れるようにする。

brew tap homebrew/versions

mavenを探してみる

$ brew search maven
homebrew/versions/maven31
homebrew/versions/maven32
maven ✔
maven-shell                                                       
homebrew/completions/maven-completion
Caskroom/cask/mavensmate     

今回欲しかったのがmaven3.2系だったのでインストール

$ brew install homebrew/versions/maven32
==> Installing maven32 from homebrew/versions
Error: Cannot install homebrew/versions/maven32 because conflicting formulae are installed.

  maven: because Differing versions of same formula

Please `brew unlink maven` before continuing.

Unlinking removes a formula's symlinks from /Users/satohjohn/.homebrew. You can
link the formula again after the install finishes. You can --force this
install, but the build may fail or cause obscure side-effects in the
resulting software.

エラーが出てきた。「新しいのあるからそっちのリンクを切ってからもう一度やってね」と言うことです。
言われたとおりのコマンドを叩いてみる。

$ brew unlink maven
Unlinking /Users/satohjohn/.homebrew/Cellar/maven/3.3.3... 5 symlinks removed

こうなってから切ってやる

$ brew install homebrew/versions/maven32
==> Installing maven32 from homebrew/versions
==> Downloading https://www.apache.org/dyn/closer.cgi?path=maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
==> Best Mirror http://ftp.meisei-u.ac.jp/mirror/apache/dist/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz
######################################################################## 100.0%
🍺  /Users/satohjohn/.homebrew/Cellar/maven32/3.2.5: 86 files, 9.0M, built in 22 seconds

インストールできたようなので、versionを確認する

$ mvn -v
Apache Maven 3.2.5 (12a6b3acb947671f09b81f49094c53f426d8cea1; 2014-12-15T02:29:23+09:00)
Maven home: /Users/satohjohn/.homebrew/Cellar/maven32/3.2.5/libexec
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: ja_JP, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"

できた

元のバージョンにもどしたくなった

brew switchを使えばよいのか?

$ brew switch maven 3.3.3
Cleaning /Users/satohjohn/.homebrew/Cellar/maven/3.3.3
Error: Could not symlink bin/mvn
Target /Users/satohjohn/.homebrew/bin/mvn
is a symlink belonging to maven32. You can unlink it:
  brew unlink maven32

To force the link and overwrite all conflicting files:
  brew link --overwrite maven

To list all files that would be deleted:
  brew link --overwrite --dry-run maven

上手く行かない。
brew infoを使って2つを比べると

$ brew info maven
maven: stable 3.3.9
Java-based project management
https://maven.apache.org/
Conflicts with: mvnvm
/Users/satohjohn/.homebrew/Cellar/maven/3.3.3 (92 files, 9M)
  Built from source on 2015-11-13 at 11:47:01
From: https://github.com/Homebrew/homebrew-core/blob/master/Formula/maven.rb
==> Requirements
Required: java ✔
$ brew info maven32
homebrew/versions/maven32: stable 3.2.5
Java-based project management
https://maven.apache.org/
Conflicts with: maven, mvnvm
/Users/satohjohn/.homebrew/Cellar/maven32/3.2.5 (86 files, 9.0M) *
  Built from source on 2016-10-13 at 09:23:36
From: https://github.com/Homebrew/homebrew-versions/blob/master/maven32.rb
==> Requirements
Required: java ✔

ってなっている
どうやら同じFromのものでないとできないようである。
おとなしく、unlinkしてlinkしなおすのがよさげです。

$ brew unlink maven32
Unlinking /Users/satohjohn/.homebrew/Cellar/maven32/3.2.5... 3 symlinks removed
$ brew link maven  
Linking /Users/satohjohn/.homebrew/Cellar/maven/3.3.3... 5 symlinks created
$ mvn -v
Apache Maven 3.3.3 (7994120775791599e205a5524ec3e0dfe41d4a06; 2015-04-22T20:57:37+09:00)
Maven home: /Users/satohjohn/.homebrew/Cellar/maven/3.3.3/libexec
Java version: 1.7.0_79, vendor: Oracle Corporation
Java home: /Library/Java/JavaVirtualMachines/jdk1.7.0_79.jdk/Contents/Home/jre
Default locale: ja_JP, platform encoding: UTF-8
OS name: "mac os x", version: "10.11.4", arch: "x86_64", family: "mac"

できました。

参考

http://stackoverflow.com/questions/3987683/homebrew-install-specific-version-of-formula
今回紹介したのは回答の中の2番ですね。
3番の Try some formula from the past が頻繁に切り替える様なツールには良いかもしれないですね。
少しむずかしい気がするけど紹介されているlogをgrepするというのがなかなかに良い気がする。

5
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
5
2