Saturday, October 19, 2024

Install java (openjdk and oraclejdk) on fedora 40



search openjdk version

dnf search openjdk

sudo dnf install java-latest-openjdk.x86_64




java -version




showing i installed version 21




now go the oracle jdk download page




https://www.oracle.com/java/technologies/downloads/?er=221886




I downloaded jdk-23_linux-x64_bin.tar.gz




sudo mkdir -p /usr/local/java




cd Downloads



sudo cp -r jdk-23_linux-x64_bin.tar.gz /usr/local/java



sudo tar zxvf jdk-23_linux-x64_bin.tar.gz




sudo nano /etc/profile



add the following lines





JAVA_HOME=/usr/local/java/jdk-23.0.1
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH


save the file and close
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk-23.0.1/bin/java" 1
echo $?
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk-23.0.1/bin/javac" 1
echo $?
sudo update-alternatives --install "/usr/bin/javaws.itweb" "javaws.itweb" "/usr/local/java/jdk-23.0.1/bin/javaws.itweb" 1
echo $?
sudo update-alternatives --set java /usr/local/java/jdk-23.0.1/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk-23.0.1/bin/javac
sudo update-alternatives --set javaws.itweb /usr/local/java/jdk-23.0.1/bin/javaws.itweb
source /etc/profile
reboot

now both java and javac command is working..

 

Source:https://phoenixnap.com/kb/fedora-install-java




































No comments:

Post a Comment