0
0

JDKのインストール

Posted at

はじめに

JDKをインストールした時のログです。

以下のOracle Linuxにインストールします。

$ cat /etc/oracle-release 
Oracle Linux Server release 8.8

ダウンロード

ここでは/usr/java配下にインストールします。

$ sudo su - 
# mkdir /usr/java
# cd /usr/java/

以下のサイトから環境に合ったバイナリーをダウンロードして、展開します。

# wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz
--2023-09-21 04:44:00--  https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz
Resolving download.oracle.com (download.oracle.com)... 104.93.8.87
Connecting to download.oracle.com (download.oracle.com)|104.93.8.87|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 197176830 (188M) [application/x-gzip]
Saving to: ‘jdk-21_linux-x64_bin.tar.gz’

jdk-21_linux-x64_bin.tar.gz                100%[=======================================================================================>] 188.04M   150MB/s    in 1.3s    

2023-09-21 04:44:02 (150 MB/s) - ‘jdk-21_linux-x64_bin.tar.gz’ saved [197176830/197176830]
# tar zxvf jdk-21_linux-x64_bin.tar.gz 

確認します。

# ls -l jdk-21
total 24
drwxr-xr-x.  2 root  root  4096 Sep 21 04:45 bin
drwxr-xr-x.  5 root  root   146 Sep 21 04:45 conf
drwxr-xr-x.  3 root  root   132 Sep 21 04:45 include
drwxr-xr-x.  2 root  root  4096 Sep 21 04:45 jmods
drwxr-xr-x. 71 root  root  4096 Sep 21 04:45 legal
drwxr-xr-x.  5 root  root  4096 Sep 21 04:45 lib
lrwxrwxrwx.  1 10668 10668   23 Aug  9 20:39 LICENSE -> legal/java.base/LICENSE
drwxr-xr-x.  3 root  root    18 Sep 21 04:45 man
-rw-r--r--.  1 10668 10668  290 Aug  9 20:39 README
-rw-r--r--.  1 10668 10668 1243 Aug  9 20:39 release
# exit

JAVA_HOMEの設定

.bashrcファイルに以下を追記して、反映させます。

.bashrc
export JAVA_HOME=/usr/java/jdk-21
export PATH=$JAVA_HOME/bin:$PATH
export CLASSPATH=.:$JAVA_HOME/jre/lib:$JAVA_HOME/lib:$JAVA_HOME/lib/tools.jar
$ . .bashrc 

確認します。

$ echo $JAVA_HOME
/usr/java/jdk-21
$ java --version
java 21 2023-09-19 LTS
Java(TM) SE Runtime Environment (build 21+35-LTS-2513)
Java HotSpot(TM) 64-Bit Server VM (build 21+35-LTS-2513, mixed mode, sharing)

動作確認

以下のコードをコンパイル、実行して動作を確認します。

hello.java
public class hello{
  public static void main(String[] args){
    System.out.print("Hello");
  }
}
$ javac hello.java 
$ ls -l
total 8
-rw-rw-r--. 1 opc opc 407 Sep 21 05:04 hello.class
-rw-rw-r--. 1 opc opc  99 Sep 21 04:58 hello.java
$ java hello
Hello
0
0
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
0
0