-1

I'm trying to install java (jre 1.8) on Linux Suse,

I've downloaded the tar.gz file from oracle website and unzipped it.

Now I have java on my machine but I can only run it like that:

./java -version
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

running the command by itself doesn't work:

/usr/java/jdk1.8.0_91/bin # java -version
If 'java' is not a typo you can run the following command to lookup the package that contains the binary:
    command-not-found java
-bash: java: command not found

enter image description here

So obviously I can't add to the PATH because it will not be recognized.

Does anyone know what am I missing?

Shahar Hamuzim Rajuan
  • 5,610
  • 9
  • 53
  • 91
  • 1
    You need to add the directory `/usr/java/jdk1.8.0_91/bin` to your executable search path. `export PATH=/usr/java/jdk1.8.0_91/bin:${PATH}`. I'm not familar with Suse, but in your user home there should be some `.profile` file where you can add this setting. If you want to change it for all users have a look for a file `/etc/profile`. – SubOptimal May 08 '16 at 11:31
  • But how does it make sense to add it to the PATH if it's not running as it should from the "bin" directory itself? – Shahar Hamuzim Rajuan May 08 '16 at 11:35

1 Answers1

2

Linux is not Windows. If you start a executable without a path the system will start it only if it's found in one of the directories specified in PATH.

This means even if the executable you want to run is in your current directory it would not be executed if this directory is not in PATH. If you explicitly specify the directory the executable will be executed even the directory it's not in PATH.

See some small examples.

Following s assumed: /usr/java/jdk1.8.0_91/bin is not specified in PATH.

cd /tmp
java 

Would fail as /tmp is not in PATH.

cd /tmp
./java

Would fail as there is (normally) no java executable in the /tmp directory.

cd /usr/java/jdk1.8.0_91/bin
java

Would fail as /usr/java/jdk1.8.0_91/bin is not in PATH.

cd /usr/java/jdk1.8.0_91/bin
./java

Would be executed as you explicitly specify to run java found in the current directory ./.

SubOptimal
  • 22,518
  • 3
  • 53
  • 69
  • 1
    In Suse you need to Add /etc/profile.local and the PATH addition will survive upgrades for the regular users. For root check the .profile located in /etc – Shahar Hamuzim Rajuan May 08 '16 at 12:20
  • @ShacharHamuzimRajuan Thanks for adding this information, related for Suse. As the location and file names might be different depending on the used Linux distribution. – SubOptimal May 09 '16 at 05:32