|
CentOS 7 is the current default jdk1.6 and 1.7. If you need a later version 1.8, we need a little extra means.
First, we need the next page from the latest version of jdk. Oracle provides rpm packages and tar.gz package. In order to save trouble, directly download a rpm package bin.
After the download is complete, you can use the rpm command to install, but prefer to use yum to get lazy.
# Yum localinstall jdk-8u20-linux-x64.rpm -y
...
Resolving Dependencies
-> Running transaction check
---> Package jdk1.8.0_20.x86_64 2000: 1.8.0_20-fcs will be installed
-> Finished Dependency Resolution
...
Installed:
jdk1.8.0_20.x86_64 2000: 1.8.0_20-fcs
Complete!
After installation, in order to save space, rpm packages can also be deleted.
This is in fact jdk under / usr / java directory to configure a set of environment. View this directory, we can see more than a directory jdk1.8.0_20, while soft chain link to the next and last two default directories.
$ Ls -al / usr / java
total 12
drwxr-xr-x. 3 root root 4096 Oct 13 22:10.
drwxr-xr-x. 15 root root 4096 Jul 31 04:27 ..
lrwxrwxrwx 1 root root 16 Oct 13 22:10 default -.> / usr / java / latest
drwxr-xr-x. 9 root root 4096 Oct 13 22:10 jdk1.8.0_20
lrwxrwxrwx 1 root root 21 Oct 13 22:10 latest -.> /usr/java/jdk1.8.0_20
But so far it has not been in practical use. We need alternative tools to manage.
Because of soft links, if we will point to the configuration of the contents of / usr / java / default / bin / xxx, after installation jdk 1.9 or even 2.0, so long as the direct link to modify in soft, without having to do so again. So below I will use the / usr / java / default / new java home.
However, occasionally passing you, if do not intend to do so, but want to specify the version without using jdk1.8.0_20 want to change your own default will replace jdk1.8.0_20. The following are all so similar situation, please note.
First, let's view the current alternative environment.
# Alternatives --config java
There is 1 program that provides 'java'.
Selection Command
-----------------------------------------------
* + 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
Enter to keep the current selection [+], or type selection number: ^ C
We note that under, alternatives already have a java, and our goal is to not destroy the original environmental conditions of a 1.8 increase. Of course, after the completion of all, of you can try to delete their own share of the installed rpm package .
We added alternative first java
# Alternatives --install / usr / bin / java java / usr / java / default / bin / java 2
Several parameters are better understood, the executable file is / usr / java / default / bin / java soft link to / usr / bin / java, configuration named java, the last parameter 2 is because we saw before, we've got a java, so the index to select 2.
Then continue the configuration
# Alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* + 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
2 / usr / java / default / bin / java
Enter to keep the current selection [+], or type selection number: 2
We found out more than a choice, we point to the newly installed / usr / java / defalut / bin / java. Select this command.
Go look at:
# Alternatives --config java
There are 2 programs which provide 'java'.
Selection Command
-----------------------------------------------
* 1 /usr/lib/jvm/java-1.7.0-openjdk-1.7.0.65-2.5.1.2.el7_0.x86_64/jre/bin/java
+ 2 / usr / java / default / bin / java
Enter to keep the current selection [+], or type selection number: 2
We found that the + sign has been moved below.
Similarly, we'll configuration remaining
# Alternatives --install / usr / bin / jar jar / usr / java / default / bin / jar 2
# Alternatives --install / usr / bin / javac javac / usr / java / default / bin / javac 2
# Alternatives --set jar / usr / java / default / bin / jar
# Alternatives --set javac / usr / java / default / bin / javac
This will get.
Finally, we can verify the next:
$ Java -version
java version "1.8.0_20"
Java (TM) SE Runtime Environment (build 1.8.0_20-b26)
Java HotSpot (TM) 64-Bit Server VM (build 25.20-b23, mixed mode)
$ Javac -version
javac 1.8.0_20
Finally, we may need to configure the environment variables.
Environment variables can be configured under ordinary users.
You can write
$ Export JAVA_HOME = / usr / java / default
And other blabla.
However, we also want to write the configuration file. Depending on the specific shell may be. If using bash, add content in ~ / .bashrc or ~ / .bash_profile follows:
export JAVA_HOME = / usr / java / default
export JRE_HOME = / usr / java / default / jre
export PATH = $ PATH: $ JAVA_HOME / bin: $ JRE_HOME / bin |
|
|
|