How to install JDK 10 under Ubuntu? - java

How do I install Java Development Kit (JDK) 10 on Ubuntu?
The installation instructions on Oracle's help center only explain how to download and extract the archive on Linux platform, without any system setup.

Update: JDK 11 Now Available
sudo apt-get install openjdk-11-jdk
For JDK 10
Option 1: Easy Installation (PPA)
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Then set as default with:
sudo apt-get install oracle-java10-set-default
And finally verify Installation with:
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Source: Linux Uprising
Option 2: Manual Installation
Download OpenJDK 10 binaries for Linux.
Untar the downloaded archive:
tar xzvf openjdk-10_linux-x64_bin.tar.gz
Move the extracted archive to where your system keeps your installed JDKs:
sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/
Add the new Java alternative:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1
Update your system's java alternatives and choose JDK 10:
$ sudo update-alternatives --config java
here are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode
* 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number:
and
$ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 auto mode
1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-10-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
Verify your installation with:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
and
$ javac --version
javac 10
Done
If you prefer Oracle's JDK, download it and follow the installation steps as shown above.

I've found SdkMan! a very useful tool because it provides a convenient way for managing your JDKs from the shell.
For example, once it is installed, you can:
Install a specific JDK version: sdk install java 10.0.2-open
Downloading: java 10.0.2-open
In progress...
################# 12,3%
Use a specific JDK version: sdk use java 10.0.2-open
Using java version 10.0.2-open in this shell.
List available JDK: sdk list java
===================================================================
Available Java Versions
===================================================================
9.0.4-open
+ 8u161-oracle
8.0.191-oracle
> + 8.0.171-oracle
7.0.191-zulu
12.ea.15-open
11.0.1-open
10.0.2-open
1.0.0-rc8-graal
===================================================================
+ - local version
* - installed
> - currently in use
=======================================================================
And much more
See https://sdkman.io/usage

There is a ppa on java 10 that installs oracle's java: https://launchpad.net/~linuxuprising/+archive/ubuntu/java
I am not sure if this will be maintained though.
It seems to be a copy of the webupd8 way on how to handle oracle java installation (ref: documentation).
How to use this ppa:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Verify installation:
$ /usr/lib/jvm/java-10-oracle/bin/java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Setting up environment variables (make java10 default)
sudo apt-get install oracle-java10-set-default

Note: You need update-alternatives only if you have multiple java versions.
Note: You can purge everything about Java before fresh installing new Java.
sudo apt purge java*
For Java 10 fresh installation
Download JDK 10 from here (you can download JRE and server JRE): http://www.oracle.com/technetwork/java/javase/downloads/index.html
Extract and put somewhere in /opt/java directory. You putting JDK in /opt/java directory makes it will be usable for all users as it is being in the public /opt directory.
(Note: I downloaded JDK, JRE, and server JRE, and extracted JDK and renamed extracted the folder to jdk10, extracted JRE and renamed extracted the folder to jre10, and extracted server JRE and renamed extracted the folder to jre10server as shown in below snapshot).
Update your /etc/environment file as below
Now, you need to reload the /etc/environment script file into the system using source command as below.
source /etc/environment
If you want to know more about update-alternatives then here is the link: https://askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre-jdk

You need to do update-alternatives --install before the final step.
sudo update-alternatives --install "/usr/bin/java" java "/usr/lib/jvm/java-10-openjdk-amd64/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" javac "/usr/lib/jvm/java-10-openjdk-amd64/bin/javac" 1

I've found a repo
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update
sudo apt install openjdk-10-jdk
Repo home page

Install Jdk 10 On Linux Ubuntu
Download the required tarball from from Oracle official
website, i.e.
https://www.oracle.com
Unzip this tarball using "tar -zxvf tarball_name”
Create a folder named "java" in "/usr/lib", you need root permission
sudo mkdir /usr/lib/java
Move the extracted folder to “/usr/lib/java/” by using the following command:
sudo mv java-10-dir-name/ /usr/lib/java/
Now go to the location, i.e. cd /usr/lib/java/java-10-dir-name/
Next, run these below scripts in terminal:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/java-10-dir-name/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/java-10-dir-name/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/java-10-dir-name/bin/javaws" 1
NOTE: In the commands given above, you have to name the extracted directory of "java" instead of "java-10-dir-name".
Update the JAVA_HOME in your ~/.bashrc
export JAVA_HOME=/usr/lib/java/java-10-dir-name
set PATH="$PATH:$JAVA_HOME/bin"
export PATH
Verify the installation
verify whether Java 10 is installed correctly in your machine, execute the following command in your terminal:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
And
$ javac --version
javac 10

