JAVA not in path although JAVA_HOME set - java

I have set all the requirement variables in the /etc/profile but when launching elasticsearch, it is still not find Java. How i can set the environment variable. That's my /etc/profile
PATH=$PATH:$HOME/bin
APPLICATIONS=$HOME/Applications
JAVA_HOME=$APPLICATIONS/jdk1.7.0_79
PATH=$JAVA_HOME/bin:$PATH
export APPLICATIONS
export JAVA_HOME
export PATH
Output of commands
[root#87500e63467f Applications]# echo $PATH
/root/Applications/jdk1.7.0_79/bin:/root/Applications/jdk1.7.0_79/bin:/root/Applications/jdk1.7.0_79/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/root/bin:/root/bin
[root#87500e63467f Applications]# echo $JAVA_HOME
/root/Applications/jdk1.7.0_79
[root#87500e63467f Applications]# java -version
java version "1.7.0_79"
Java(TM) SE Runtime Environment (build 1.7.0_79-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.79-b02, mixed mode)
error: "Read-only file system" setting key "vm.max_map_count"
Starting elasticsearch: which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)
Could not find any executable java binary. Please install java in your PATH or set JAVA_HOME
[FAILED]
in the error, it says that ""Starting elasticsearch: which: no java in (/sbin:/usr/sbin:/bin:/usr/bin)"", it means really java isn't in that path, but how come when I echo $PATH, it shows that the java is in the path ?

After reading the docs from ElasticSearch, I found that if you're running on Ubuntu or Debian, the package only ships with the OpenJDK because of licensing issues. To fix this Java path problem, I installed the following after installing ElasticSearch (as directed by the docs):
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
java -version
Then upon running sudo service elasticsearch start everything worked and I had no more Java path issues.

run the command
java -XshowSettings
search the entry java.home = /usr/java/jdk1.8.0_91/jre
export the java_home in your bash profile
export JAVA_HOME=/usr/java/jdk1.8.0_91/jre
or in /etc/profile to expand to all users

Specifically for OpenBSD6.0, add
export JAVA_HOME=/usr/local/jdk-1.8.0/
to your .profile.
This specific version of the jdk, and possibly the basic path itself is subject to change in subsequent and previous versions of OpenBSD, you have been warned.

To get it going - though not nice - you could setup a symbolic link to your java in /usr/bin (which is listed by elasticsearch to be seen):
ln -s /root/Applications/jdk1.7.0_79/bin/java /usr/bin/java

Make sure the path you have provided for JAVA_HOME is correct.
And why not keep it simple:
export PATH=$PATH:/path/to/jdk
try to set Java home to /jdk1.7.0_79/bin and see if that helps.

Simply add the below path in bashrc and profile file under /etc/ directory.
export JAVA_HOME=/path/to/java/jdk
export PATH=$JAVA_HOME/bin:$PATH

I noticed one file in the output called /etc/sysconfig/elasticsearch
this might do the trick, so I defined JAVA_HOME in this file like, and it works.
more u can get from here

Encountered the same issue while installing Elasticsearch 5 on a debian machine. That's how I installed Java 9:
su -
echo "deb http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee /etc/apt/sources.list.d/webupd8team-java.list
echo "deb-src http://ppa.launchpad.net/webupd8team/java/ubuntu xenial main" | tee -a /etc/apt/sources.list.d/webupd8team-java.list
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys EEA14886
apt-get update
apt-get install oracle-java9-installer

I don't know if this is your particular situation, but working with ElasticSearch/Kibana/Logstash (ELK stack) the docs didn't work for me on Ubuntu 16.04. Putting content from this post together with several others, my solution was:
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
# checking my work given 9 won't work with OSSEC you can use
# java -version
sudo usermod -a -G ossec logstash
sudo apt-get install logstash
sudo systemctl daemon-reload
sudo systemctl enable logstash.service
sudo systemctl start logstash.service
The end result for me on ubuntu 16.04 was
sudo java -version
java version "1.8.0_161"
Java(TM) SE Runtime Environment (build 1.8.0_161-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.161-b12, mixed mode)
If you are working with wazuh, it is important to add the PPAs for their specific versions. I hope this helps.

you need set JAVA_HOME in the /etc/default/elasticsearch,like
cat /etc/default/elasticsearch
JAVA_HOME=/var/local/jdk1.8.0_151
the next start
/etc/init.d/elasticsearch start
ES running.
my OS ubuntu18.04.

If you are using "not installed" Java, check if your "elasticsearch" user has access to the defined by you JAVA_HOME directory and all parent directories. That was my problem..

Related

Kotlin could not find the required JDK tools with JAVA_HOME correctly set

I have the following error building my android project on Ubuntu from the command line using the gradle wrapper. Running from Android Studio is fine. After some reading of other posts I'm still not sure how to fix it, since my JAVA_HOME enviroment variable is correct. I'm not setting it from any user config files but it seems to be set from somewhere on my system. I've also tried uninstall/reinstall.
Execution failed for task
> Kotlin could not find the required JDK tools in the Java installation '/usr/lib/jvm/java-8-openjdk-amd64/jre' used by Gradle. Make sure Gradle is running on a JDK, not JRE.
So where is JAVA_HOME set to and where is it installed?
user#user$ java -version
openjdk version "1.8.0_222"
OpenJDK Runtime Environment (build 1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10)
OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)
user#user$ echo $JAVA_HOME
/usr/lib/jvm/java-1.8.0-openjdk-amd64
user#user
sudo update-java-alternatives --list
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
At this point I'm lost and confused.
user#user$ readlink -f $(which java)
/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
user#user$ which java
/usr/bin/java
user#user$ whereis java
java: /usr/bin/java /usr/share/java /usr/share/man/man1/java.1.gz
JAVA_HOME isn't set in any of my user config files, the following returns nothing
grep JAVA_HOME /etc/environment /etc/bash.bashrc /etc/profile.d/* /etc/profile
The only environment entries are
user#user$ grep -r JAVA_HOME /etc
/etc/ca-certificates/update.d/jks-keystore: export JAVA_HOME=/usr/lib/jvm/$jvm
/etc/ca-certificates/update.d/jks-keystore: PATH=$JAVA_HOME/bin:$PATH

How to install JDK 11 under Ubuntu?

So Java 11 is out. Does anybody know how to install it (OpenJDK from Oracle) from the command line?
I would like to see something like it was before for Oracle Java 10:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
P. S. In the similar question proposed instruction:
sudo apt-get install openjdk-11-jdk
doesn't work.
Now it is possible to install openjdk-11 this way:
sudo apt-get install openjdk-11-jdk
(Previously it installed openjdk-10, but not anymore)
To install Openjdk 11 in Ubuntu, the following commands worked well.
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt-get update
sudo apt install openjdk-11-jdk
sudo apt-get install openjdk-11-jdk
after this, try
java -version
to make sure java version is 1.11.x, if found old one or different, check below command to see the available jdks,
update-java-alternatives --list
you should see something like below,
java-1.11.0-openjdk-amd64 1111 /usr/lib/jvm/java-1.11.0-openjdk-amd64
java-1.8.0-openjdk-amd64 1081 /usr/lib/jvm/java-1.8.0-openjdk-amd64
you can see java 1.11 available from above list, use below command to set java 11 to default,
sudo update-alternatives --config java
for above command, you will get something like below and also, will ask for an option to set,
There are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
*2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/jdk1.8.0_211/bin/java 0 manual mode
Press <enter> to keep the current choice[*], or type selection number:
you can select desired selection number, my case it's 0
for javac,
sudo update-alternatives --config javac
will result something like below,
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/javac 1111 manual mode
*2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
3 /usr/lib/jvm/jdk1.8.0_211/bin/javac 0 manual mode
Press <enter> to keep the current choice[*], or type selection number:
in my case, it's 0 again
after above steps, try
java -version
it will display something like below,
openjdk version "11.0.4" 2019-07-16
OpenJDK Runtime Environment (build
11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed > mode, sharing)
For anyone running a JDK on Ubuntu and want to upgrade to JDK11, I'd recommend installing via sdkman. SDKMAN is a tool for switching JVMs, removing and upgrading.
SDKMAN is a tool for managing parallel versions of multiple Software Development Kits on most Unix based systems. It provides a convenient Command Line Interface (CLI) and API for installing, switching, removing and listing Candidates.
Install SDKMAN
$ curl -s "https://get.sdkman.io" | bash
$ source "$HOME/.sdkman/bin/sdkman-init.sh"
$ sdk version
Install Java (11.0.3-zulu)
$ sdk install java
In Ubuntu, you can simply install Open JDK by following commands.
sudo apt-get update
sudo apt-get install default-jdk
You can check the java version by following the command.
java -version
If you want to install Oracle JDK 8 follow the below commands.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
If you want to switch java versions you can try below methods.
vi ~/.bashrc and add the following line export JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221 (path/jdk folder)
or
sudo vi /etc/profile and add the following lines
#JAVA_HOME=/usr/lib/jvm/jdk1.8.0_221
JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
export PATH=$JAVA_HOME/bin:$PATH
export JAVA_HOME
export JRE_HOME
export PATH
You can comment on the other version. This needs to sign out and sign back in to use. If you want to try it on the go you can type the below command in the same terminal. It'll only update the java version for a particular terminal.
source /etc/profile
You can always check the java version by java -version command.
First check the default-jdk package, good chance it already provide you an OpenJDK >= 11.
ref: https://packages.ubuntu.com/search?keywords=default-jdk&searchon=names&suite=all&section=all
Ubuntu 18.04 LTS +
So starting from Ubuntu 18.04 LTS it should be ok.
sudo apt update -qq
sudo apt install -yq default-jdk
note: don't forget to set JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/default-java
mvn -version
Ubuntu 16.04 LTS
For Ubuntu 16.04 LTS, only openjdk-8-jdk is provided in the official repos so you need to find it in a ppa:
sudo add-apt-repository -y ppa:openjdk-r/ppa
sudo apt update -qq
sudo apt install -yq openjdk-11-jdk
note: don't forget to set JAVA_HOME
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-amd64
mvn -version
I had problems installing open jdk on ubuntu 17.04
I managed to install it using this steps:
wget https://download.java.net/java/ga/jdk11/openjdk-11_linux-x64_bin.tar.gz -O /tmp/openjdk-11+28_linux-x64_bin.tar.gz
tar xfvz /tmp/openjdk-11+28_linux-x64_bin.tar.gz --directory /usr/lib/jvm/
rm /etc/alternatives/java
ln -s /usr/lib/jvm/jdk-11/bin/java /etc/alternatives/java
java -version
You should see this:
openjdk version "11" 2018-09-25
OpenJDK Runtime Environment 18.9 (build 11+28)
OpenJDK 64-Bit Server VM 18.9 (build 11+28, mixed mode)
I came here looking for the answer and since no one put the command for the oracle Java 11 but only openjava 11 I figured out how to do it on Ubuntu, the syntax is as following:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt update
sudo apt install oracle-java11-installer
I created a Bash script that basically automates the manual installation described in the linked similar question. It requires the tar.gz file as well as its SHA256 sum value. You can find out more info and download the script from my GitHub project page. It is provided under MIT license.
Just updated older Ubuntu versions to openJDK 11Actually I need it for Jenkins only and it seems to work fine.
Ubuntu 12.04 (Precise):
Download from openjdk-lts (11.0.4+11-1~12.04) precise
Files:
openjdk-11-jre-headless_11.0.4+11-1~12.04_amd64.deb
openjdk-11-jre_11.0.4+11-1~12.04_amd64.deb
Ubuntu 14.04 (Trusty):
Download from openjdk-lts (11.0.5+10-2ubuntu1~14.04) trusty
Files:
openjdk-11-jre-headless_11.0.5+10-2ubuntu1_14.04_amd64.deb
openjdk-11-jre_11.0.5+10-2ubuntu1_14.04_amd64.deb
Installation
After download I installed the files with Ubuntu Software Center ("headless" first!)
Then I selected the new version with sudo update-alternatives --config java
I didn't have to change any environment variables (like JAVA_HOME) - maybe Jenkins doesn't care about them...
if you want to use official oracle jdk.
then download jdk 11 or latest from oracle website: https://www.oracle.com/java/technologies/javase-downloads.html
then use this command to install :
sudo dpkg -i the file you downloaded
then add to your PATH using /etc/profile file.
in my case it's just worked 100% using ubuntu 20.04
note: official oracle jdk free only for developments.
Following are command to install openjdk 11
sudo apt-get install openjdk-11-jdk
We can check the version by running following command
java -version
For setting the JAVA_HOME in path we can following command
sudo gedit .bashrc.
Set the following value in bashrc file
export JAVA_HOME=$(dirname $(dirname $(readlink -f $(which java))))
export PATH=$PATH:$JAVA_HOME/bin
To execute the content of bashrc file run following command
source ~/.bashrc.

How can I found where I defined JAVA_HOME

Here is my system info
wangbo#ubuntu:~$ uname -a
Linux ubuntu 4.4.0-72-generic #93-Ubuntu SMP Fri Mar 31 14:07:41 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
When I check java version
java version "1.7.0_80"
Java(TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot(TM) 64-Bit Server VM (build 24.80-b11, mixed mode)
but when I echo $JAVA_HOME
/usr/lib/jvm/java-9-oracle
It is unmatched , It seems that I defined $JAVA_HOME somewhere , but I can`t found it , Anyone can help me how can I found my $JAVA_HOME defined
Other useful info :
I had install and uninstall jdk9 as first jdk before
It is not in ~/.bashrc
It is not in /etc/bash.bashrc
It is not in ~/.profile
UPDATE
wangbo#ubuntu:~$ more /etc/environment
PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games"
1) JAVA_HOME is most probably defined in /etc/profile.d/jdk.sh and /etc/profile.d/jdk.csh These files are unfortunately not managed by the update-alternatives system.
2) Which executable you run should depend on the update-alternatives system, but if you have forced a particular version in your PATH it won’t.
Many java applications are actually invoked by scripts which choose their preferred jvm setting up a consistent environment, and shouldn’t be affected by your problem. It is best to have a consistent environment for free java invocations from the shell, however, and in most installations I know this is achieved manually...
Some java distributions don’t need JAVA_HOME at all. In other cases you need it. My advice is to define JAVA_HOME only when it turns out you need it. If it is the case, define it in a shell script and use that script to invoke the commands that you need that particular value for.
EDIT: /etc/profile.d/jdk.sh seems to be installed by oracle-java8-set-default.
# Uninstall the package (choose one)
sudo apt purge oracle-java8-set-default
sudo apt remove --purge oracle-java8-set-default
# Configure the desired Java binary
sudo update-alternatives --config java
sudo update-alternatives --config javac
you should better check /etc/environment
Your Java command is picked up from the PATH variable. Most probably, you have added Java7 to your path. Check your .profile, .bash_profile, /etc/profile and /etc/environment files.
JAVA_HOME is used by some scripts/tools (ant comes to mind) - to select a java command.
Try
sudo find / -path /sys -prune -o -path /proc -prune -o -type f -exec grep -l JAVA_HOME {} + 2>/dev/null
Sorry the first version of my answer will take forever. But this will take only some time, but it will find the file.
On my ubuntu 14.04 system, kernel 4.4.0-71-generic I used the following:
$ echo $JAVA_HOME
/usr/lib/jvm/java-8-oracle

How to remove old version of Java and install new version

I have a Linux box on which Java 1.7 is installed:
#java -version
java version "1.7.0_09-icedtea"
OpenJDK Runtime Environment (rhel-2.3.4.1.el6_3-x86_64)
OpenJDK 64-Bit Server VM (build 23.2-b09, mixed mode)
But for some new tool I need to install the jdk-8u45-linux-x64.tar.gz
So how can I remove old one and install the new one?
To remove OpenJDK (the one you've already installed)
sudo apt-get purge openjdk-\*
Make a new directory for your new JDK
sudo mkdir -p /usr/local/java
Copy the file to the directory (you should be in that file path)
sudo cp -r jdk-8u45-linux-x64.tar.gz /usr/local/java/
Extract the file
sudo tar xvzf jdk-8u45-linux-x64.tar.gz
You should add this to your PATH now. To do that:
a. Open /etc/profile : sudo gedit /etc/profile
b. Scroll down (the end) and add the path where your jdk was installed
JAVA_HOME=/usr/local/java/jdk1.8.0_45
PATH=$PATH:$HOME/bin:$JAVA_HOME/bin
export JAVA_HOME
export PATH
Save and exit
Inform your Linux system where your Oracle Java JDK/JRE is located.
a. Notify the system that Oracle Java JRE is available for use
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.8.0_45/bin/java" 1
b. Notify the system that Oracle Java JDK is available for use
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.8.0_45/bin/javac" 1
c. Notify the system that Oracle Java Web start is available for use
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.8.0_20/bin/javaws" 1
Inform your Linux system that Oracle Java JDK/JRE must be the default Java.
a. Set the java runtime environment for the system
sudo update-alternatives --set java /usr/local/java/jdk1.8.0_45/bin/java
b. Set the javac compiler for the system
sudo update-alternatives --set javac /usr/local/java/jdk1.8.0_45/bin/javac
c. Set Java Web start for the system
sudo update-alternatives --set javaws /usr/local/java/jdk1.8.0_20/bin/javaws
Reload your system wide PATH
source /etc/profile
Check the new version and you're done!
java -version
Just unpack the new Java version, for example into /opt. Then do
export JAVA_HOME=/opt/jdk1.8.0_45
export PATH=$JAVA_HOME/bin:$PATH
Put these exports into the startup files for your shell and you should be set. It is not necessary to uninstall the Java 7 installation.
On Centos/Redhat
First do : rpm -qa|grep jdk
And then : rpm -e <the version which you dont want>
I had java 7 installed on my ubuntu machine and wanted java 8. For that i followed the following steps
purge the older with sudo apt-get purge openjdk-\*
Add repository sudo add-apt-repository ppa:openjdk-r/ppa
Update the packages sudo apt-get update
Install java 8 with sudo apt-get install openjdk-8-jdk
To check list of java versions installed dosudo update-java-alternatives --list
Select default java for java sudo update-alternatives --config java
Select default java for javac sudo update-alternatives --config javac
check with java -version and javac -version to check if update version is installed
I referred following link Install OpenJDK8 on Unbuntu Trusty
Hope this helps!
I went to this article, the final option did it for me:
A final option for you to consider is yum remove libpcap, see how many packages it wants to remove (yum won't actually remove anything until you hit the Y button and press enter), since you may be able to remove these packages and use yum, if it turns out you couldn't after all, you can roll back with yum history undo command (I don't remember in what version of yum this was implemented in yum, so check first if this sub command is available to you). Also, make sure that you got your repositories pointing to the repos which has these files available.
After that I could remove my old jdk with:
sudo rpm -e java-1.8.0-openjdk-1.8.0.352.b08-2.el7_9

How to install the JDK on Ubuntu Linux

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

Categories