I am trying to install Java on a Linux server.
Linux server details
NAME="Oracle Linux Server"
VERSION="7.9"
System Architecture
x86_64
What I have tried so far
I have downloaded x64 Compressed Archive from https://download.oracle.com/java/24/latest/jdk-24_linux-x64_bin.tar.gz and extracted it in the /usr/java/
folder as a super user by using sudo su
command. Then I updated the values of the PATH
and JAVA_HOME
variables in the .bashrc
file. The echo $PATH
command and echo $JAVA_HOME
returned the below values.
/sbin:/bin:/usr/sbin:/usr/bin:/apps/local/go/bin:/apps/local/go/dev/bin:/usr/java/jdk-24/bin
/usr/java/jdk-24
Then I ran java -version
to check the installation. But it returned below error.
bash: /usr/java/jdk-24/bin/java: cannot execute binary file
I did enough googling and tried the below workarounds
sudo update-alternatives --config java
// it didn't return any valuechmod +x /usr/java/jdk-24/bin/java
// didn't work
Then I navigated to my user folder (/home/XXX
) and opened .bash_profile
file:
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
PATH=$PATH:$HOME/.local/bin:$HOME/bin
export JAVA_HOME=/usr/local/lib/java/jdk-24
export PATH=$JAVA_HOME/bin:$PATH
export PATH
Then I ran source .bash_profile
and then ran java -version
, which showed the following:
java version "24" 2025-03-18
Java(TM) SE Runtime Environment (build 24+36-3646)
Java HotSpot(TM) 64-Bit Server VM (build 24+36-3646, mixed mode, sharing)
If I exit the root user and try again, it shows the "cannot execute binary file" error again.
Please help me to solve this issue.