Related

Where is 'javac' in java-17-openjdk-amd64?

Win10 WSL 2 over an Ubuntu layer
Ubuntu: lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 20.04.3 LTS
Release: 20.04
Codename: focal\
Java: java --version
openjdk 17.0.1 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.1+12-Ubuntu-120.04, mixed mode, Sharing)
I've successfully installed openjdk 17.0.1, but there is no 'javac' command in bin (such as exists in java-11-openjdk-amd64/bin). There is no javac counterpart in java-17-openjdk-amd64/bin.
I've googled, oogled, and bugled to no great gain. In my experience, this means I'm missing something simple.
Someone please guide me here. What gives? How can I get the 'javac' command in openjdk 17.0.1, or how do I use that SDK to create a class?
RHEL/RockyLinux/CentOs/AlmaLinux etc: javac is in "devel" package
dnf -y install java-17-openjdk
dnf -y install java-17-openjdk-devel
Then set default versions
alternatives --config java
alternatives --config javac
I'm unsure which directions I used to install Open JDK before, but I followed the following instructions to remove and re-install: https://www.linuxcapable.com/how-to-install-openjdk-17-on-ubuntu-20-04/
I now have 'javac' in java-17-openjdk-amd64/bin.
Whew.
This worked for me
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/jvm/jdk-17/bin/javac" 1

I can't find the javac for versions other than java17

I have installed multiple versions of java on my Linux mint mate 20.
I can find the multiple Java versions. But I can't find the multiple javac versions, javac is only present for Java 17.
I have installed all the Java version using
sudo apt-get install openjdk-x-jdk, where x is the the Java version.
This is the log of 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-17-openjdk-amd64/bin/java 1711 auto mode
1 /usr/lib/jvm/java-11-openjdk-amd64/bin/java 1111 manual mode
* 2 /usr/lib/jvm/java-17-openjdk-amd64/bin/java 1711 manual mode
3 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
Press <enter> to keep the current choice[*], or type selection number:
This is the log of sudo update-alternatives --config javac
atul#mintMate:~$ sudo update-alternatives --config javac
There is only one alternative in link group javac (providing /usr/bin/javac): /usr/lib/jvm/java-17-openjdk-amd64/bin/javac
Nothing to configure.
atul#mintMate:~$
This is my terminal log
atul#mintMate:~$ java -version
openjdk version "17.0.1" 2021-10-19
OpenJDK Runtime Environment (build 17.0.1+12-Ubuntu-120.04)
OpenJDK 64-Bit Server VM (build 17.0.1+12-Ubuntu-120.04, mixed mode, sharing)
atul#mintMate:~$ javac -version
javac 17.0.1
Is there a way to install or locate javac in the openjdk-amd64/bin/ folder. As I have already tried to look for them manually using the tree command.
Your Java 8 install is only for the Java Runtime Environment (JRE). Therefore, it won't have a Java compiler (javac). The compiler is part of the Java Development Kit (JDK).
Try installing Java 8 JDK: sudo apt-get install openjdk-8-jdk. It is likely that your Java 11 distribution is also a JRE-only install. If you need it, just install it the same way as I showed you for Java 8.

Install latest java version in ubuntu 16.04 [duplicate]

