[MacOS] Hướng dẫn cài đặt Oracle JDK

by Hieu Nguyen
1 comment 180 views

Mặc định thì Oracle JDK sẽ được chọn cài đặt trên MacOS. Do đó nếu muốn sử dụng Oracle JDK thì bạn cần phải cài đặt lại. Trong bài viết này tôi sẽ hướng dẫn các bạn cài đặt Oracle JDK.

Homebrew

  • Nếu bạn chưa cài đặt brew thì có thể sử dụng lệnh sau để tiến hành cài đặt
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  • Nếu đã cài đặt rồi thì tiến hành update lastest brew như sau:
[email protected] ~ % brew update && brew upgrade
Updated 1 tap (homebrew/core).
==> New Formulae
swift-sh
==> Updated Formulae
apache-spark               jetty                      xcodegen
docker-slim                vim                        zsh-syntax-highlighting
Updating Homebrew...

Kiểm tra caskjava

brew cask info java

Nếu homebrew/cask chưa được cài đặt thì nó sẽ tự động cài đặt luôn

[email protected] ~ % brew cask info java
==> Tapping homebrew/cask
Cloning into '/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask'...
remote: Enumerating objects: 3655, done.
remote: Counting objects: 100% (3655/3655), done.
remote: Compressing objects: 100% (3648/3648), done.
remote: Total 3655 (delta 26), reused 510 (delta 5), pack-reused 0
Receiving objects: 100% (3655/3655), 1.23 MiB | 215.00 KiB/s, done.
Resolving deltas: 100% (26/26), done.
Tapped 1 command and 3543 casks (3,660 files, 4.0MB).
java: 13.0.2,8:d4173c853231432d94f001e99d882ca7
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rb
==> Name
OpenJDK Java Development Kit
==> Artifacts
jdk-13.0.2.jdk -> /Library/Java/JavaVirtualMachines/openjdk-13.0.2.jdk (Generic Artifact)
  • Nếu đã cài đặt rồi bạn sẽ nhận được thông tin về phiên bản java đã được cài đặt
[email protected] ~ % brew cask info java
java: 13.0.2,8:d4173c853231432d94f001e99d882ca7
https://openjdk.java.net/
Not installed
From: https://github.com/Homebrew/homebrew-cask/blob/master/Casks/java.rb
==> Name
OpenJDK Java Development Kit
==> Artifacts
jdk-13.0.2.jdk -> /Library/Java/JavaVirtualMachines/openjdk-13.0.2.jdk (Generic Artifact)

Tiến hành cài đặt Oracle JDK sử dụng brew cask

[email protected] ~ % brew cask install oracle-jdk
==> Caveats
Installing oracle-jdk means you have AGREED to the license at:
  https://www.oracle.com/technetwork/java/javase/terms/license/javase-license.html

==> Downloading https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173c8532
==> Downloading from https://download.oracle.com/otn-pub/java/jdk/13.0.2+8/d4173
######################################################################## 100.0%
==> Verifying SHA-256 checksum for Cask 'oracle-jdk'.
==> Installing Cask oracle-jdk
==> Running installer for oracle-jdk; your password may be necessary.
==> Package installers may write to any location; options such as --appdir are i
Password:
installer: Package name is JDK 13.0.2
installer: Installing at base path /
installer: The install was successful.
🍺  oracle-jdk was successfully installed!

Kiểm tra phiên bản java sau khi cài đặt

[email protected] ~ % java --version
java 13.0.2 2020-01-14
Java(TM) SE Runtime Environment (build 13.0.2+8)
Java HotSpot(TM) 64-Bit Server VM (build 13.0.2+8, mixed mode, sharing)
[email protected] ~ % javac --version
javac 13.0.2

setting JAVA_HOME

Thêm export JAVA_HOME=$(/usr/libexec/java_home) vào ~/.zshrc

echo 'export JAVA_HOME=$(/usr/libexec/java_home)' >> ~/.zshrc

Kiểm tra biến JAVA_HOME

Đóng Termial sau đó bật lại và kiểm tra biến JAVA_HOME

[email protected] libexec % echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-13.0.2.jdk/Contents/Home

Như vậy là bạn đã tiến hành cài đặt thành công Oracle Java rồi.
Tài liệu tham khảo
https://emcorrales.com/blog/install-oracle-jdk-macos-homebrew

1 comment
9

1 comment

Duc Nguyen March 2, 2020 - 10:23 PM

Hay quá a Híu

Reply

Leave a Comment

* By using this form you agree with the storage and handling of your data by this website.

You may also like

%d bloggers like this: