Installing Oracle JDK 7 in Debian/Ubuntu/Mint

I am currently learning Scala and wanted to install the Scala IDE. In the process I ran into some problems that it programs would not compile correctly, which seemed to be caused by the OpenJDK 7. So I decided to remove OpenJDK 7 and install Oracle JDK 7. All the instructions I could find to do this where downloading based on manually downloading the Oracle JDK 7 and installing it interactively. As I also wanted the installation to work in a Docker container I wanted a fully automated solution.

I came up with the following instruction:

# Switch to root
su -

# Tell Debian/Ubuntu/Mint we are running in non-interactive mode to avoid dialog
# error when installing Oracle JDK
export DEBIAN_FRONTEND=noninteractive

# Install Oracle JDK repository and install JDK 7
echo "deb http://archive.ubuntu.com/ubuntu trusty main universe" > /etc/apt/sources.list && \
apt-get update && \
apt-get -y install software-properties-common python-software-properties && \
add-apt-repository ppa:webupd8team/java -y && \
apt-get -y update && \
apt-get purge openjdk* \
echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections && \
apt-get -y install oracle-java7-installer && \
apt-get -y install oracle-java7-set-default && \
apt-get clean && \
rm -rdf /var/cache/oracle-jdk7-installer

Some notes:
1) The line “apt-get -y install software-properties-common python-software-properties” is needed when installing a Docker image. These packages are needed for the add-appt-repository. Can be omitted if installing directly in Debian/Ubuntu/Mint.
2) The line “apt-get purge openjdk*” removes all installed versions of OpenJDK. The line can be omitted when installing in a Docker container.
3) The line “echo debconf shared/accepted-oracle-license-v1-1 select true | debconf-set-selections” is to make sure yes is answered when the Oracle JDK 7 license dialog is displayed.
4) The line “apt-get -y install oracle-java7-installer” is used to set Oracle JDK 7 as the default JDK.
5) The last two lines are some housekeeping to remove the repositories and JDK installation files (useful when using these commands in Docker to keep the image size to a minimum).

Leave a comment