javac : command not found - java

I have installed java in my CentOS release 5.5 machine using the command yum install java. But I am unable to compile a class using javac.
Do I need to install any other package?
I have tried to locate the javac executable but i am unable to locate it.
/usr/bin/java is linked as follows:
/usr/bin/java -> /etc/alternatives/java
/etc/alternatives/java -> /usr/lib/jvm/jre-1.6.0-openjdk.x86_64/bin/java
I have seen the following output by yum list installed |grep java:
java-1.6.0-openjdk.x86_64 1:1.6.0.0-1.16.b17.el5 installed
tzdata-java.x86_64 2011b-1.el5 installed

Worked for me with this command:
yum install java-devel

You installed the Java Runtime Environment (JRE) only, which does not provide javac. For javac, you have to install the OpenJDK Development Environment. You can install java-devel or java-11-devel, which both include javac.
By the way: you can find out which package provides javac with a yum search, e.g.
su -c 'yum provides javac'
on more recent releases of CentOS e.g. 6 the command changes to
su -c 'yum provides */javac'

Use the following sudo command:
sudo yum install java-1.6.0-openjdk-devel

I don't know exactly what yum install java will actually install. But to check for javac existence do:
> updatedb
> locate javac
preferably as root. If it's not there you've probably only installed the Java runtime (JRE) and not the Java Development Kit (JDK). You're best off getting this from the Oracle site: as the Linux repos may be slightly behind with latest versions and also they seem to only supply the open-jdk as opposed to the Oracle/Sun one, which I would prefer given the choice.

I use Fedora (currently 31)
Even with JDK's installed, I still need to specify JAVAC_HOME in the .bashrc, especially since I have 4 Java versions using sudo alternatives --configure java to switch between them.
To find java location of java selected in alternatives
readlink -f $(which java)
In my case:
/usr/java/jdk1.8.0_241-amd64/jre/bin/java
So I set following in .bashrc to:
export JAVA_HOME=/usr/java/jdk1.8.0_241-amd64/jre/bin/java
export JAVAC_HOME=/usr/java/jdk1.8.0_241-amd64/bin/javac
export PATH=$PATH:/usr/java/jdk1.8.0_241-amd64/jre/bin
export PATH=$PATH:/usr/java/jdk1.8.0_241-amd64/bin/
Now javac –version gives:
javac 1.8.0_241
This is useful for those who want to use Oracle's version. Just remember to change your .bashrc again if you make a change with java alternatives.

Is the javac executable in a directory that is part of your PATH?
I don't know the CentOS equivalent of the Windows path but if you cd to the java sdk directory and run ./javac does anything happen?

Install same version javac as your JRE
yum install java-devel

This worked for me:
sudo dnf install java-<version>-devel

You have installed the Java Runtime Environment(JRE) but it doesn't contain javac.
So on the terminal get access to the root user sudo -i and enter the password.
Type yum install java-devel, hence it will install packages of javac in fedora.

Linux Mint 19.3
I installed Java Oracle manually, like this:
$ sudo ln -s /usr/lib/jvm/java-1.8.0_211/bin/javac /usr/bin/javac

for java 8 use
sudo yum install java-1.8.0-openjdk-devel

Make sure you install JDK/JRE first.
follow these steps:
open terminal go to your root dictionary by typing
cd /
you will see Library folder
Now follow this path Library/Java/JVM/bin
Once you get into bin you can see the javac file
Now you need to get the path of this folder for that just write this command
pwd
get the path for your javac.

Related

WSL Bash isn't finding java in PATH

