Score:2

How do I install and setup OpenJDK in Ubuntu from Snapcraft?

mx flag

How is OpenJDK installed from snap so that javac and java are available from the CLI?

nicholas@mordor:~$ 
nicholas@mordor:~$ snap list
Name                       Version           Rev    Tracking         Publisher      Notes
bare                       1.0               5      latest/stable    canonical✓     base
chromium                   113.0.5672.126    2477   latest/stable    canonical✓     -
core18                     20230503          2751   latest/stable    canonical✓     base
core20                     20230503          1891   latest/stable    canonical✓     base
core22                     20230531          750    latest/stable    canonical✓     base
cups                       2.4.2-5           872    latest/stable    openprinting✓  -
firefox                    111.0.1-2         2517   latest/stable/…  mozilla✓       -
gnome-3-38-2004            0+git.6f39565     140    latest/stable    canonical✓     -
gnome-42-2204              0+git.587e965     102    latest/stable/…  canonical✓     -
gtk-common-themes          0.1-81-g442e511   1535   latest/stable/…  canonical✓     -
openjdk                    20.0.1+9          1349   latest/stable    jgneff         -
snap-store                 41.3-71-g709398e  959    latest/stable/…  canonical✓     -
snapd                      2.59.4            19361  latest/stable    canonical✓     snapd
snapd-desktop-integration  0.9               83     latest/stable/…  canonical✓     -
nicholas@mordor:~$ 
nicholas@mordor:~$ openjdk.java -version
openjdk version "20.0.1" 2023-04-18
OpenJDK Runtime Environment (build 20.0.1+9-snap)
OpenJDK 64-Bit Server VM (build 20.0.1+9-snap, mixed mode, sharing)
nicholas@mordor:~$ 
nicholas@mordor:~$ java --version
Command 'java' not found, but can be installed with:
sudo apt install openjdk-17-jre-headless  # version 17.0.7+7~us1-0ubuntu1~23.04, or
sudo apt install default-jre              # version 2:1.17-74
sudo apt install openjdk-11-jre-headless  # version 11.0.19+7~us1-0ubuntu1~23.04
sudo apt install openjdk-20-jre-headless  # version 20.0.1+9~us1-0ubuntu1~23.04
sudo apt install openjdk-8-jre-headless   # version 8u372-ga~us1-0ubuntu1~23.04
sudo apt install openjdk-18-jre-headless  # version 18.0.2+9-2ubuntu1
sudo apt install openjdk-19-jre-headless  # version 19.0.2+7-0ubuntu4
sudo apt install openjdk-21-jre-headless  # version 21~14ea~us1-0ubuntu1
nicholas@mordor:~$ 
nicholas@mordor:~$ javac --version
Command 'javac' not found, but can be installed with:
sudo apt install openjdk-17-jdk-headless  # version 17.0.7+7~us1-0ubuntu1~23.04, or
sudo apt install default-jdk              # version 2:1.17-74
sudo apt install openjdk-11-jdk-headless  # version 11.0.19+7~us1-0ubuntu1~23.04
sudo apt install openjdk-20-jdk-headless  # version 20.0.1+9~us1-0ubuntu1~23.04
sudo apt install openjdk-8-jdk-headless   # version 8u372-ga~us1-0ubuntu1~23.04
sudo apt install ecj                      # version 3.32.0+eclipse4.26-2
sudo apt install openjdk-18-jdk-headless  # version 18.0.2+9-2ubuntu1
sudo apt install openjdk-19-jdk-headless  # version 19.0.2+7-0ubuntu4
sudo apt install openjdk-21-jdk-headless  # version 21~14ea~us1-0ubuntu1
nicholas@mordor:~$ 
nicholas@mordor:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 23.04
Release:    23.04
Codename:   lunar
nicholas@mordor:~$ 

see also:

https://stackoverflow.com/q/67469925/4531180

https://snapcraft.io/install/openjdk/ubuntu

Score:2
iq flag

The snap binaries are not in your system PATH, try running the java and javac commands with the full snap command, like openjdk.java and openjdk.javac, you can also create symbolic link like:

sudo ln -s /snap/bin/openjdk.java /usr/bin/java
sudo ln -s /snap/bin/openjdk.javac /usr/bin/javac

Still the best would be to use an environment manager for Java, like SDKMAN or jEnv

Nicholas Saunders avatar
mx flag
I had forgotten about SDKMAN and am interested to hear about jEnv. Curious why the snap wouldn't be able to put the binaries in the PATH.
Saxtheowl avatar
iq flag
Because it is sandboxed and isolated from the rest of the system, including system libraries and resources
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.