How to make apt recognize an installed tar package?

I’ve installed Oracle Java. I want to be able to remove OpenJDK, but when trying to do so apt wants to install another version of Java.

How can I configure apt so that it knows I already have a third-party Java installed so I can remove these OpenJDK packages?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Create a dummy package using equivs. In a nutshell:

  1. Create a control file for the dummy package. The program equiv-controls creates a template. Give it a file name.
    equivs-control oracle-jre.control
  2. Edit the control file. At least set the Package: line to sun-java6-jre (the name of the defunct Sun/Oracle Java package). You should also write a meaningful Description:, set the section to java. Declare that the package Provides: java-6-runtime and other versions (this is the virtual package that other programs depend on, can find this out by checking what openjdk-6-jre provides and what various programs require). The file might look like this:
    Section: java
    Priority: optional
    Standards-version: 3.9.2
    Package: sun-6-jre
    Provides: java6-runtime, java-runtime
    Description: dummy package when Oracle Java is installed
  3. Create a Debian package with the control file you created. This package is only there for the dependencies and installs no file.
    equivs-build oracle-jre.control
  4. Install the resulting deb package.
    sudo dpkg -i sun-6-jre_1.0_all.deb

Method 2

I do not believe there is a method for doing this. In lieu of using a PPA repository that provides you with .deb packages of Java, you could give this script a try which will roll you’re own .deb packages of the Java installation.

This script is called OAB-Java, specifically oab-java.sh.

Example

Downloading the script:

cd ~/
wget https://github.com/flexiondotorg/oab-java6/raw/0.2.8/oab-java.sh -O oab-java.sh
chmod +x oab-java.sh
sudo ./oab-java.sh

The script takes the following switches:

  • -7 : Build oracle-java7 packages instead of sun-java6
  • -c : Remove pre-existing packages from /var/local/oab/deb and sources from /var/local/oab/src.
  • -k : Use the specified existing key instead of generating one
  • -s : Skip building if the packages already exist
  • -t : Specify the Java version tag to use from the upstream Debian packaging script.
  • -h : This help

To prepare & install the Oracle 6 .deb files:

$ sudo ./oab-java.sh
$ sudo apt-get install sun-java6-jre

To prepare & install the Oracle 7 .deb files:

$ sudo ./oab-java.sh -7
$ sudo apt-get install oracle-java7-jre

Method 3

The answer above given by @Gilles worked perfectly for me for a while. With Java 8 and newer versions of Ubuntu, though, it doesn’t work. Following is the oracle-jre.control file I now use.

Section: java
Priority: optional
Standards-version: 3.9.2
Package: sun-8-jre
Provides: default-jre, openjdk-8-jre, openjfx
Description: Dummy package when Oracle Java is installed

Method 4

You can put a hold on a package with apt-mark.

Hold:

sudo apt-mark hold package_name

Unhold:

sudo apt-mark unhold package_name

That will prevent apt from touching it.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x