How to specify which version of Java to use in the terminal?

Java 8 is installed on CentOS 7 devbox. I need to use Java 7 to compile cans. So I downloaded and installed Java 7, but it java -versionstill shows Java 8. How can I make sure Java 7 is used to compile jar on the command line?

Here are the steps I took to install Java 7:

# wget --no-check-certificate --no-cookies --header "Cookie: oraclelicense=accept-securebackup-cookie" http://download.oracle.com/otn-pub/java/jdk/7u75-b13/jdk-7u75-linux-x64.rpm  
# rpm -ivh jdk-7u75-linux-x64.rpm
# export JAVA_HOME=/usr/java/latest
# java -version
java version "1.8.0_45"
Java(TM) SE Runtime Environment (build 1.8.0_45-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.45-b02, mixed mode)

As you can see, it java -versionstill points to Java 8, although it /usr/java/latestpoints to the just downloaded and installed version of Java 7.

The command I want to run is java -jar gs-actuator-service-0.1.0.jar. Can someone show how to change the syntax in this particular command to indicate the version of Java 7? Or do I need to remove Java 8? If so, what specific steps am I taking?

+4
3

- Java , .

export PATH=$JAVA_HOME/bin:$PATH

- , alternatives Java 7 .

alternatives --config java
+5
${JAVA_HOME}/bin/java -version

JAVA_HOME . , Java-. , .

+1
alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1
alternatives --config java

: Centos

-3

Source: https://habr.com/ru/post/1622012/


All Articles