I have an export command in my .bashrc to add the path of the java.exe file to PATH. Right now, running echo $PATH gives me this at the end
/mnt/c/Program Files/Java/jdk-14.0.2/bin
This is exactly where the java.exe and javac.exe files are stored, but when I run something like
java -version I'm getting the Command 'java' not found error. What am I doing wrong here?
You have added the Windows version of the Java binaries to the Path. You use WSL to run Linux binaries. (WSL1 is a compatibility layer, WSL2 uses the Linux kernel).
You have two options:
Install Java in your WSL environment. For example on Ubuntu with following commands:
sudo apt update
sudo apt install openjdk-14-jdk
After installing Java it will be available in the search path.
You could also run the Windows version by calling java.exe (note the .exe) on the name. This way WSL would call the Windows version. (https://learn.microsoft.com/en-us/windows/wsl/interop#run-windows-tools-from-linux)
If you want to use the windows version of java for some reason you where almost there. Try this please :)
java.exe -version
Install java in wsl:
sudo apt-get -y install openjdk-14-jdk
check the version.
java –version
check the path to config JAVA_HOME.
sudo update-alternatives --config java
eg
/usr/lib/jvm/java-14-openjdk-amd64/bin/java.
edit environment file to add the path:
sudo nano /etc/environment
add declare and add the JAVA_HOME:
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:$JAVA_HOME/bin"
JAVA_HOME=/usr/lib/jvm/java-14-openjdk-amd64
save and check the path.
source /etc/environment
echo $JAVA_HOME
Output
/usr/lib/jvm/java-14-openjdk-amd64

Install webstorm but no jdk found on ubuntu 14.04LTS

I am trying to install webstorm, but when I try to run the *.sh file it gives me error of not having java environment available.
So I tried to look into the official documentation
But the steps to install the jdk didn't worked. I tried to locate java folder, but couldn't locate this directory /usr/bin/java
Please guide me how I can install webstorm now?
Java generally installs in /usr/lib/jvm/java-[major version]-openjdk-[arch]. Install a package such as openjdk-7-jdk and check in that location.
If you already have java installed, running which java will tell you the path of the java executable.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
I haven't tried with java-8. Then:
sudo update-alternatives --java
And set auto-mode or java-7 (You might try with java-8)
First check the about java version
java -version
if its not returning you need to check your installed jdk
go to
cd /usr/lib/jvm
if you are finding something which start with java_XXXX
it means this is the only your jdk, and you can set JAVA_HOME as well path till bin folder by using export
I had a similar problem, during installation of eclipse (openjdk-7-jdk was required). I used
> sudo apt-get update
> sudo apt-get install ...
and it worked.
You should just install a JRE (to allow Java execution programs) and not a JDK (to develop Java programs).
No need a JDK to allow Webstorm to lauch.
On ubuntu : apt-get install default-jre
Have a nice day :)
David

downgrade java version

I tried to downgrade java version.
If I use apt-get install sun-java6-jdk on Ubuntu, it will install java version 1.6.26 .
What I want is java 1.6.20. How can I downgrade java?
Java on Linux doesn't need to be installed as root. You can install as many different Java versions you want on Linux, either in separate user accounts or in a single account.
I do it all the time (switching from one Java version to another) to test on various versions of the JVM.
Changing your Java version can be as simple as this:
... $ which java
/home/b/jdk1.5.0_22/bin/java
... $ export PATH=/home/b/jdk1.6.0_25/bin:$PATH
... $ which java
/home/b/jdk1.6.0_25/bin/java
To fetch an old version, go to the "Oracle Java Archive" page (Google if link becomes broken):
http://www.oracle.com/technetwork/java/archive-139210.html
Then pick your poison. I download the .bin, chmod +x it and then I extract the Java version I want from the .tgz.
Then I simply set the PATH and I'm usually good to go.
I run my IDE (IntelliJ IDEA) using one Java version, I typically compile using another JDK and I test on several JVMs.
All this from the same user account.
So it's not as if you had to install "one" Java version on a Linux system...
Now, concretely, if I were you, I'd simply remove all traces from Java while being root, and then I'd download the old version I need from the Oracle Java Archive.
like tactical coder said, you can install as many versions as you want, to switch the current version just run:
sudo update-alternatives --config java
And select the desired version.
If you wish, run it for javac and javaws:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
Source:
https://askubuntu.com/questions/56104/how-can-i-install-sun-oracles-proprietary-java-jdk-6-7-8-or-jre
Follow these steps to downgrade JAVA here[JAVA14 to JAVA8]:
sudo apt-get update
sudo apt-get install openjdk-8-jdk
sudo update-alternatives --config javac
Now Select the version of JDK
sudo update-alternatives --config java
Now Select the version of JRE
DONE
Check if it is downgraded by
java -version
You can download it from the archive section for Java SE 6.
$sudo apt-get install openjdk-8-jre (replace with the version you want to install)
$sudo update-alternatives --config java
{will get the option to choose the alternative java on your machine}
select the one you want to use as default
$java -version
Check the java version
I find Jenv to be the easiest way to switch between Java versions. You can set a Java version globally, or you can set it so that certain directories will use a specified version of Java.
See their website
once installed with Homebrew or cloned from github its as easy as:
jenv add /path/to/java1.6.20/home
jenv global 1.6.20

