install openjdk-7 on Linuxmint 19.1 or Ubuntu 18.04

some application still rely on old java, for example iReport 4.0.1 that used by openbravo still rely on java 7. however recent release of linuxmint 19.1 (based on ubuntu 18.04) come with java 8 as it’s default. this tutorial share how to install java 7 along with java 8 and how to switch each other.

this tutorial based on this page. here the step-by-step guidance:

Download the JDK for Linux 32-bit or 64-bit (for example: jdk-7u80-linux-x64.tar.gz) here.
Navigate to your downloaded JDK (for example ~/Downloads):

cd /home/"your_user_name"/Downloads

Create a a directory in /usr/local where java will reside and copy tarball there:

sudo mkdir -p /usr/local/java
sudo cp -r jdk-7u80-linux-x64.tar.gz /usr/local/java/

Navigate to /usr/local/java:

cd /usr/local/java/

Extract the tarball:

sudo tar xvzf jdk-7u80-linux-x64.tar.gz

Check if tarball has been successfully extracted:

ls –a

you should see jdk1.7.0_80

Open /etc/profile with sudo privileges:

sudo nano /etc/profile
Scroll down to the end of the file using arrow keys and add the following lines below to the end of /etc/profile file:
JAVA_HOME=/usr/local/java/jdk1.7.0_80
JRE_HOME=/usr/local/java/jdk1.7.0_80
PATH=$PATH:$JRE_HOME/bin:$JAVA_HOME/binexport
export JAVA_HOME
export JRE_HOME
export PATH

Update alternatives:

sudo update-alternatives --install "/usr/bin/java" "java" "/usr/local/java/jdk1.7.0_80/bin/java" 1
sudo update-alternatives --install "/usr/bin/javac" "javac" "/usr/local/java/jdk1.7.0_80/bin/javac" 1
sudo update-alternatives --install "/usr/bin/javaws" "javaws" "/usr/local/java/jdk1.7.0_80/bin/javaws" 1
sudo update-alternatives --set java /usr/local/java/jdk1.7.0_80/bin/java
sudo update-alternatives --set javac /usr/local/java/jdk1.7.0_80/bin/javac
sudo update-alternatives --set javaws /usr/local/java/jdk1.7.0_80/bin/javaws

Reload profile:

source /etc/profile

Verify installation:

java -version

You should receive a message which displays:

java version “1.7.0_80”
Java™ SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot™ 64-Bit Server VM (build 24.80-b11, mixed mode)
switch back to java 8:
sudo update-alternatives --config java
You should receive a message which display:

There are 3 choices for the alternative java (providing /usr/bin/java).

Selection Path Priority Status

  0            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      auto mode
  1            /usr/lib/jvm/java-11-openjdk-amd64/bin/java      1101      manual mode
  2            /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java   1081      manual mode
* 3            /usr/local/java/jdk1.7.0_80/bin/java             1         manual mode

Press to keep the current choice[*], or type selection number:
for that case, type 2 to switch back to java 8
Verify when you switch back to java 8:

java -version

You should receive a message which displays:

openjdk version “1.8.0_191”
OpenJDK Runtime Environment (build 1.8.0_191-8u191-b12-2ubuntu0.18.04.1-b12)
OpenJDK 64-Bit Server VM (build 25.191-b12, mixed mode)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值