java version in linux - java

# which java
/usr/bin/which: no java in (/usr/local/jdk/jdk1.5.0_10/bin/java:/usr/local/jdk/jdk1.5.0_10/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin)
I installed java in /usr/local/jdk/jdk1.5.0_10 but cannot run java -version
I get this
$ java -version
-bash: /usr/bin/java: No such file or directory
this is red hat linux

It's not in your path.
use
export PATH=$PATH:/usr/local/jdk/jdk1.5.0_10/bin
export JAVA_HOME=/usr/local/jdk/jdk1.5.0_10
Look at ~/.bash_profile for where to define this permanatly.

Can you do
ls /usr/local/jdk/jdk1.5.0_10/bin
And why is /usr/local/jdk/jdk1.5.0_10/bin/java in your path?

Must be in local path of java before running to see what version is installed. Use find / -name java (this will list anything with java on the server copy the path ). path should end with..../jre/bin/java
copy full path.
Open Java location of the path you copied above, remove java at the end you path then enter,
Enter command below:
./Java -Version

Related

Installed Java SE Development Kit, but can't use the command javac

I've just installed the Java SE Development Kit from http://www.oracle.com/technetwork/java/javase/downloads/jdk10-downloads-4416644.html
I've created a test java file, to make into a Java class and run - the code is the following:
public class Hello {
public static void main(String[] args){
System.out.println("Hello World!");
}
}
I then saved this as Hello.java and fired up Terminal (i'm on Mac OSX).
I simply type in:
javac Hello.java
and it returns the following error message:
-bash: javac: command not found
If anyone knows why and could help me fix the issue that'd be fantastic.
Download the right option. According to the download link, you're using an Oracle JDK. As a macOS user, you should choose the option dk-10.0.1_osx-x64_bin.dmg to download.
Ensure JDK 10 is installed. By default, Oracle JDK is installed in system directory /Library/Java/JavaVirtualMachines/. Browse it and check if there's a sub-directory called jdk-10.jdk:
$ ls /Library/Java/JavaVirtualMachines/
jdk-10.jdk jdk-11.jdk jdk-9.0.4.jdk jdk1.8.0_131.jdk
Check Java Control Panel. Go to "System Preferences" > "Java" to check the Java version installed.
Check the PATH variable. Ensure /usr/bin/ is included in it.
$ type javac
javac is /usr/bin/javac
$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/MacGPG2/bin
^
Check your %PATH% variable. Your %PATH% variable must have path to the bin directory in your JDK's installation directory. The PATH variable allows you to access certain files without having to specify their full path, you can check how to add JDK to your PATH here. If you do not want to mess with it, all you have to do is either cd into bin directory of your JDK installation or always specify the full path to javac, the choice is yours.

Setting JAVA_HOME variable

I try to set JAVA_HOME variable on an ubuntu server. I get the Java path with this command
which java
/usr/bin/java
I set the result in /etc/environment
JAVA_HOME="/usr/bin/java"
When I try to run a mvn command I get this error
Error: JAVA_HOME is not defined correctly.
We cannot execute /usr/bin/java/bin/java
You should not set JAVA_HOME to /usr/bin/java, because that's just a symbolic link to the java executable, which points to where the real executable is.
JAVA_HOME should point to the Java installation directory, and not to the java executable (or a link to the executable).
Find out where your Java installation directory is and then set JAVA_HOME to that directory (and not to the java executable). If you installed Java using Ubuntu's package management system, then the Java home directory is probably one of the subdirectories in /usr/lib/jvm.
Per the Oracle site:
export JAVA_HOME=jdk-install-location
export PATH=$JAVA_HOME/bin:$PATH
You can add these lines into your ~/.bash_profile (or ~/.bashrc), and then refresh using source ~/.bash_profile

java path setting on windows 8.1

I am trying to set java path on my windows 8.1, and i installed jdk 8u 64 bit and in environmental variables under system variables there is no PATH found,so i incuded new path variable to set path for jdk and jre ,by copying the bin path of jdk C:\Program Files (x86)\Java\jdk1.8.0_40\bin and i appended jre path C:\Program Files (x86)\Java\jre1.8.0_40,but it doesnt work when i tried in command prompt by typing "java -version"
and "javac" it says that java is not a internal or external command. and i had a doubt that to run java through command prompt ,do we need any other installations like turbo c
please help me out to set path in my pc,i am a begginer of java
thank you
javac is not part of jre, but part of jdk. So have C:\Program Files (x86)\Java\jdk1.8.0_40\bin;C:\Program Files (x86)\Java\jre1.8.0_40\bin in the path. As Anand noted, the ; is missing as well.
This path is wrong -
C:\Program Files (x86)\Java\jdk1.8.0_40C:\Program F iles
(x86)\Java\jre1.8.0_40\bin
you need a ; in between the two different paths.
Try adding this instead -
C:\Program Files (x86)\Java\jdk1.8.0_40\bin;C:\Program F iles
(x86)\Java\jre1.8.0_40\bin
If you are trying to add the path in the user variables
JAVA_HOME=C:\Program Files\Java\jdk1.8.0_66
in the JAVA_HOME don't add any semicolan (;) and
path=C:\Program Files\Java\jdk1.8.0_66\bin;.;
in the path section end of the line add ;.; to consider all paths and save. Then try to restart system and open the command prompt and try to check
java -version
javac
JAVA_HOME AND PATH

How to install java 7 on mac in custom location?

I want to install java 7 on mac silently. I am unable to find any documentation/links on the same. Also I don't want it in /Library. Is it possible to install the same on any custom location. I am very new to mac any help is highly appreciated.
Just to make the steps from #HawkMage more explicit (and illustrate them working with JDK8):
Download the binary (eg, jdk-8u5-macosx-x64.dmg) from Oracle
Double click from Finder to mount the Volume. Ignore the window with the “JDK 8 Update x.pkg”
Use pkgutil to expand the contents of the package into a temporary directory:
$ pkgutil --expand /Volumes/JDK\ 8\ Update\ 05/JDK\ 8\ Update\ 05.pkg /tmp/jdkpkg
Then, change to that dir and use cpio to expand the Payload file:
$ cd /tmp/jdkpkg
$ cpio -i < ./jdk18005.pkg/Payload
Finally, move the Home dir to wherever you’d like your JAVA_HOME to live
$ mv Contents/Home /mytools/jdk-1.8.0_05
Unfortunately the "standard" Java that comes on OS X is packaged in a very non-standard way.
It is not as easy as linux, the DMG downloaded gives you a PKG file that if you run it just installs Java. This is not useful if you are trying to keep the standard Java that comes with OS X intact.
What I do is download the DMG file from Oracle and open it but instead of running the PKG I use pkgutil to extract the contents of the package. You will find a directory named jdk*.pkg and in it you will see a file named Payload. This is a GZipped CPIO file and you can extract it by cating it and piping it into cpio -zi. From this you will now have a directory named Contents and under it you will find a directory named Home. This "Home" directory is the what you would normially get with the Linux tar.gz Java download. You can copy it to wherever you want and put the bin directory in your path and set the JAVA_HOME to it and you are good to go.
Just like in Linux, you can pretty much install Java anywhere you like on a mac. You just need to make sure that you add the Java executable to the path or create a symbolic link of the java executable and put it in the /usr/bin/ directory so it can be executed anywhere.
To add Java to path:
1) Modify .bash_profile found in your home director.
2) Add this line: export PATH=/yourjavadir/bin:$PATH
3) Save and exit
4) Then do source .bash_profile to reload the file. You'll only need to do this one time.
To create a symbolic link:
ln -s /yourjavadir/java /usr/bin/java
I had the same issue and just managed to figure it out.
Download and unzip the Java binary in your custom directory. For eg -
/Users/myuser/Documents/jre1.8.0_25.jre
Update your .bash_profile with the following parameters
export JAVA_HOME=/Users/a514624/Documents/jre1.8.0_25.jre/Contents/Home
export PATH=$PATH:$JAVA_HOME/bin
Close the terminal window and open it again. Alternately, you could type the command 'source .bash_profile'.
After these steps, if you type java -version on the command prompt, you would see it reflecting the version which you were hoping to see -
$ java -version
java version "1.8.0_25" Java(TM) SE Runtime
Environment (build 1.8.0_25-b17) Java HotSpot(TM) 64-Bit Server VM
(build 25.25-b02, mixed mode)
Unlink the existing Java softlink (would require root/elevated privileges)
root$ unlink /usr/bin/java
Create a symbolic link to the new Java installation
root$ ln -s /Users/myuser/Documents/jre1.8.0_25.jre/Contents/Home/bin/java /usr/bin/java
Thats it. Life is beautiful after this. Hope this helps!
If you just need JRE/Java Runtime Edition then previous answers arecorrect but if you need JRE and JDK (Java Development Kit) then simply go to below link and select the mac and run the dmg and it's much better and by far the easiest.
http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html

run .jar file with "java" command Centos

I'm trying to run a .jar file on my centos box, but it says "java: command not found".
What's the best or easiest way to solve this? I was hoping for a yum command but not sure that that will exist for java?
Apparently some versions of CentOS doesn't come with a JVM installed due to some licensing restriction. See HowTo Install Java on CentOS 4 and CentOS 5 for instructions.
You can use such command to check if Java is available in your repository:
yum list | grep java
It should return something like that:
java-1.6.0-openjdk
java-1.6.0-sun
If such package exists you can install it using such command (run it as the root user):
yum install java-1.6.0-openjdk
Either the JRE is not installed or, more likely, its location is not included in your PATH environment variable. If the java executable is not in your PATH, you would need to use the full path & filename to execute it.
cd to the location of the jar file
C:\temp>java -jar sample.jar

Categories