Java installation issues on Ubuntu

Trying to install Java (JDK 6) on my new Ubuntu system and getting some bizarro errors. This is my first time ever using any flavor of Linux and so I'm sure it's a user issue (permissions or otherwise).
I downloaded the BIN file directly off Oracle's site (Java SE 6u23 for 64-bit Linux). This defaulted to downloading to /home/myUserName/Downloads.
From there I moved the file to /opt/java, which was a directory I created, because (as a Linux novice) that made sense to be the directory where Java should go.
I then ran the following 2 commands, per instruction I found online for running BINs:
chmod +x jdk-6u23-linux-x64.bin
sudo ./jdk-6u23-linux-x64.bin
Now, in my /opt/java directory I see both the BIN file and the jdk1.6.0_23 directory that seems to be intact upon inspection.
But, when I open a new terminal and run java -version, I get:
The program 'java' can be found in the following packages:
- gcj-4.4-jre-headless
- gcj-4.5-jre-headless
- openjdk-6-jre-headless
Try: sudo apt-get install
What is going on here?!?
(1) Was I wrong to try and make /opt/java my Java directory?
(2) Did I run the wrong commands?
(3) Is Java 1.6.0_23 even installed on my machine?
(4) What are all those gcj-xxx-headless targets?!?!
Thanks for any input!
Was I wrong to try and make /opt/java my Java directory?
Not really. Many Java developers install multiple JDK installations and always use /opt/jdk1.6.0_23 or similar paths. The bin file you downloaded is not an installer, but merely an extractor. It does not install the java binaries into system folders like /bin.
I usually download the JDK and execute it from within my home folder and afterwards move it to /opt and performing an chown.
Did I run the wrong commands?
Not really. In case you wanted to install a separate JDK, you did it correctly. In case you wanted system integration, you would be better off to use the distribution-specific packages, such as the one installed via aptitude install sun-java6-jdk or alike.
The bin you downloaded is imho more flexible, since I can use it to install multiple verisons of Java on the same system. I know this is something you don't often do on Linux machines.
If you want to use the java binary on command line, you'd have to manually set up the PATH and JAVA_HOME environment variables. I think on Ubuntu that's /etc/environment or /etc/profile or something like that.
Is Java 1.6.0_23 even installed on my machine?
Not really. See above answers.
What are all those gcj-xxx-headless targets?!?
The GCJ is the Gnu Compiler for Java. Obviously, it includes a Java Development Kit and a Java Runtime Environment.
Why downloading a bin, when you can simply:
sudo apt-get install sun-java6-jdk
If there isn't any special reason why you'd want that specific version from the site, you should use apt-get because it will take care of all the stuff like PATH variable, etc.
Please follow below steps to install oracle java:
Download the latest Java SE SDK version.
http://www.oracle.com/technetwork/java/javase/downloads/index.html
Untar the Archive:
tar -xzvf jdk-8-linux-x64.tar.gz
mv jdk1.8.0 /opt
cd /opt/jdk1.8.0
This step registers the downloaded version of Java as an alternative, and switches it to be used as the default:
update-alternatives --install /usr/bin/java java /opt/jdk1.8.0/bin/java 1
update-alternatives --install /usr/bin/javac javac /opt/jdk1.8.0/bin/javac 1
update-alternatives --install /usr/lib/mozilla/plugins/libjavaplugin.so mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so 1
update-alternatives --set java /opt/jdk1.8.0/bin/java
update-alternatives --set javac /opt/jdk1.8.0/bin/javac
update-alternatives --set mozilla-javaplugin.so /opt/jdk1.8.0/jre/lib/amd64/libnpjp2.so
Test
To check the version of Java you are now running
java -version
Output
java version "1.8.0"
Java(TM) SE Runtime Environment (build 1.8.0-b132)
Java HotSpot(TM) 64-Bit Server VM (build 25.0-b70, mixed mode)
To check the browser plugin browse to http://www.java.com/ and click “Do I have Java?”
Ref: https://askubuntu.com/questions/437776/ubuntu-13-04-unable-to-install-jdk7
You simply have put the JDK binaries in a directory. Although by convention /opt/java or /opt/jdk is often used, these are not directories that are automatically recognized by the system.
You can however update your PATH environment variable to include the /opt/java/bin dir, or symlink (ln -s) /opt/java/bin/java in one of the directories on your system that are included in your path like /usr/bin/
The JDK you installed from Sun/Oracle is the original JDK. The "headless" JDK is the open source alternative.
When you run the JDK BIN file, it simply extracts the archive. When you entered the java -version command, it found the FOSS Java, not the Java you had extracted in /opt. As somebody else had mentioned, developers keep multiple versions of the JDK. If you wish to use the Oracle's Java, then you need link /usr/bin/java to /opt/jdk1.6.0_23/bin/java.
sudo ln -s /usr/bin/java /opt/jdk1.6.0_23/bin/java
For this to work, the existing java command should be first delinked from the "headless" JDK. (Do the following before the previous command.)
sudo mv /usr/bin/java /usr/bin/java_old
This assumes that there is a link or executable named java in /usr/bin. Use the which command to be sure.
which java
To add a new pathname to the existing PATH variable, you need to type this in Terminal:
PATH=`echo $path`:/your/new/path
export PATH
If you had lost your original PATH variable, you could restore by entering this:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games
export PATH
Try:
rm -rf /usr/bin/javac
rm -rf /usr/bin/jar
ln -s /home/jdk1.6.0_13/bin/javac /usr/bin/javac
ln -s /home/jdk1.6.0_13/bin/jar /usr/bin/jar
This way, your linux can find java && javac in /usr/bin

