Related
I have installed OpenJDK 7 and it runs well on my Ubuntu 14.04 machine. I want to add Java sources to my Eclipse. When I go to /usr/lib/jvm/java-7-openjdk-amd64 there is a symlink called src.zip but it's broken. How do I fix this? Do I have to manually download sources and add them?
You should do:
sudo apt-get install openjdk-7-source
then the source code will be downloaded under: "/usr/lib/jvm/openjdk-7".
The symlink:
src.zip -> ../openjdk-7/src.zip
should work now.
The answer from Alex is correct, as in how it should be. However, for OpenJDK 11 on Ubuntu 18.10 it appears that src.zip has been moved to lib/src.zip so the symlink cannot be resolved.
In addition to the
sudo apt install openjdk-11-source
command, run
echo "(cd /usr/lib/jvm/openjdk-11/; ln -s lib/src.zip)" | sudo bash
to create an additional symbolic link.
I downloaded sources from http://jdk7src.sourceforge.net/ and added them to eclilpse. It works fine now.
installing openjdk8 again worked for me in ubuntu 16.04
step1: sudo apt install openjdk-8-source
step2 : attach the source.zip under(Window->preferences-java->Installed JREs->edit java-8-open-Jdk->expand rt.jar->click on Source attachment and attach the src.zip under /usr/lib/jvm/java-8-openjdk-amd64).
Note: This question was asked before Oracle made the OpenJDK the free version of the Oracle JDK, and the historic answers reflect that. As of 2022 you should not use Java 7 unless you must for projects which cannot run on OpenJDK 8.
To install java I have always used the classic way from the terminal.
I would like to install java manually.
I placed the folder of the JDK on the desk and I set environment variables (PATH, CLASSPATH and JAVA_HOME).
From the terminal, if I type java -version I get printed
foralobo#ubuntu-vincy:~$ java -version
java version "1.7.0_21"
Java(TM) SE Runtime Environment (build 1.7.0_21-b11)
Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode)
But when I try to install eclipse or netbeans, the system warns by saying that there is no java installed on the machine.
What is missing to compleatare manual installation?
(Ubuntu 13.04)
This answer used to describe how to install Oracle Java 7. This no longer works since Oracle end-of-lifed Java 7 and put the binary downloads for versions with security patches behind a paywall. Also, OpenJDK has grown up and is a more viable alternative nowadays.
In Ubuntu 16.04 and higher, Java 7 is no longer available. Usually you're best off installing Java 8 (or 9) instead.
sudo apt-get install openjdk-8-jre
or, f you also want the compiler, get the jdk:
sudo apt-get install openjdk-8-jdk
In Trusty, the easiest way to install Java 7 currently is to install OpenJDK package:
sudo apt-get install openjdk-7-jre
or, for the jdk:
sudo apt-get install openjdk-7-jdk
If you are specifically looking for Java 7 on a version of Ubuntu that no longer supports it, see https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher .
sudo apt-get update
sudo apt-get install openjdk-7-jdk
and if you already have other JDK versions installed
sudo update-alternatives --config java
then select the Java 7 version.
In addition to flup's answer you might also want to run the following to set JAVA_HOME and PATH:
sudo apt-get install oracle-java7-set-default
More information at:
http://www.ubuntuupdates.org/package/webupd8_java/precise/main/base/oracle-java7-set-default
Note: According to comments this text was copied from a GIST without attribution.
Download java jdk<version>-linux-x64.tar.gz file from https://www.oracle.com/technetwork/java/javase/downloads/index.html.
Extract this file where you want. like: /home/java(Folder name created by user in home directory).
Now open terminal.
Set path JAVA_HOME=path of your jdk folder(open jdk folder then right click on any folder, go to properties then copy the path using select all)
and paste here.
Like: JAVA_HOME=/home/xxxx/java/JDK1.8.0_201
Let Ubuntu know where our JDK/JRE is located.
sudo update-alternatives --install /usr/bin/java java /home/xxxx/java/jdk1.8.0_201/bin/java 20000
sudo update-alternatives --install /usr/bin/javac javac /home/xxxx/java/jdk1.8.0_201/bin/javac 20000
sudo update-alternatives --install /usr/bin/javaws javaws /home/xxxx/java/jdk1.8.0_201/bin/javaws 20000
Tell Ubuntu that our installation i.e., jdk1.8.0_05 must be the default Java.
sudo update-alternatives --set java /home/xxxx/sipTest/jdk1.8.0_201/bin/java
sudo update-alternatives --set javac /home/xxxx/java/sipTest/jdk1.8.0_201/bin/javac
sudo update-alternatives --set javaws /home/xxxxx/sipTest/jdk1.8.0_201/bin/javaws
Now try:
$ sudo update-alternatives --config java
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-6-oracle1/bin/java 1047 auto mode
1 /usr/bin/gij-4.6 1046 manual mode
2 /usr/lib/jvm/java-6-oracle1/bin/java 1047 manual mode
3 /usr/lib/jvm/jdk1.7.0_75/bin/java 1 manual mode
Press enter to keep the current choice [*], or type selection number: 3
update-alternatives: using /usr/lib/jvm/jdk1.7.0_75/bin/java to provide /usr/bin/java (java) in manual mode
Repeat the above for:
sudo update-alternatives --config javac
sudo update-alternatives --config javaws
I think you should consider Java installation procedure carefully. Following is the detailed process which covers almost all possible failures.
Installing Java with apt-get is easy. First, update the package index:
sudo apt-get update
Then, check if Java is not already installed:
java -version
If it returns "The program java can be found in the following packages", Java hasn't been installed yet, so execute the following command:
sudo apt-get install default-jre
You are fine till now as I assume.
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), which is usually needed to compile Java applications (for example Apache Ant, Apache Maven, Eclipse and IntelliJ IDEA execute the following command:
sudo apt-get install default-jdk
That is everything that is needed to install Java.
Installing OpenJDK 7:
To install OpenJDK 7, execute the following command:
sudo apt-get install openjdk-7-jre
This will install the Java Runtime Environment (JRE). If you instead need the Java Development Kit (JDK), execute the following command:
sudo apt-get install openjdk-7-jdk
Installing Oracle JDK:
The Oracle JDK is the official JDK; however, it is no longer provided by Oracle as a default installation for Ubuntu.
You can still install it using apt-get. To install any version, first execute the following commands:
sudo apt-get install python-software-properties
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
Then, depending on the version you want to install, execute one of the following commands:
Oracle JDK 7:
sudo apt-get install oracle-java7-installer
Oracle JDK 8:
sudo apt-get install oracle-java8-installer
PPA method no longer works.
While Oracle Java 6 and 7 are not supported for quite a while, they were still available for download on Oracle's website until recently.
However, the binaries were removed about 10 days ago (?), so the Oracle Java (JDK) 6 and 7 installers available in the WebUpd8 Oracle Java PPA no longer work.
Oracle Java 6 and 7 are now only available for those with an Oracle Support account (which is not free), so I can't support this for the PPA packages.
Source : http://www.webupd8.org/2017/06/why-oracle-java-7-and-6-installers-no.html
Dated : June 2017
Oracle's download page says
Updates for Java SE 7 released after April 2015, and updates for Java SE 6 released after April 2013 are only available to Oracle Customers through My Oracle Support (requires support login).
Java SE Advanced offers users commercial features, access to critical bug fixes, security fixes, and general maintenance".
I had to download it from Oracle archives -
http://www.oracle.com/technetwork/java/javase/downloads/java-archive-downloads-javase7-521261.html
You need an account for this though.
Oracle Java 1.7.0 from .deb packages
wget https://raw.github.com/flexiondotorg/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7
sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source
sudo apt-get dist-upgrade
Workaround for 1.7.0_51
There is an Issue 123 currently in OAB and a pull request
Here is the patched vesion:
wget https://raw.github.com/ladios/oab-java6/master/oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh -7
sudo apt-get update
sudo sudo apt-get install oracle-java7-jdk oracle-java7-fonts oracle-java7-source
sudo apt-get dist-upgrade
flup's answer is the best but it did not work for me completely. I had to do the following as well to get it working:
export JAVA_HOME=/usr/lib/jvm/java-7-oracle/jre/
chmod 777 on the folder
./gradlew build - Building Hibernate
Oracle as well as modern versions of Ubuntu have moved to newer versions of Java. The default for Ubuntu 20.04 is OpenJDK 11 which is good enough for most purposes.
If you really need it for running legacy programs, OpenJDK 8 is also available for Ubuntu 20.04 from the official repositories.
If you really need exactly Java 7, the best bet as of 2020 is to download a Zulu distribution. The easiest to install if you have root privileges is the .DEB version, otherwise download the .ZIP one.
https://www.azul.com/downloads/?version=java-7-lts&os=ubuntu&architecture=x86-64-bit&package=jdk#download-openjdk
Open Applicaction -> Accessories -> Terminal
Type commandline as below...
sudo apt-get install openjdk-7-jdk
Type commandline as below...
apt-cache search jdk
(Note: openjdk-7-jdk is symbolically used here. You can choose the JDK version as per your requirement.)
For "JAVA_HOME" (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export JAVA_HOME=/usr/lib/jvm/java-7-openjdk
(Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)
For "PATH" (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export PATH=$PATH:/usr/lib/jvm/java-7-openjdk/bin
(Note: "/usr/lib/jvm/java-7-openjdk" is symbolically used here just for demostration. You should use your path as per your installation.)
Check for "open jdk" installation, just type command in "Terminal" as shown below
javac -version
Note: This is an old question and the answers reflect the world as it was then. Modern Ubuntu distributions have OpenJDK available which can be installed with
sudo apt install default-jdk
I am trying to install the Java Development Kit (JDK) on Ubuntu Linux distribution, but I am unable to install it.
What are the steps to install it on Ubuntu?
Referring to Ask Ubuntu question How to set JAVA_HOME for OpenJDK?,
How to install Open JDK (Java developement kit) in Ubuntu (Linux)?
Open Terminal from Application Dash or press Ctrl+Alt+T
Update repository:
sudo add-apt-repository ppa:openjdk-r/ppa # only Ubuntu 17.4 and earlier
sudo apt update
Optional: To search available distributions of openjdk, use the following command:
apt search openjdk
Install the appropriate version with the following command:
sudo apt install openjdk-8-jdk
sudo apt install openjdk-8-source #this is optional, the jdk source code
For JAVA_HOME (Environment Variable) type command as shown below, in "Terminal" using your installation path...
export JAVA_HOME=/usr/lib/jvm/java-8-openjdk
(Note: /usr/lib/jvm/java-8-openjdk is symbolically used here just for demostration. You should use your path as per your installation.)
For PATH (Environment Variable) type command as shown below, in Terminal:
export PATH=$PATH:$JAVA_HOME/bin
To check your installation:
java -version
The following used to work before the Oracle Java license changes in early 2019.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
The PPA is discontinued, until the author finds a workaround for the license issues.
You can install Oracle's JDK 1.7 fairly easily too; as an example this is how to install JDK 1.7.0_13;
Download the JDK from Oracle's site. The download to the newest version is always linked from http://java.oracle.com.
As root, do;
cd /usr/local
tar xzf <the file you just downloaded>
As your normal user, add or change these two lines in your ~/.profile to point to the installation;
export JAVA_HOME=/usr/local/jdk1.7.0_13
export PATH=$PATH:$JAVA_HOME/bin
If it's an update, you may also want to remove the old java installation directory in /usr/local.
Log out and in again (or do . ~/.profile), and everything should just work.
The downside with Oracle's JDK is that it won't update with the rest of your system like OpenJDK will, so I'd mostly consider it if you're running programs that require it.
In case you have already downloaded the ZIP file follow these steps.
Run the following command to unzip your file.
tar -xvf ~/Downloads/jdk-7u3-linux-i586.tar.gz
sudo mkdir -p /usr/lib/jvm/jdk1.7.0
sudo mv jdk1.7.0_03/* /usr/lib/jvm/jdk1.7.0/
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/jvm/jdk1.7.0/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk1.7.0/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/jvm/jdk1.7.0/bin/javaws" 1
After installation is complete, set environment variables as follows.
Edit the system path in file /etc/profile:
sudo gedit /etc/profile
Add the following lines at the end.
JAVA_HOME=/usr/lib/jvm/jdk1.7.0
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
Source: http://javaandme.com/
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
If you want to install the latest JDK 1.8, use the webupd8team PPA.
Add the repository in your system:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
You can now install Oracle Java 8 using the following command:
sudo apt-get install oracle-java8-installer
This ppa repository also provides a package to set environment variables automatically. Just type:
sudo apt-get install oracle-java8-set-default
OpenJDK is OK for the most cases, but Oracle JDK can be required for some bank client applications (my case) - I can't use OpenJDK.
I'm surprised that I don't see any answer with the default method (repository without external PPAs) in Ubuntu 12.10+ for Oracle's JDK - I will try to describe it.
Install JavaPackage:
sudo apt-get install java-package
Download Oracle JDK from Oracle downloads page
Make a Debian package from the downloaded .tar.gz archive:
make-jpkg jdk-YOUR_VERSION-linux-PLATFORM.tar.gz
This command will produce a .deb package.
Install the package in your favourite way (for example, sudo dpkg -i oracle-java8-jdk_8u40_amd64.deb)
It's the officially supported way from Debian developers for installing Oracle JDK, and I suppose it's very simple.
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
Installing Java 8 on Ubuntu
First you need to add webupd8team Java PPA repository in your system and install Oracle Java 8 using following set of commands.
$ sudo add-apt-repository ppa:webupd8team/java
$ sudo apt-get update
$ sudo apt-get install oracle-java8-installer
Verify Installed Java Version
After successfully installing Oracle Java using the above steps, verify the installed version using the following command.
$ java -version
java version "1.8.0_77"
Java(TM) SE Runtime Environment (build 1.8.0_77-b03)
Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)
###Configuring the Java environment
In Webupd8 ppa repository also providing a package to set environment variables, Install this package using following command.
$ sudo apt-get install oracle-java8-set-default
Reference
Simply run:
sudo apt-get install default-jdk
Wiki from Ubuntu website:
For Ubuntu 10.04 LTS, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
sudo add-apt-repository "deb http://archive.canonical.com/ lucid partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin
sudo update-alternatives --config java
For Ubuntu 10.10, the sun-java6 packages have been dropped from the Multiverse section of the Ubuntu archive. It is recommended that you use openjdk-6 instead.
If you can not switch from the proprietary Sun JDK/JRE to OpenJDK, you can install sun-java6 packages from the Canonical Partner Repository. You can configure your system to use this repository via command-line:
sudo add-apt-repository "deb http://archive.canonical.com/ maverick partner"
sudo apt-get update
sudo apt-get install sun-java6-jre sun-java6-plugin
sudo update-alternatives --config java
Installed in ubuntu 18.04
My workaround was,
$ sudo apt update
Install OpenJDK 8:
$ sudo apt install openjdk-8-jdk
Verify the Java installation by running the following command which will print the Java version:
$ java -version
The output should look like this:
Output:
openjdk version "1.8.0_191"
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)
Using a PPA (Obsolete)
Note: WebUpd8 team's PPA has been discontinued with effective from April 16, 2019. Thus this PPA doesn't have any Java files. More information can be found on PPA's page on Launchpad. Hence the below method no longer works and exists because of historical reasons.
You can use WebUpd8 PPA (this will download the required files from Oracle and install JDK 8):
sudo apt-add-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Are PPA's safe to add to my system and what are some “red flags” to watch out for?
Also ensure your JAVA_HOME variable has been set to:
/usr/lib/jvm/java-8-oracle
Manual install
The tar.gz provided by Oracle don't have an actual installation process. You just extract those files to a location you want and add them to your path. So the process is the following:
Download a .tar.gz from Oracle (here I will be using jdk-8u20-linux-x64.tar.gz);
Extract it to somewhere;
Move the extracted folder to /usr/lib/jvm. This is not required but it is the place where Java runtime software is installed
sudo mv /path/to/jdk1.8.0_20 /usr/lib/jvm/oracle_jdk8
Create a file /etc/profile.d/oraclejdk.sh with the following content (adapt the paths to reflect the path where you stored your JDK):
export J2SDKDIR=/usr/lib/jvm/oracle_jdk8
export J2REDIR=/usr/lib/jvm/oracle_jdk8/jre
export PATH=$PATH:/usr/lib/jvm/oracle_jdk8/bin:/usr/lib/jvm/oracle_jdk8/db/bin:/usr/lib/jvm/oracle_jdk8/jre/bin
export JAVA_HOME=/usr/lib/jvm/oracle_jdk8
export DERBY_HOME=/usr/lib/jvm/oracle_jdk8/db
Done! Those paths will only be recognized after you logout or restart, so if you want to use them right away run source /etc/profile.d/oraclejdk.sh.
In Ubuntu 18.04, We can install java like a normal package without using an external repository
Just run this command
sudo apt install openjdk-8-jdk
You can use the sudo apt-get install default-jdk terminal command to install the default JDK version.
Before installing Java, type the sudo apt-get update terminal command and then type the install terminal command. You can get more information from here.
Have a look at OpenJDK. It is the standard JVM implementation on Linux.
The best is to install default Java until a specific Java version is not required.
Before this, execute java -version to check if Java is not already installed.
sudo apt-get update
sudo apt-get install default-jre
sudo apt-get install default-jdk
That is everything that is needed to install Java.
I recommend JavaPackage.
It's very simple. You just need to follow the instructions to create a .deb package from the Oracle tar.gz file.
You can install via apt-get:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java11-installer
After, do not forget to check the version:
java -version
sun-java6-jdk is a virtual package provided by oracle-java8-installer or oracle-java7-installer or oracle-java7-installer.
sudo apt-get install oracle-java8-installer
will give you sun-java6-jdk.
I have successfully installed JDK 10 on Ubuntu 18.04 LTS following this video.
I am copying the excerpt from the description of the video.
Just open the terminal and give these commands :
For Java Installation (PPA)
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
For setting up environment variables (make java10 default)
sudo apt-get install oracle-java10-set-default
The same procedure can be followed on Ubuntu 16.04, Linux Mint, Debian and other related Linux systems to install JDK 10.
You can use SDKMan,
curl -s "https://get.sdkman.io" | bash
source "~/.sdkman/bin/sdkman-init.sh"
sdk install java
If you want to install Oracle JDK, you can use this automated script that does all the work for you.
There are detailed instructions how to use it on the author's blog.
Installing Oracle's Java JDK requires you to accept the Oracle license before the installation begins. This is only required once. If for some reason you need the installation to be automated, you can run the following commands to install without user interaction, useful for an automatic script for example.
sudo add-apt-repository -y ppa:webupd8team/java
sudo apt-get update
echo debconf shared/accepted-oracle-license-v1-1 select true | sudo debconf-set-selections
echo debconf shared/accepted-oracle-license-v1-1 seen true | sudo debconf-set-selections
sudo apt-get -y install oracle-java8-installer
java -version
Try to use SDKMAN! package manager - https://sdkman.io/install
Now it's the easiest way to install many JVM-based SDKs, tools and frameworks on any Linux distribution.
Upon installation, run the following command to see all available Java distributions:
sdk list java
Select the distribution that you need and install it:
sdk install java <version>
Install the appropriate version of OpenJDK
JAVA_VERSION=8
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt-get update
sudo apt-get -qq install -y openjdk-$JAVA_VERSION-jdk
Set Environment Variables in /etc/profile.d/jdk.sh
JAVA_HOME=/usr/lib/jvm/java-$JAVA_VERSION-openjdk-amd64
echo "export JAVA_HOME=$JAVA_HOME" | sudo tee -a /etc/profile.d/jdk.sh
echo "export J2SDKDIR=$JAVA_HOME" | sudo tee -a /etc/profile.d/jdk.sh
echo "export J2REDIR=$JAVA_HOME/jre" | sudo tee -a /etc/profile.d/jdk.sh
echo "export PATH=$PATH:$JAVA_HOME/bin:$J2REDIR/bin" | sudo tee -a /etc/profile.d/jdk.sh
Check your installation
/bin/bash /etc/profile.d/jdk.sh
java -version
echo $JAVA_HOME
echo $J2REDIR
echo $PATH
Step 01: Download JDK
Download the JDK of required version from oracle official website :
[Oracle website to download JDK]: https://www.oracle.com/in/java/technologies/javase-downloads.html
e.i - jdk-11.0.12_linux-x64_bin.tar.gz
Step 02: Installation:
a) Extract the downloaded files using following command
sudo -tar -vzxf jdk-11.0.12_linux-x64_bin.tar.gz
b) Create a directory of name java inside usr/lib directory
mkdir java
c) Move the extracted jdk-11.0.12 directory inside the new created directory java
sudo mv jdk-11.0.12 /usr/lib/java
Step 03:
a) Execute following commands one by one
sudo update-alternative -install /usr/lib/java java /usr/lib/java/jdk-11.0.12/bin/java 1
sudo update-alternative -install /usr/lib/javac javac /usr/lib/java/jdk-11.0.12/bin/javac 1
Step 04: installation varification :
Verify the installation by using following commands
java --version
javac --version
You can use oraji. It can install/uninstall both JDK or JRE from oracle java (.tar.gz).
To install run sudo oraji '/path/to/the/jdk_or_jre_archive'
To uninstall run oraji -u and confirm the version number.
I had the same problem and none of the comments worked for me. Finally, I noticed that I disabled my updates. When I reactivate it, so sudo apt-get update worked correctly and the issue was solved.
(update in system settings> software and updates>updates tab
here I ticked two first option of important update and recommended updates).
Try this in case you do not want to install OpenJDK: JDK Source Installer for Ubuntu
In Ubuntu1604 I faced "No installation candidate error". Following below steps helped me install.
-sudo apt-get update
-sudo apt-get upgrade
-apt-get install software-properties-common
-sudo add-apt-repository ppa:webupd8team/java
-apt-get update
-sudo apt install oracle-java8-installer
Over Debian you can try
apt-get install default-jdk
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.
I've been using a linux machine for less than two weeks, so I am extremely new to Linux.
I'd also like to install the Java Developers Kit. How should this be done? Is there an apt-get command, or should I just click on the download button at Sun's website?
I'm sure there is more than one way to do this, and it probably doesn't matter much, but I was impressed with how smoothly apt-get install worked when installing PHP and MySQL, so if there is a right way to do this, I'd like to know.
I'm using Ubuntu version 9.04
Yes, definitely it's the suggested way to install JDK on your Linux system (if available).
On Ubuntu:
sudo apt-get install sun-java6-jdk
The Oracle JDK is no longer included in the Ubuntu repos. According to https://stackoverflow.com/a/15543636/192221 , the following ppa can be used:
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu precise main" | tee -a /etc/apt/sources.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java7-installer
If you have OpenJDK installed already, you might need to use
update-alternatives --config java
to use the Oracle Java by default.
If you for some reason need to install the sun packages you can use the make-jpkg command to create a deb file and still have the files managed by apt/dpkg.
To do this:
sudo apt-get install java-package
fakeroot make-jpkg jre-1_5_0_06-linux-i586.bin
you will then have a .dpg file that you can install using for example gdebi
gdebi-gtk jre.deb
Also note that you can have multiple JDKs installed and switch between them using update-alternatives:
update-alternatives --config java
update-alternatives --config javac
and so on for other java related binaries, have a look in /etc/alternatives to find out which are available.
In Ubuntu 9.10 Karmic Koala apt-get and the Synaptic Software Manager both install version 6.15.1 of Sun Java and the JDK, which are now out of date, and an old version of Netbeans,, so don't use "sudo apt-get install" for these.
Go to the Sun Java download page
http://www.java.com/en/download/manual.jsp
Select the non-RPM 32-bit or 64-bit self extracting file, download it and check the file size of the downloaded file. Doesn't matter where you download it.
Click on the link to installation instructions for the corresponding file.
An easier way to set executable permission is to right click on the file in the file browser (Nautilus) and click Properties, then on the Permissions tab, click the Execute checkbox.
To test, open a new terminal and type:
java -version
You should see Java version "1.6.0_18" etc.
If you don't, you probably need to add some lines, adjusted to suit your installation directories, to .bashrc and .bash_profile which are both hidden files in your home directory.
gedit .bashrc
Add the following:
export JAVA_HOME=/opt/java/64/jre1.6.0_18
export PATH=$PATH:$JAVA_HOME/bin
Then edit your .bash_profile file and insert the same lines at the end:
gedit .bash_profile
Open a new terminal window and test as above.
If all went well, in the Applications menu > System Tools, you should now have the Sun Java Control Panel.
You can repeat a similar installation procedure for the JDK and Netbeans where you mark the downloaded .bin file as executable and then execute it from a terminal window in the directory you want to install into, such as /usr/local.
After installing the JDK, add to your .bashrc and .bash_profile files a line similar to this:
export PATH=$PATH:/usr/local/jdk1.6.0_18/bin
Netbeans 6.8 seems to be able to set itself up ok without any editing and adds itself to the Applications Programming menu.
My Ubuntu box has sun-java5-jdk and sun-java6-jdk available.
I am personally a linux mint person. However, I couldn't find this in my respitory:
sudo apt-get install sun-java6-jdk
After poking around for a bit, I was able to get this to work.
sudo apt-get install openjdk-6-jdk
Cheers.
I'm not sure Ubuntu 9.04. Is it openJDK?
But in Ubuntu 9.10 It is openJDK.
So It have many problem.
You can do like this to remove and install sun java jdk
sudo apt-get remove openJDK*
sudo apt-get install sun-java6*