Mastering the Art of Changing Java Versions in Ubuntu: A Comprehensive Guide
Linux

Mastering the Art of Changing Java Versions in Ubuntu: A Comprehensive Guide

2023-03-06 · 10 分鐘 · Ray Lee (System Analyst)

To change the default Java version in Ubuntu, you can follow these steps:

Check the installed Java versions on your system using the command:

1. Check the installed Java versions on your system using the command:

sudo update-alternatives --config java

This command will list all the installed Java versions on your system along with their paths.

2. Choose the version that you want to use as the default by typing the number next to it.

3. Press Enter to confirm your selection.

4. Check the version of Java that is currently set as the default by typing the command:

java -version

This command will display the version of Java that is currently set as the default on your system.

5. If you want to switch to a different version of Java, repeat the steps above.

6. You can also set the JAVA_HOME environment variable to point to the path of the Java version you want to use. To do this, open the /etc/environment file in a text editor and add the following line:

JAVA_HOME=/path/to/java

Replace “/path/to/java” with the path to the Java version you want to use.

7. Save the file and exit the text editor.

8. To apply the changes, run the following command:

source /etc/environment

This will reload the environment variables and apply the changes you made to the JAVA_HOME variable.

That’s it! You have successfully changed the default Java version in Ubuntu.

English Version

To change the default Java version in Ubuntu, you can follow these steps:

Check the installed Java versions on your system using the command:

1. Check the installed Java versions on your system using the command:

sudo update-alternatives --config java

This command will list all the installed Java versions on your system along with their paths.

2. Choose the version that you want to use as the default by typing the number next to it.

3. Press Enter to confirm your selection.

4. Check the version of Java that is currently set as the default by typing the command:

java -version

This command will display the version of Java that is currently set as the default on your system.

5. If you want to switch to a different version of Java, repeat the steps above.

6. You can also set the JAVA_HOME environment variable to point to the path of the Java version you want to use. To do this, open the /etc/environment file in a text editor and add the following line:

JAVA_HOME=/path/to/java

Replace “/path/to/java” with the path to the Java version you want to use.

7. Save the file and exit the text editor.

8. To apply the changes, run the following command:

source /etc/environment

This will reload the environment variables and apply the changes you made to the JAVA_HOME variable.

That’s it! You have successfully changed the default Java version in Ubuntu.

日本語版

UbuntuでデフォルトのJavaバージョンを変更するには、以下の手順に従ってください:

以下のコマンドを使用して、システムにインストールされているJavaバージョンを確認します:

1. 以下のコマンドを使用して、システムにインストールされているJavaバージョンを確認します:

sudo update-alternatives --config java

このコマンドは、システムにインストールされているすべてのJavaバージョンとそのパスを一覧表示します。

2. デフォルトとして使用したいバージョンの横にある番号を入力して選択します。

3. Enterキーを押して選択を確定します。

4. 以下のコマンドを入力して、現在デフォルトに設定されているJavaのバージョンを確認します:

java -version

このコマンドは、システムで現在デフォルトに設定されているJavaのバージョンを表示します。

5. 別のバージョンのJavaに切り替えたい場合は、上記の手順を繰り返してください。

6. JAVA_HOME環境変数を使用したいJavaバージョンのパスに設定することもできます。これを行うには、テキストエディタで/etc/environmentファイルを開き、以下の行を追加します:

JAVA_HOME=/path/to/java

“/path/to/java”を使用したいJavaバージョンのパスに置き換えてください。

7. ファイルを保存してテキストエディタを終了します。

8. 変更を適用するには、以下のコマンドを実行します:

source /etc/environment

これにより、環境変数が再読み込みされ、JAVA_HOME変数に加えた変更が適用されます。

以上です!Ubuntuでデフォルトの Javaバージョンの変更が完了しました。

Ray Lee (System Analyst)
作者 Ray Lee (System Analyst)

iDempeire ERP Contributor, 經濟部中小企業處財務管理顧問 李寶瑞