How to install Java 8 on Mac

Don't rely on Oracle to install Java properly on your Mac.

Use Homebrew. this will install the latest jdk:

brew cask install java

in my case, jdk is openjdk 11.

If you want to manage multiple versions of Java on your Mac, consider using jenv.

UPDATE: Now that Java 8 is no longer the most current version, if you want java 8 install it this way:

brew tap caskroom/versions
brew cask install java8

To get a list of all older versions of java: brew tap caskroom/versions and then use brew search java.

We use brew cask since we'd otherwise use the Oracle GUI installer that will likely not install Java properly on your Mac. (Use brew cask install APP to install GUI apps; use brew install APP.) Java is not a GUI app; It should not require "cask" but at least Oracle is consistent.

If you want to install jdk7, you need to download jdk on oracle website(requires a login). Then install it.

mac default install jdk7 to /Library/Java/JavaVirtualMachines/jdk1.7.0_80.jdk

jEnv is a command line tool to help you forget how to set the JAVA_HOME environment variable.

Linux / OS X

$ git clone https://github.com/gcuisinier/jenv.git ~/.jenv

Mac OS X via Homebrew

$ brew install jenv

Installation

Bash

$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.bash_profile
$ echo 'eval "$(jenv init -)"' >> ~/.bash_profile

Zsh

$ echo 'export PATH="$HOME/.jenv/bin:$PATH"' >> ~/.zshrc
$ echo 'eval "$(jenv init -)"' >> ~/.zshrc

Configure

$ jenv add /System/Library/Java/JavaVirtualMachines/1.6.0.jdk/Contents/Home
  oracle64-1.6.0.39 added
$ jenv add /Library/Java/JavaVirtualMachines/jdk17011.jdk/Contents/Home
  oracle64-1.7.0.11 added

And Use !

List managed JDKs

$ jenv versions
  system
  oracle64-1.6.0.39
* oracle64-1.7.0.11 (set by /Users/hikage/.jenv/version)

Configure global version

$ jenv global oracle64-1.6.0.39

Configure local version (per directory)

$ jenv local oracle64-1.6.0.39

Configure shell instance version

$ jenv shell oracle64-1.6.0.39

view JAVA_HOME 

$ jenv exec bash
bash-3.2$ echo $JAVA_HOME

ps: when install Java, do not use a proxy, because the download speed is faster and do success.

reference address:

1. https://stackoverflow.com/questions/24342886/how-to-install-java-8-on-mac

2. http://www.jenv.be/ 

3. http://davidcai.github.io/blog/posts/install-multiple-jdk-on-mac/

4. https://github.com/gcuisinier/jenv/issues/44

5. https://github.com/jenv/jenv/wiki/Available-commands

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值