Setting a JAVA HOME Path in Ubuntu

open jdk 8μ—μ„œ 11둜 λ°”κΎΈλ©΄μ„œ JAVA_HOME μž¬μ„€μ • ν•œ 것 μ •λ¦¬ν•΄μš©

1. Install

sudo apt-get install openjdk-11-jdk
  • 이 λͺ…λ Ήμ–΄λ‘œ Java runtime environmentλ₯Ό κ°–κ³ μžˆλŠ” openjdk-11-jre package κΉŒμ§€ μ„€μΉ˜λœλ‹€!

2. Check the version

chloe@chloe-XPS-15-9570 ~
$ java -version
openjdk version "11.0.8" 2020-07-14
OpenJDK Runtime Environment (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1)
OpenJDK 64-Bit Server VM (build 11.0.8+10-post-Ubuntu-0ubuntu118.04.1, mixed mode, sharing)

3. Find where JDK is installed

  • /usr/lib/jvm/κ²½λ‘œμ— κ°€λ©΄ μ„€μΉ˜ν•œ JDK 듀을 확인할 수 μžˆλ‹€

    chloe@chloe-XPS-15-9570 ~
    $ cd /usr/lib/jvm/
    
    chloe@chloe-XPS-15-9570 /usr/lib/jvm
    $ ls
    default-java     java-11-openjdk-amd64     java-8-openjdk-amd64
    java-1.11.0-openjdk-amd64  java-1.8.0-openjdk-amd64  openjdk-11
    

4. Set environment variable

vim으둜 /etc/environment μ—΄κΈ°

sudo vi /etc/environment

μ•„λž˜μ˜ ν™˜κ²½λ³€μˆ˜λ₯Ό μΆ”κ°€ν•˜κΈ°

JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export JAVA_HOME

source λͺ…λ Ήμ–΄λ‘œ μˆ˜μ •λœ κ°’ λ°”λ‘œ μ μš©ν•˜κΈ°

source /etc/environment

5. Check the environment variable

5-1. echo λͺ…λ Ήμ–΄λ‘œ μ„€μ •ν•œ ν™˜κ²½λ³€μˆ˜ ν™•μΈν•˜κΈ°

chloe@chloe-XPS-15-9570 /usr/lib/jvm
$ echo $JAVA_HOME
/usr/lib/jvm/java-11-openjdk-amd64

5-2. printenv λͺ…λ Ήμ–΄λ‘œ ν™•μΈν•˜κΈ°

chloe@chloe-XPS-15-9570 /usr/lib/jvm
$ printenv | grep "java"
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
  • grep 을 μ‚¬μš©ν•˜λ©΄ νŠΉμ • λ¬Έμžμ—΄μ„ 찾을 수 μžˆλ‹€!

    • μ—¬κΈ°μ„œλŠ” "java" λ₯Ό μ°ΎλŠ” 것!

끝~!

+

Alternatives 쀑에 ν•„μš”ν•œ λ²„μ „μœΌλ‘œ λ°”κΎΈμ–΄μ„œ Build ν•˜κ³ μ‹Άμ„ λ•Œ

chloe@chloe-XPS-15-9570 ~
$ sudo update-alternatives --config java
[sudo] password for chloe: 
There are 2 choices for the alternative java (providing /usr/bin/java).

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1111      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode

Press <enter> to keep the current choice[*], or type selection number: 
  • μ›ν•˜λŠ” version의 번호λ₯Ό μž…λ ₯ν•˜λ©΄ λ³€κ²½ κ°€λŠ₯ν•˜λ‹€

Last updated