This guide will walk you through the complete workflow of using JavaOptionsCli to install and manage Java versions on your system.
Prerequisites
Before you begin, make sure you have:
- JavaOptionsCli installed and accessible from your terminal (see Installation)
- sudo privileges on your system
- A Java JDK
.tar.gz file downloaded
Complete workflow
Place the tar.gz file in a directory
Download a Java JDK .tar.gz file and place it in a directory. For this example, we’ll use Java 21:cd ~/Downloads
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz
You must run JavaOptionsCli from the same directory where the .tar.gz file is located.
Verify the file is present:Example output:-rw-r--r-- 1 user user 185M Mar 4 10:30 jdk-21_linux-x64_bin.tar.gz
Run JavaOptionsCli
Launch JavaOptionsCli from the same directory:You’ll see the interactive menu:╔════════════════════════════════════╗
║ ║
║ ║
║ JavaOptionsCli ║
║ ║
║ ║
╚════════════════════════════════════╝
New Version Java
Changes Version
View List Versions
Delete Version
Update List
Exit
Install a new Java version
Select “New Version Java” from the menu and follow the prompts:1. Enter the tar file name
Enter the name of the tar file
jdk-21_linux-x64_bin.tar.gz
JavaOptionsCli will extract the archive and move it to /opt/java/.2. Choose the Java folder
The tool will list the extracted folder:Here are your Java versions and their folders
jdk-21
ℹ Ej. jdk-21
Enter the folder for the new Java version
jdk-21
3. Set the priority version
ℹ Ej. Java 21 === 2100
Enter the Java version
2100
The priority number determines which version is selected by default when multiple versions are available. Higher numbers have higher priority. A common convention is to use the version number multiplied by 100 (e.g., Java 21 = 2100, Java 17 = 1700).
JavaOptionsCli will register the Java version with update-alternatives:sudo update-alternatives --install /usr/bin/java java /opt/java/jdk-21/bin/java 2100
sudo update-alternatives --install /usr/bin/javac javac /opt/java/jdk-21/bin/javac 2100
sudo update-alternatives --install /usr/bin/jar jar /opt/java/jdk-21/bin/jar 2100
You’ll see: Verify the installation
Back at the main menu, select “View List Versions” to see all installed Java versions:ℹ Showing versions
ℹ Showing Java versions
/opt/java/jdk-21/bin/java
ℹ Showing javac versions
/opt/java/jdk-21/bin/javac
ℹ Showing jar versions
/opt/java/jdk-21/bin/jar
Verify Java is working correctly in your terminal:Example output:java version "21.0.2" 2024-01-16 LTS
Java(TM) SE Runtime Environment (build 21.0.2+13-LTS-58)
Java HotSpot(TM) 64-Bit Server VM (build 21.0.2+13-LTS-58, mixed mode, sharing)
Switching Java versions
If you have multiple Java versions installed, you can easily switch between them:
Open the changes version menu
From the main menu, select “Changes Version”.
Select the Java version
You’ll see the update-alternatives configuration menu for java, javac, and jar:There are 2 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /opt/java/jdk-21/bin/java 2100 auto mode
1 /opt/java/jdk-17/bin/java 1700 manual mode
2 /opt/java/jdk-21/bin/java 2100 manual mode
Press <enter> to keep the current choice[*], or type selection number:
Enter the selection number for your desired Java version and press Enter. Verify the switch
After selecting the version for all three tools (java, javac, jar), verify the change:
Common workflows
Installing multiple Java versions
# Install Java 17
cd ~/Downloads
wget https://download.oracle.com/java/17/latest/jdk-17_linux-x64_bin.tar.gz
JavaOptionsCli
# Select "New Version Java" and follow prompts with priority 1700
# Install Java 21
wget https://download.oracle.com/java/21/latest/jdk-21_linux-x64_bin.tar.gz
JavaOptionsCli
# Select "New Version Java" and follow prompts with priority 2100
Listing all installed versions
JavaOptionsCli
# Select "View List Versions"
Or use update-alternatives directly:
update-alternatives --list java
Removing a Java version
JavaOptionsCli
# Select "Delete Version" and follow the prompts
The “Delete Version” feature will remove the Java installation from /opt/java/ and unregister it from update-alternatives.
Troubleshooting
”Error: permission denied”
JavaOptionsCli requires sudo privileges for certain operations. Make sure you have the necessary permissions:
Ensure you’re running JavaOptionsCli from the same directory as your .tar.gz file:
cd /path/to/tar/file
JavaOptionsCli
Java version not changing
If the Java version doesn’t change after using “Changes Version”, make sure you selected the version for all three tools: java, javac, and jar.
Next steps
Now that you’ve successfully installed and managed Java versions with JavaOptionsCli, you can:
- Install additional Java versions for different projects
- Switch between versions as needed for compatibility
- Use the “Update List” option to refresh the alternatives list
- Explore the “Delete Version” feature to remove unused installations