2

How to install Java 13 on Ubuntu 18.04.3 from terminal with sudo privildges?

tgkprog
  • 585
  • 1
  • 14
  • 30

1 Answers1

1

Method 2 For newer Ubuntu (tested in 2025 with Ubuntu 22.04):

 sudo apt update
 sudo apt upgrade -y
 apt search openjdk
 #select a version like openjdk-21-jdk or headless if server
 # notice the jdk and not jre if you want to compile & build
 # headless for jdk without UI non GUi programs; server side, batch, terminal only
 sudo apt install openjdk-21-jdk-headless -y

Remove the -y if you want to be prompted

this lists till jdk 21, for newer ones need to use method 1 for now


Method 1: Followed https://openjdk.java.net/install/index.html per Pilot6 comment (thanks).

JDk 22 and later : https://jdk.java.net/23/

JDK 9 to 21

Oracle's OpenJDK JDK binaries for Windows, macOS, and Linux are available on release-specific pages of jdk.java.net as .tar.gz or .zip archives.

As an example, the archives for JDK 13 may be found on jdk.java.net/13 and may be extracted on the command line using

$ tar xvf openjdk-13*_bin.tar.gz

Commands to download java 15 from jdk net (Linux / x64) using terminal and saving to a folder in Downloads folder called 'j'. ~ is shortcut for current logged in user's home directory

mkdir ~/Downloads/j
cd  ~/Downloads/j
curl https://download.java.net/java/GA/jdk15.0.2/0d1cfde4252546c6931946de8db48ee2/7/GPL/openjdk-15.0.2_linux-x64_bin.tar.gz --output ./jdk_15.0.2_linuxx64bin.tar.gz
 tar xvf j16.tar.gz

Used sudo mv to move directory 'jdk-13.0.1' to /usr/lib/jvm/

  sudo mv jdk-13  /usr/lib/jvm/

Then in my ~/.profile file added/edited (as I had Java 11 before) in text editor:

export JAVA_HOME=/usr/lib/jvm/jdk-13.0.1
export PATH=$JAVA_HOME/bin:$PATH

In the current terminal(s) to reload the profile after changes gave command:

. ~/.profile 

Note that its a period, a space and then the file name. Its short hand for the command:

source ~/.profile

and could use Java 13. Worked after restart too, without running the commands, due to entry in ~/.profile

To test, in terminal give command : echo $JAVA_HOME Will see out put :

/usr/lib/jvm/jdk-13.0.1

You can also set it up as alternatives as in https://askubuntu.com/a/464894/165511 I like to set up the JAVA_HOME variable as need that to run maven etc

sudo update-alternatives --config java
sudo update-alternatives --config javac

Also run

java -version

and

javac -version

To check version of java that is used in that terminal. remember ytou can have different versions in different scripts and programs

tgkprog
  • 585
  • 1
  • 14
  • 30