Linu Study Notes-install and uninstall JDK on ubuntu

Source: Internet
Author: User

Linu Study Notes-install and uninstall JDK on ubuntu

 

Abstract: This document mainly records how to manually install and install JDK in ubuntu12.0.4 and manually delete JDK using shell scripts. It also involves some small commands. Scp and tar.

 

I. Manual Installation

 

1.1 obtain the corresponding installation package

 

I downloaded it from another ubuntu machine and moved it from there. Scp can be used to copy files from different Linux systems in the same LAN, provided that the IP addresses of the two computers can ping each other.

Assume that my machine is A and the IP address is 192.168.26.222.

The other one has jdk B and IP address 192.168.26.249.

Use the following command on the terminal interface of B:

Scp jdk-7u51-linux-x64.tar.gz root@192.168.26.222:

Enter the root user password of 192.168.26.222, and the specified file (jdk) will be transmitted to the/root folder of 192.168.26.222.

 

1.2decompress jdk-7u51-linux-x64.tar.gz

 

1.2.1 tar command

 

To access the server through SSH, it is inevitable that compression, decompression, packaging, and unpacking will be used. In this case, the tar command is an essential and powerful tool. The most popular tar in linux is very powerful, although it is small.

The tar command can create files for linux Files And Directories. Using tar, you can create a file (backup file) for a specific file, change the file in the file, or add a new file to the file. Tar was originally used to create files on tape. Now, you can create files on any device. Using the tar command, you can package a large number of files and directories into one file, which is very useful for backing up files or combining several files into one file for network transmission.

First, we need to clarify two concepts: Packaging and compression. Packaging refers to converting a large number of files or directories into a total file. Compression refers to converting a large file into a small file through some compression algorithms.

Why do we need to differentiate these two concepts? This is because many Linux compression programs can only compress one file. In this way, when you want to compress a large number of files, you must first compress these files into a package (tar command ), then use the compression program to compress (gzip bzip2 command ).

At the end of lifecycle. After the tar package is generated, other programs can be used for compression.

Command Format:

Tar [required parameters] [select parameters] [files]

Command function:

Used to compress and decompress files. Tar itself does not have the compression function. It is implemented by calling the compression function.

Command parameters:

Necessary parameters are as follows:

-A adds A compressed file to an existing compressed file.

-B. Set the block size.

-C create a new compressed file

-D record file difference

-R: add files to compressed files.

-U added and changed existing files to existing compressed files.

-X Extract files from compressed files

-T display the compressed file content

-Z supports gzip file Extraction

-J supports bzip2 File Extraction

-Z supports compress file Extraction

-V shows the operation process

-L file system boundary settings

-K keep the original file not to overwrite

-M: The reserved file is not overwritten.

-W confirm the correctness of the compressed file

The optional parameters are as follows:

-B: set the number of blocks.

-C switch to the specified directory

-F: Specify the compressed file

-- Help: displays help information.

-- Version: displays version information.

(Note: tar is packed, not compressed !)

 

1.2.2 Extract

Be sure to pay attention to the path of the file and the decompressed path. It is very important to set the environment variables later. My files are stored in the root user's home directory, that is, under the/root directory. and decompressed files are also in this directory. The decompressed jdk file name is jdk1.7.0 _ 51.

Unzip the command:

Tar-xzvf jdk-7u51-linux-x64.tar.gz

1.3 set Environment Variables

 

You can edit/etc/profile to add environment variables, or use echo to write environment variables. Both methods aim to enable Java environment variables when a bash is started.

 

1.3.1 edit/etc/profile and add Environment Variables

Back up data first!

Cp/etc/profile. bak vim/etc/profile export JAVA_HOME =/root/jdk1.7.0 _ 51 export PATH = $ JAVA_HOME/bin: $ PATH export CLASS_PATH =.: $ JAVA_HOME/lib/dt. jar: $ JAVA_HOME/lib/tools. jar: $ CLASS_PATH: Save and exit the file and make the modification take effect. Source/etc/profile


1.3.2 write via echo

Remember to back up the data first (back up an original/etc/profile )!

Cp/etc/profile. bak

After the backup, enter the following command on the terminal:

 

                        echo export JAVA_HOME=`pwd`/ jdk1.7.0_51 >> /etc/profile                        echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile                        echo 'export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASS_PATH' >> /etc/profile                        source /etc/profile


1.4 Verification

 

A) java-version

Use java-version verification. If the version information of JDK 7 is displayed, the installation is successful.

B) Make sure it works: Create a Java file, compile and execute it, and check whether it can be correctly executed.

 

 

Ii. Shell Installation

 

In fact, Shell installation is to integrate the commands used in the above command input through the terminal into a Shell script. installation is to execute the Shell script. Note the directory file. Here, the root account's home directory --/root is used. To use this Shell correctly, you need to put the jdk compressed file and the shell in the/root directory, and then run install_jdk7.sh

Install_jdk7.sh script content:

    #!bin/bash    #andyChen461857202@qq.com    #2014-4-9    #thefirst time of create it .    cd~    tar–xzvf jdk-7u51-linux-x64.tar.gz    cp/etc/profile /etc/profile.bak    echo export JAVA_HOME=`pwd`/ jdk1.7.0_51  >> /etc/profile    echo 'export PATH=$JAVA_HOME/bin:$PATH' >> /etc/profile    echo 'export CLASS_PATH=.:$JAVA_HOME/lib/dt.jar:$JAVA_HOME/lib/tools.jar:$CLASS_PATH' >> /etc/profile    source /etc/profile    java –version

Run install_jdk7.sh

        bash install_jdk7.sh

If you enter the version information of jdk 7, jdk can be used normally.

It's really convenient!


Iii. Uninstall JDK

 

Unlike installing software, jdk can also be seen from its configuration process, that is, decompression, configuration of environment variables, so-called uninstallation, deletion of files, and restoration of environment variables.

 

3.1 Delete the decompressed JDK file.

 

              cd~              rm-rfjdk1.7.0_51

3.2 modify Environment Variables

 

Delete the environment variable settings in/etc/profile,

                sourc /etc/profile



More: Linux Study Notes-start

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.