How to Install Java on Ubuntu - Step-by-Step Guide

Опубликовано: 17 Октябрь 2024
на канале: SkillSharp
944
10

Are you looking to install Java on your Ubuntu system? In this step-by-step tutorial, we'll guide you through the process to set up Java on Ubuntu. Follow these simple steps to ensure a smooth installation.

Step 1: Download JDK 8
Start by downloading the JDK 8 tar.gz file from the official website. This file will be the foundation for your Java installation.

Step 2: Extract Contents
Use the 'tar' command to extract the contents of the downloaded file. Execute the command 'tar -xzvf filename.tar.gz' in your terminal to unpack the contents.

Step 3: Move Extracted Files
Create a directory for Java in /usr/local/ and move the extracted files there. Use the following commands:

sudo mkdir /usr/local/java
cd /home/akshay/Downloads/
sudo mv jdk_folder /usr/local/java/jdk_folder

Step 4: Update Alternatives
Update the alternatives for Java, Java compiler, and Java Web Start using the following commands:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk_folder/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk_folder/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk_folder/bin/javaws" 1

Step 5: Update bashrc File
Open the .bashrc file using a text editor and add the following lines at the end:
sudo gedit ~/.bashrc

Add:
export JAVA_HOME=/usr/local/java/jdk_folder
export PATH=$PATH:$JAVA_HOME/bin

Step 6: Apply Changes
Source the .bashrc file to apply the changes:
source ~/.bashrc

Step 7: Check Java Version
java -version

Congratulations! You've successfully installed Java on your Ubuntu system. Now you're ready to start developing and running Java applications. If you found this tutorial helpful, don't forget to like, share, and subscribe for more tech tutorials. Thanks for watching!