Java is a popular programming language used for developing a wide variety of applications, from web to desktop software. OpenJDK (Open Java Development Kit) is an open-source implementation of the Java Platform, Standard Edition (Java SE). In this guide, we will explain how to install OpenJDK on FunOS, set up the necessary environment variables, and uninstall OpenJDK if needed.
What is OpenJDK?
OpenJDK is an open-source implementation of the Java SE platform, maintained by the OpenJDK community. It provides the complete Java runtime environment, including tools such as the Java compiler (javac) and the Java Virtual Machine (JVM). OpenJDK is typically used for development because it is free and has community-driven support.
Comparison with Oracle JDK:
- OpenJDK is open-source, whereas Oracle JDK is developed by Oracle and includes additional commercial features.
- Starting from Java 11, Oracle JDK requires a commercial license for use in production, while OpenJDK remains free for both development and production use.
- In terms of functionality, both JDKs are very similar, with most developers choosing OpenJDK due to its open-source nature.
How to Install OpenJDK on FunOS
FunOS, being based on Ubuntu, allows you to easily install OpenJDK from the default repositories. Below are step-by-step instructions to install OpenJDK.
Installing from the Ubuntu Repositories
- Open a Terminal
There are multiple ways to open the terminal in FunOS:
- Click the Menu in the lower-left corner, then click Terminal.
- Click the Terminal icon in the Tray.
- Use the keyboard shortcut Ctrl + Alt + T.
- Update the Package List
Before installing any package, it’s a good practice to ensure the package list is up to date by running:
sudo apt update
- Install OpenJDK
To install the default OpenJDK version, use the following command:
sudo apt install default-jdk
- Verifying the Installation
After the installation, you can verify that OpenJDK is installed and check the version by running:
java --version
The output should look similar to:
openjdk 21.0.4 2024-07-16
OpenJDK Runtime Environment (build 21.0.4+7-Ubuntu-1ubuntu224.04)
OpenJDK 64-Bit Server VM (build 21.0.4+7-Ubuntu-1ubuntu224.04, mixed mode, sharing)
Set the Environment Variables for Java
To ensure that Java can be used system-wide and that tools like Maven or Gradle can locate the Java Development Kit (JDK), you need to set the JAVA_HOME
environment variable. This variable points to the directory where Java is installed.
- Edit the
.bashrc
File
The.bashrc
file in your home directory is responsible for configuring your terminal environment. To set up Java environment variables, you will need to edit this file. Open the.bashrc
file using the mousepad editor with the following command:
mousepad ~/.bashrc
- Add the Following Definitions
Scroll to the bottom of the.bashrc
file and add these lines:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin
- JAVA_HOME points to the location of the JDK installation directory.
- PATH ensures that the
java
andjavac
commands are accessible from the command line.
- Save the File
After adding the above lines, save the.bashrc
file and close the editor.
- Apply the Changes
For the changes to take effect immediately, you need to “source” the.bashrc
file:
source ~/.bashrc
Now your system is configured to use OpenJDK, and the environment variables are set correctly.
How to Uninstall OpenJDK on FunOS
If for any reason you need to remove OpenJDK from your FunOS system, you can follow these steps to safely uninstall it.
Uninstalling OpenJDK
- Open a Terminal
As mentioned earlier, you can open a terminal using Menu > Terminal, Terminal icon in the Tray, or Ctrl + Alt + T.
- Remove OpenJDK
To uninstall OpenJDK, run the following command:
sudo apt remove --purge default-jdk
- Remove Unused Dependencies
After removing OpenJDK, you can clean up any unused dependencies with:
sudo apt autoremove --purge
Remove Environment Variables
If you want to completely remove all traces of Java from your system, you also need to remove the environment variables that were set earlier.
- Edit the
.bashrc
File
Open the.bashrc
file using the mousepad editor:
mousepad ~/.bashrc
- Remove the Java Definitions
Find the lines that define the Java environment variables:
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin
Delete these lines from the file.
- Save the File
After removing the lines, save the.bashrc
file and close the editor.
- Apply the Changes
As before, “source” the.bashrc
file to apply the changes:
source ~/.bashrc
This ensures that the Java environment variables are no longer active on your system.
Conclusion
Installing OpenJDK on FunOS is a simple process that can be accomplished in just a few steps. OpenJDK provides a free, open-source alternative to Oracle JDK, making it a great choice for Java development. This guide has walked you through installing OpenJDK, configuring the necessary environment variables, and uninstalling it if needed. Now you can start developing Java applications or running Java-based programs with ease on FunOS.
Leave a Reply