原文:https://askubuntu.com/questions/761127/how-do-i-install-openjdk-7-on-ubuntu-16-04-or-higher
Option 1: Manual Installation
Download the packages intended for your architecture:
(for most users, this means amd64 if 64bit, or i386 if 32bit Ubuntu is installed)
(Attempt to) install the packages usingdpkg:
sudo dpkg-i openjdk-7-*libjpeg62-turbo*
Check the output fromdpkg. If there were dependency problems - which is likely - you will see the following (with your architecture substituted for amd64):
Errors were encountered while processing:
openjdk-7-jre:amd64
openjdk-7-jre-headless:amd64
openjdk-7-jdk:amd64
If there were no dependency issues, great, you're done, skip to #4. Otherwise, if you need to resolve some dependency issues, this is handled with:
sudo apt install-f
Notice, there is no need to re-rundpkgafter lettingaptresolve dependencies. It will automatically finish installation of the openjdk packages.
Update java alternatives. You can view all installed java versions withupdate-java-alternatives --list. To activate OpenJDK Java 1.7, run:
sudo update-java-alternatives-s java-1.7.0-openjdk-amd64
You may notice an error about theIcedTeaPlugin.soplugin being unavailable. This isn't a real concern for developers working with the JDK.
Verify java is working:
java-version
which should output something similar to:
java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
Option 2: Automatic Installation(including updates withapt)
Pinningcan be utilized to install and update openjdk-7 and libjpeg62-turbo (a dependency) from Debian repositories.
Install the Debian keyring:
sudo apt install debian-archive-keyring
Add the needed repositories:
sudo add-apt-repository'deb http://httpredir.debian.org/debian experimental main'sudo add-apt-repository'deb http://httpredir.debian.org/debian sid main'
Why not use a stable Debian repository?You'll run into unsatisfiable dependencies with Debian stable. The experimental (for openjdk-7) and sid (for libjpeg62-turbo) repositories are more lenient with dependency versions.
Create a pinning file that tellsaptto only consider packages that interest us (we certainly don't want our entire Ubuntu distribution "upgraded" with Debian experimental packages).
Create file/etc/apt/preferences.d/debianwith the below contents. You'll need superuser privileges, so use one ofsudo vim,sudo nano,gksudo gedit, etc.
Package:*Pin:release o=Debian,n=experimentalPin-Priority:-1Package:*Pin:release o=Debian,n=sidPin-Priority:-1Package:openjdk-7-jdkPin:release o=Debian,n=experimentalPin-Priority:500Package:openjdk-7-jrePin:release o=Debian,n=experimentalPin-Priority:500Package:openjdk-7-jre-headlessPin:release o=Debian,n=experimentalPin-Priority:500Package:libjpeg62-turboPin:release o=Debian,n=sidPin-Priority:500
Updateaptcache (expect this to take a while since Debian's package lists are big):
sudo apt update
Install openjdk-7-jdk:
sudo apt install openjdk-7-jdk
Update java alternatives. You can view all installed java versions withupdate-java-alternatives --list. To activate OpenJDK Java 1.7, run:
sudo update-java-alternatives-s java-1.7.0-openjdk-amd64
You may notice an error about theIcedTeaPlugin.soplugin being unavailable. This isn't a real concern for developers working with the JDK.
Verify java is working:
java-version
which should output something similar to:
java version "1.7.0_121"
OpenJDK Runtime Environment (IcedTea 2.6.8) (7u121-2.6.8-1)
OpenJDK 64-Bit Server VM (build 24.121-b00, mixed mode)
网友评论