Linu study Notes-install and uninstall JDK on ubuntu

Source: Internet
Author: User
Linu Study Notes & mdash; install and uninstall JDK 17 in ubuntu abstract: describes how to install and uninstall JDK in 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.

1. manually install 1.1 to 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 the 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 exportJAVA_HOME =/root/jdk1.7.0 _ 51 exportPATH = $ JAVA_HOME/bin: $ PATH exportCLASS_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                        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    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
Related Article

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.