How do I install Java Development Kit (JDK) 10 on Ubuntu?
The installation instructions on Oracle's help center only explain how to download and extract the archive on Linux platform, without any system setup.
Update: JDK 11 Now Available
sudo apt-get install openjdk-11-jdk
For JDK 10
Option 1: Easy Installation (PPA)
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Then set as default with:
sudo apt-get install oracle-java10-set-default
And finally verify Installation with:
$ java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Source: Linux Uprising
Option 2: Manual Installation
Download OpenJDK 10 binaries for Linux.
Untar the downloaded archive:
tar xzvf openjdk-10_linux-x64_bin.tar.gz
Move the extracted archive to where your system keeps your installed JDKs:
sudo mv jdk-10 /usr/lib/jvm/java-10-openjdk-amd64/
Add the new Java alternative:
sudo update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1
sudo update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1
Update your system's java alternatives and choose JDK 10:
$ sudo update-alternatives --config java
here are 3 choices for the alternative java (providing /usr/bin/java).
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 auto mode
* 1 /usr/lib/jvm/java-10-openjdk-amd64/bin/java 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/java 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number:
and
$ sudo update-alternatives --config javac
There are 3 choices for the alternative javac (providing /usr/bin/javac).
Selection Path Priority Status
------------------------------------------------------------
* 0 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 auto mode
1 /usr/lib/jvm/java-10-openjdk-amd64/bin/javac 1 manual mode
2 /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1081 manual mode
3 /usr/lib/jvm/java-9-openjdk-amd64/bin/javac 1091 manual mode
Press <enter> to keep the current choice[*], or type selection number: 1
update-alternatives: using /usr/lib/jvm/java-10-openjdk-amd64/bin/javac to provide /usr/bin/javac (javac) in manual mode
Verify your installation with:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
and
$ javac --version
javac 10
Done
If you prefer Oracle's JDK, download it and follow the installation steps as shown above.
I've found SdkMan! a very useful tool because it provides a convenient way for managing your JDKs from the shell.
For example, once it is installed, you can:
Install a specific JDK version: sdk install java 10.0.2-open
Downloading: java 10.0.2-open
In progress...
################# 12,3%
Use a specific JDK version: sdk use java 10.0.2-open
Using java version 10.0.2-open in this shell.
List available JDK: sdk list java
===================================================================
Available Java Versions
===================================================================
9.0.4-open
+ 8u161-oracle
8.0.191-oracle
> + 8.0.171-oracle
7.0.191-zulu
12.ea.15-open
11.0.1-open
10.0.2-open
1.0.0-rc8-graal
===================================================================
+ - local version
* - installed
> - currently in use
=======================================================================
And much more
See https://sdkman.io/usage
There is a ppa on java 10 that installs oracle's java: https://launchpad.net/~linuxuprising/+archive/ubuntu/java
I am not sure if this will be maintained though.
It seems to be a copy of the webupd8 way on how to handle oracle java installation (ref: documentation).
How to use this ppa:
sudo add-apt-repository ppa:linuxuprising/java
sudo apt-get update
sudo apt-get install oracle-java10-installer
Verify installation:
$ /usr/lib/jvm/java-10-oracle/bin/java -version
java version "10.0.1" 2018-04-17
Java(TM) SE Runtime Environment 18.3 (build 10.0.1+10)
Java HotSpot(TM) 64-Bit Server VM 18.3 (build 10.0.1+10, mixed mode)
Setting up environment variables (make java10 default)
sudo apt-get install oracle-java10-set-default
Note: You need update-alternatives only if you have multiple java versions.
Note: You can purge everything about Java before fresh installing new Java.
sudo apt purge java*
For Java 10 fresh installation
Download JDK 10 from here (you can download JRE and server JRE): http://www.oracle.com/technetwork/java/javase/downloads/index.html
Extract and put somewhere in /opt/java directory. You putting JDK in /opt/java directory makes it will be usable for all users as it is being in the public /opt directory.
(Note: I downloaded JDK, JRE, and server JRE, and extracted JDK and renamed extracted the folder to jdk10, extracted JRE and renamed extracted the folder to jre10, and extracted server JRE and renamed extracted the folder to jre10server as shown in below snapshot).
Update your /etc/environment file as below
Now, you need to reload the /etc/environment script file into the system using source command as below.
source /etc/environment
If you want to know more about update-alternatives then here is the link: https://askubuntu.com/questions/159575/how-do-i-make-java-default-to-a-manually-installed-jre-jdk
You need to do update-alternatives --install before the final step.
sudo update-alternatives --install "/usr/bin/java" java "/usr/lib/jvm/java-10-openjdk-amd64/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" javac "/usr/lib/jvm/java-10-openjdk-amd64/bin/javac" 1
I've found a repo
sudo add-apt-repository ppa:openjdk-r/ppa
sudo apt update
sudo apt install openjdk-10-jdk
Repo home page
Install Jdk 10 On Linux Ubuntu
Download the required tarball from from Oracle official
website, i.e.
https://www.oracle.com
Unzip this tarball using "tar -zxvf tarball_name”
Create a folder named "java" in "/usr/lib", you need root permission
sudo mkdir /usr/lib/java
Move the extracted folder to “/usr/lib/java/” by using the following command:
sudo mv java-10-dir-name/ /usr/lib/java/
Now go to the location, i.e. cd /usr/lib/java/java-10-dir-name/
Next, run these below scripts in terminal:
sudo update-alternatives --install "/usr/bin/java" "java" "/usr/lib/java/java-10-dir-name/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/lib/java/java-10-dir-name/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/lib/java/java-10-dir-name/bin/javaws" 1
NOTE: In the commands given above, you have to name the extracted directory of "java" instead of "java-10-dir-name".
Update the JAVA_HOME in your ~/.bashrc
export JAVA_HOME=/usr/lib/java/java-10-dir-name
set PATH="$PATH:$JAVA_HOME/bin"
export PATH
Verify the installation
verify whether Java 10 is installed correctly in your machine, execute the following command in your terminal:
$ java --version
openjdk 10 2018-03-20
OpenJDK Runtime Environment 18.3 (build 10+46)
OpenJDK 64-Bit Server VM 18.3 (build 10+46, mixed mode)
And
$ javac --version
javac 10

