1

It's the first time for me to install packages in Ubuntu.I know not much about the apt command.When i type java in the command window directly,these below message appears:

XXX@nwtjkswskuae4w6f-0717825:~$ java
The program 'java' can be found in the following packages:
 * default-jre
 * gcj-4.8-jre-headless
 * openjdk-7-jre-headless
 * gcj-4.6-jre-headless
 * openjdk-6-jre-headless
Ask your administrator to install one of them

So, here's my question:

  1. How does these message come about? I mean,how does the shell find program 'in the following packages' when i type java or the other commands?
  2. Where to find these packages like 'gcj-4.8-jre-headless' or 'openjdk-7-jre-headless', and why is the java command related to these packages?
dcom-launch
  • 147
  • 6
madwolf
  • 19
  • 2

2 Answers2

0

The syntax to install a new package, with the valid package name is

sudo apt install [packagename]

In this instance, the command you need is:

sudo apt install openjdk-7-jre-headless

The reason the shell knows about those packages is there is a cache for apt, which contains a list of all known packages based on the repos you have configured. It knows which program names are provided by which packages. So, if you try one of those package names but don't have the proper package installed, it notifies the user for convenience.

You can find package names using the command :

apt-cache search [search query] , for example apt-cache search java. This will search the package name and package descriptions in your cache for whatever search term you provide.

dcom-launch
  • 147
  • 6
  • >The reason the shell knows about those packages is there is a cache for apt, which contains a list of all known packages based on the repos you have configured. It knows which program names < Are you sure that's coming from apt-cache and not apt-file? – g00se Jul 23 '21 at 14:27
0

Hello if you type in your terminal java --version , what is the Output ? If Java is not installed, you can install it with openJDK11 with the following command :

sudo apt-get update    
sudo apt install default-jdk

It will install the openJDK11 LTS

Quentin Genet
  • 155
  • 2
  • 3
  • 15