Set Java environment variable problem on ubuntu

I got a message "No Java virtual machine could be found from your PATH
environment variable. You must install a VM prior to
running this program." Does anyone know how set up it correctly? Thanks!
If you install Java the Ubuntu way, you won't have to add it to the PATH yourself.
First, install Java from the Ubuntu repository:
sudo apt-get install sun-java6-jre
There are several other packages: sun-java6-jdk for the JDK, sun-java6-plugin for the browser plug-in etc.
Use Ubuntu's alternatives mechanism to select Sun Java 6 as the default version of Java that you want to use:
sudo update-alternatives --config java
This will present you with a menu where you can choose which version of Java you want to use by default (you can have multiple Java versions installed at the same time on your system).
See: https://help.ubuntu.com/community/Java
As the error message says, this looks like you have not set your PATH or JAVA_HOME environment variable correctly.
can you execute java from the command line? Try:
$ java -version
or
$ dpkg -L sun-java6-jre
Provided your are using debian or some derivative of it, if the "dpkg ..." command gives you any useful output, you should set the JAVA_HOME to the location of the installation directory, for instance
export JAVA_HOME=/usr/lib/jvm/java-6-sun-1.6.0.10
export PATH=$PATH:$JAVA_HOME
and you should be able to get java running.
First make sure you have the path to your java binaries.
locate javac
This will return a list of all locations matching "java". Look for something like "/usr/lib/jvm/java-6-sun-1.6.0.11".
Open /etc/environment with a text editor and add the following. Make sure you set JAVA_HOME to the actual path of the java installation directory you just found:
export JAVA_HOME="/usr/lib/jvm/java-6-sun-1.6.0.11"
export PATH="$PATH:$JAVA_HOME/bin"
I think that you need to install this package
sudo apt-get install sun-java5-bin
also check this
> #!/bin/bash
> # Init Script for j2re
> #This goes in /etc/profile.d
>
> JAVA_HOME=/usr/java/j2reVERSion
> PATH=$JAVA_HOME/bin:$PATH
>
> export JAVA_HOME PATH

Categories