Changing java 7 to java 8 ubuntu openjdk not working

I have a project that runs on Jenkins using docker. At start the docker have java 7 installed by default which is necesary for the project to build. But after, the proyect build and is up, I need to install java 8 to run the e2e tests, selenium server needs java 8. So to install java 8 i use openjdk8 the following ways:
apt-get -y update
apt-get install -y openjdk-8-jdk
echo 'Changing Java version, it should be 8'
export JAVA_HOME="/usr/lib/jvm/java-8-openjdk-amd64"
echo "path"
echo $JAVA_HOME
echo "version java"
java -version
The problem is that when this runs it still outputs the java 7. Below output from the code above.
Changing Java version, it should be 8
path
/usr/lib/jvm/java-8-openjdk-amd64
version java
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)
Any idea what could be happening?
you can do following:
update-alternatives --install /usr/bin/java java /usr/lib/jvm/java-8-openjdk-amd64/bin/java 1
update-alternatives --install /usr/bin/javac javac /usr/lib/jvm/java-8-openjdk-amd64/bin/javac 1
and then by using following you can set the config to use which version:
update-alternative --config java
update-alternative --config javac
Make sure that java8 home/bin is first in the path
update-java-alternatives --list | grep java-8
export JAVA_HOME= java 8 path here
export PATH=$JAVE_HOME/bin:$PATH

ppa:webupd8team/java is only loading jre

The instructions at oracle state that running the following will install both the jre and jdk.
sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java8-installer
Then sudo apt-get install oracle-java8-set-default
and sure enough when I run java -version I get:
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
and when I run javac -version I get:
javac 1.8.0_101
So I believe that means the jdk is installed. So to point $JAVA_HOME to the jdk I run sudo update-alternatives --config java to see where to point to. I get:
Selection Path Priority Status
------------------------------------------------------------
0 /usr/lib/jvm/java-8-oracle/jre/bin/java 2 auto mode
* 1 /usr/lib/jvm/java-8-oracle/jre/bin/java 2 manual mode
2 /usr/local/java/jre1.8.0_74/bin/java 1 manual mode
I don't see a jdk folder to point to here? I've searched for a jdk folder on the system (ubuntu 14.04) but don't find one. The contents of the `/usr/lib/jvm/java-8-oracle/ folder are:
bin COPYRIGHT db include javafx-src.zip jre lib LICENSE man README.html release src.zip THIRDPARTYLICENSEREADME-JAVAFX.txt THIRDPARTYLICENSEREADME.txt
Am I going nuts or is the PPA repository not in fact installing the jdk?
The problem relates to a react-native application throwing this error > Could not find tools.jar
So for anyone who runs into issues with getting their local jdk install to work; one thing to check is that your update-alternatives has been correctly installed.
In my output above under sudo update-alternatives --config java you will see that the selected line points to the jre directory. I had been expecting to find a jdk folder to which I could point, but the jdk path (in this case) is /usr/lib/jvm/java-8-oracle/bin/java. With the oracle java-8 install the java-8-oracle/bin/java directory IS the jdk and the jre directory is a sub-directory of java-8-oracle (the jdk).
This was obvious once I downloaded jdk1.8.0_101 only to find the contents were the same as java-8-oracle. In all my searches the advice was to point to the jdk folder - hence the expectation that something was missing, which it wasn't - just not named as expected.
To update your alternatives do:
sudo update-alternatives --install "/usr/bin/java" "java" \
"/usr/lib/jvm/java-8-oracle/bin/java" 1 <-- should be your path; this is mine.

Categories

Resources