Ehsan Sadeghi
Ehsan Sadeghi

Reputation: 47

Install java on Centos 7 and Command not known error

I downloaded JDK8U171 and copy it to /opt/jdk1.8.0_171/. I installed it by these commands :

alternatives --install /usr/bin/java java /opt/jdk1.8.0_171/bin/java 2
alternatives --config java

after this java -version worked perfectly

java version "1.8.0_171"
Java(TM) SE Runtime Environment (build 1.8.0_171-b11)
Java HotSpot(TM) 64-Bit Server VM (build 25.171-b11, mixed mode)

all these works were done by root. In my user account when I enter java -version I got /usr/bin/java : Permission denied but when I use

usermod a+x /usr/bin/java

I get command not known. I exported $PATH = $PATH:/opt/jdk1.8.0_171/bin but it's not useful. which java also returns /usr/bin/which: no java in (/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin:/home/esadeghi/.local/bin:/home/esadeghi/bin:/opt/jdk1.8.0_171/bin:/usr/bin/java:/opt/jdk1.8.0_171/bin)

Upvotes: 2

Views: 1374

Answers (1)

Mikhail Kholodkov
Mikhail Kholodkov

Reputation: 25176

You have to grant read permissions to your user with chmod and/or assign your user to the group and grant the permissions.

Also, you can install JDK (or JRE) using yum installer it should assign proper permissions automatically.

Or you can just download binary package from Oracle website, then unzip it to any appropriate folder and grant full read permissions (chmod -R 777 /jdk1.8.0_171) to the folder for everyone.

Upvotes: 1

Related Questions