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
Related
I have installed Ubuntu 20.4 LTS on WSL. My windows 10 already have the JDK installed. Do I need to install JDK on ubuntu on WSL or can I use the Windows 10 JDK in the Ubuntu? How you do Java programming on WSL? Which is the proper way?
I was just wondering if I need to install all the development tools and binaries again on Linux won't it take a lot of space & hog a lot of CPU/Ram resources?
Run the following commands as a user with sudo privileges or root to update the packages index and install the OpenJDK 11 JDK package:
$ sudo apt update
$ sudo apt install openjdk-11-jdk
Once the installation is complete, you can verify it by checking the Java version:
$ java -version
The output should look something like this:
openjdk version "11.0.7" 2020-04-14
OpenJDK Runtime Environment (build 11.0.7+10-post-Ubuntu-3ubuntu1)
OpenJDK 64-Bit Server VM (build 11.0.7+10-post-Ubuntu-3ubuntu1, mixed mode, sharing)
Set JAVA_HOME Environment Variable:
OpenJDK 11 is located at /usr/lib/jvm/java-11-openjdk-amd64/bin/java
Once you found the path of your preferred Java installation, open the /etc/environment file:
$ sudo nano /etc/environment
Assuming you want to set JAVA_HOME to point to OpenJDK 11, add the following line, at the end of the file:
JAVA_HOME="/usr/lib/jvm/java-11-openjdk-amd64"
For changes to take effect on your current shell you can either log out and log in or run the following source command:
$ source /etc/environment
Verify that the JAVA_HOME environment variable was correctly set:
$ echo $JAVA_HOME
You should see the path to the Java installation:
/usr/lib/jvm/java-11-openjdk-amd64
for reference you can follow this link below
How to Install Java on Ubuntu 20.04
We can use that Windows JDK inside the wsl2. we should add this to /etc/environment
JAVA_HOME=/mnt/c/Program Files/Java/jdk-11.0.8/bin/
by adding this bin folder we may run regular commands but append with .exe format eg: javac.exe hello.java java.exe hello.java
if you don't like that way then add alias like below:
alias java='java.exe'
alias javac='javac.exe'
I think we can use any of the windows programs like this :)
There is not a "proper" (as in supported or recommended by JDK providers) way to install or use Java on WSL. I could not find any official recommendations.
However, it is possible to either install and use Oracle JDK for Windows installation from WSL, or install OpenJDK Java into your WSL world from the Ubuntu package manager.
I was just wondering if I need to install all the development tools and binaries again on Linux won't it take a lot of space & hog a lot of CPU/Ram resources ?
See above. But note that you are only going to "hog CPU/RAM" if you are running both kinds of JVM at the same time.
References:
Installing Oracle JDK on Windows subsystem for Linux
Java JDK 11 install script for Windows Subsystem for Linux (WSL)
Windows Subsystem for Linux Java Setup ... using the Ubuntu package system.
(There are many more articles on this topic if the above don't address your concerns.)
I installed Java via IntelliJ IDEA on Windows 11 and wanted to reuse the installation on WSL.
Create matching functions in ~/.bashrc to start the executables directly and export them so they can be used from subshells:
java() {
/mnt/c/Program\ Files/Eclipse\ Adoptium/jdk-<version>/bin/java.exe "$#"
}
export -f java
javac() {
/mnt/c/Program\ Files/Eclipse\ Adoptium/jdk-<version>/bin/javac.exe "$#"
}
export -f javac
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
EDIT
I am trying to install Hadoop 2.6.0 on my Ubuntu 14 machine. I am coming across an error though.
When I am trying to set the HOME variable for Java it does not seem to be doing as expected.
I am on my machine as hduser setup specifically for running and using Hadoop. This user is a sudoer.
Some information:
java -version' gives the following
java version "1.7.0_79"
OpenJDK Runtime Environment (IcedTea 2.5.5) (7u79-2.5.5-0ubuntu0.14.04.2)
OpenJDK 64-Bit Server VM (build 24.79-b02, mixed mode)
This is the only version installed on my machine, which can be seen by running the following command:
update-alternatives --display java
Which gives the following message:
java - auto mode
link currently points to /usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java
/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java - priority 1071
slave java.1.gz: /usr/lib/jvm/java-7-openjdk-amd64/jre/man/man1/java.1.gz
Current 'best' version is '/usr/lib/jvm/java-7-openjdk-amd64/jre/bin/java'.
I then go to the following path:
cd /usr/lib/jvm
and the I list out the contents ls
default-java java-1.7.0-openjdk-amd64 java-7-openjdk-amd64
I then type cd java* and pwd which brings up the following path:
/usr/lib/jvm/java-1.7.0-openjdk-amd64
Ok, so with that information, I then copy that directory into the .bashrc file as follows:
# The java implementation to use.
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
The hadoop-env.sh file I fill out as follows:
#Hadoop variables
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
I then at the terminal type source ~/.bashrc and then restart the terminal in order for it to set to the new Java path. When typing Hadoop -version I get the following output:
/usr/bin/hadoop: line 350: /usr/lib/jvm/java-6-sun/bin/java: No such file or directory
/usr/bin/hadoop: line 434: /usr/lib/jvm/java-6-sun/bin/java: No such file or directory
I do not know where to go from here.
Thank you,
Add JAVA_HOME to point to your openjdk in hadoop-env.sh. Add this line in hadoop-env.sh:
export JAVA_HOME=/usr/lib/jvm/java-1.7.0-openjdk-amd64
NOTE: Change JAVA_HOME path in .bashrc too
UPDATE I:
Run these commands in terminal. (This will set java & javac in /bin to use your jdk)
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/java 1
sudo update-alternatives --config java
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/java-1.7.0-openjdk-amd64/bin/javac" 1
sudo update-alternatives --config javac
NOTE: If you dont have java and javac in the specified path, it will be inside /jre folder. Change it respectively.
It seems that you have installed java (I mean JRE/JDK here) 1.6, 1.7 and 1.8 at the same time. Which is comlpetelly ok since java installations are usually managed via alternatives subsystem.
The problem is that (contrary to your expectations) setting JAVA_HOME doesn't select which java is used. This is done via mentioned alternatives subsystem instead. The JAVA_HOME variable itself is only addtional configuration and doesn't have power to override what is being executed when one asks to start java process.
Moreover running cd java* isn't really a good idea unless you would like to go into first directory which starts with given string. Try to run ls java* to see my point. And again, it's ok to have multiple different versions of java here thanks to alternatives subsystem.
Another problem is that you are mixing different flavours of java which you probably don't have installed (java-8-oracle vs java-6-sun vs java-1.6.0-openjdk.
To check which java is installed, run:
alternatives --display java
And then based on the results, swich to one version of java and set JAVA_HOME accordingly.
This is probably one of the most confusing things I've had since I haven't used Unix too much before.
I have Ubuntu and I need to install my IDE (Eclipse) to support Java and C++.
I got Eclipse through the software center, then through the terminal's apt-get I installed openjdk for java, it appeared as a "Java project" in eclipse but it wouldn't compile, for example if I write System.out.println("something"); it does not even compile the System.out.println as it does not recognize it.
So can someone please once and for all refer me to a tutorial on how to install all these (and configure it) correctly? I have only found tips here and on google, nothing that -really- explains, and most the tutorials on how to install eclipse with java wants you to get sun-java-6-jdk which is not available anymore in the apt-cache
Looks like you have not installed the java properly :
Step 1 : Download java binaries from oracle.com/
Step 2 : Extract the compressed folder in your home directory /home
you can either right click on the tar ball and choose "Extract" option or you can use
[user#user-pc ~]$ tar xzvf <filename>.tar.gz
example : [user#user-pc ~]$ tar xzvf jdk-7u3-linux-x64.tar.gz
Step 3 :
Once its extracted, switch to root user
[user#user-pc ~]$ su
and execute the following commands:
[root#user-pc ~]# update-alternatives --install /usr/bin/java java /home/<extracted_folder_name>/bin/java 1
[root#user-pc ~]# update-alternatives --install /usr/bin/javac javac /home/<extracted_folder_name>/bin/javac 1
[root#user-pc ~]# update-alternatives --set java /home/<extracted_folder_name>/bin/java
[root#user-pc ~]# update-alternatives --set javac /home/<extracted_folder_name>/bin/javac
I have tried this on Linux Mint, though I make and educated guess that it should work fine for almost all Linux Debian Distros.
Restart your eclipse and it should work fine.
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.