2

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

1 Answer 1

2

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

3
  • 1
    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. Jun 10 at 16:15
  • 1
    Because it is sandboxed and isolated from the rest of the system, including system libraries and resources
    – Saxtheowl
    Jun 10 at 16:17
  • 1
    i was installing openjdk 22 on ubuntu 22.04 LTS, and it was no longer the case, the above commands no longer works. instead , the snap openjdk comes with a config file located at /snap/openjdk/current/openjdk.env, run ". $(openjdk)" in the command line , and it's done . details refes to github.com/jgneff/openjdk#self-contained Aug 27 at 9:22

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .