When to use this command
Use this command when you:- Have downloaded a new Java JDK tar file (e.g.,
jdk-21.tar.gz) - Want to add another Java version to your system
- Need to install a specific Java version for project requirements
Prerequisites
Before running this command, ensure:
- You have a Java tar file downloaded
- The
/opt/javadirectory exists on your system - You have sudo privileges
Step-by-step usage
Enter tar file name
When prompted, enter the name of your Java tar file:The tar file should be in your current directory.
Tar extraction
The tool automatically extracts the tar file and moves it to You’ll then see a list of all Java folders in
/opt/java/:/opt/java.Specify folder name
Enter the folder name for your new Java version:This is the directory name inside
/opt/java/ where your Java installation resides.Set version priority
Assign a priority number to your Java version:Higher numbers = higher priority. The system will use the highest priority version when set to auto mode.
What happens behind the scenes
The command performs several operations as shown ininternal/commands/newjava.go:13-78:
1. Directory verification
/opt/java exists, creating it if necessary.
2. Tar extraction and move
3. Register with update-alternatives
For each binary (java, javac, jar), the tool runs:
Real terminal example
Common use cases
Installing multiple Java versions for different projects
Installing multiple Java versions for different projects
If you maintain projects requiring different Java versions, install each version with appropriate priority:
- Java 8: priority 800
- Java 11: priority 1100
- Java 17: priority 1700
- Java 21: priority 2100
Testing new Java releases
Testing new Java releases
When a new Java version is released, you can install it alongside existing versions without affecting your current setup. Give it a lower priority initially for testing.
Installing Oracle vs OpenJDK versions
Installing Oracle vs OpenJDK versions
You can install both Oracle JDK and OpenJDK versions side by side, using different folder names like
jdk-17-oracle and jdk-17-openjdk.Troubleshooting
Error: Directory /opt/java doesn’t exist- Create it with:
sudo mkdir -p /opt/java
- Ensure you have sudo privileges
- The command will prompt for your password when needed
- Verify the tar file is in your current directory
- Check the tar file isn’t corrupted:
tar -tzf your-file.tar.gz