Recently the department has introduced a batch of new servers on which the JDK is to be installed. In order to keep consistent with the JDK version on the existing machine, you need to download and install the Oracle JDK .
Although it can be installed using the yum installation tool, it cannot guarantee that the installed version is the one you want. For example, if the version I need to install is JDK 1.6.0_22, I need to go to oracal official website to download it.
Find the corresponding installation file jdk-6u22-linux-x64-rpm.bin , download it, upload it to the server, and the rest is installation. However, how should this strangely named file (*rpm.bin) be installed?
Only two steps are required:
- jdk-6u22-linux-x64-rpm.bin itself can be executed directly, just need to modify the execution permission.
$ chmod a+x jdk-6u22-linux-x64-rpm.bin
- Then just execute it directly.
$ ./jdk-6u22-linux-x64-rpm.bin
Execution output:
Unpacking... Checksumming... Extracting... UnZipSFX 5.50 of 17 February 2002, by Info-ZIP ([email protected]). inflating: jdk-6u22-linux-amd64.rpm inflating: sun-javadb-common-10.5.3-0.2.i386.rpm inflating: sun-javadb-core-10.5.3-0.2.i386.rpm inflating: sun-javadb-client-10.5.3-0.2.i386.rpm inflating: sun-javadb-demo-10.5.3-0.2.i386.rpm inflating: sun-javadb-docs-10.5.3-0.2.i386.rpm inflating: sun-javadb-javadoc-10.5.3-0.2.i386.rpm Preparing... ########################################### [100%] 1:jdk ########################################### [100%] Unpacking JAR files... rt.jar... jsse.jar... charsets.jar... tools.jar... localedata.jar... plugin.jar... javaws.jar... deploy.jar... Installing JavaDB Preparing... ########################################### [100%] 1:sun-javadb-common ########################################### [ 17%] 2:sun-javadb-core ########################################### [ 33%] 3:sun-javadb-client ########################################### [ 50%] 4:sun-javadb-demo ########################################### [ 67%] 5:sun-javadb-docs ########################################### [ 83%] 6:sun-javadb-javadoc ########################################### [100%] Java(TM) SE Development Kit 6 successfully installed. Product Registration is FREE and includes many benefits: * Notification of new versions, patches, and updates * Special offers on Sun products, services and training * Access to early releases and documentation Product and system data will be collected. If your configuration supports a browser, the Sun Product Registration form for the JDK will be presented. If you do not register, none of this information will be saved. You may also register your JDK later by opening the register.html file (located in the JDK installation directory) in a browser. For more information on what data Registration collects and how it is managed and used, see: http://java.sun.com/javase/registration/JDKRegistrationPrivacy.html Press Enter to continue..... Done.
It is installed by default under the /usr/java/jdk1.6.0_22 path. You can move it to any other location, such as following the path on other servers, put it under /opt/app, and execute the mv command:
$ mv /usr/java/jdk1.6.0_22 /opt/app
----
When the jdk is installed in the above way, how to make it take effect: that is, how to make it the default environment of the system?
Doing this requires setting the JAVA_HOME environment variable and incorporating it into the system's PATH variable.
First check the value of the current JAVA_HOME variable:
$ echo $JAVA_HOMEThe return value is empty, indicating that the variable has not been explicitly set yet.
In order to set JAVA_HOME and ensure that the settings are still in effect on the next login, we need to modify the system startup script.
- If you only want the settings to take effect under the currently logged in user, you need to modify the ~/.bash_profile file
- If you want the settings to apply to all users of the system, you need to modify the /etc/profile file
The modification method is: use vim to open the corresponding file and add code similar to the following at the end of the file:
# Set JAVA_HOME / PATH
export JAVA_HOME=/opt/app/jdk1.6.0_22
export PATH=$PATH:$JAVA_HOME/bin
To make the configuration take effect immediately, execute the source command:
$ source ~/.bash_profile
OR
$ source /etc/profile
So far, we have successfully set the newly installed Sun JDK as the system default.