CentOS installation JDK1.7 setting environment variables and the difference between profile and BASHRC files

Source: Internet
Author: User

1. Check if JDK is installed in the current system (usually the default installation in CentOS OpenJDK)

# java–version

If OPENJDK is present, it needs to be uninstalled first:

# Rpm-qa|grep JDK or Rpm-qa|grep Java
java-1.6.0-openjdk-1.***
java-1.7.0-openjdk-1.***

# Rpm-qa|grep GCJ
java-1.***
libgcj-***

# yum-y Remove Java java-1.6.0-openjdk-1.***
# yum-y Remove Java java-1.7.0-openjdk-1.***
# yum-y Remove Java java-1.***
# yum-y libgcj-***

2. Download JDK1.7

Http://www.oracle.com/technetwork/java/javase/downloads/index.html

Pull to the bottom and click DOWNLOAD Download history version under Java Archive.

Select Java SE7

Choose Accept License Agreement agree to various conditions, here to download the time need to login (so to register an Oracle account) ...

Upload to the server.

I uploaded it under the/usr/local/directory. ...... This location is optional and is self-planning as needed.

3. Unzip the file

[Email Protected]_7_135_centos local]# cd/usr/local/
[Email protected]_7_135_centos local]# tar zxvf jdk-7u80-linux-x64.tar.gz

In fact, decompression is equivalent to the installation is complete.

[Email Protected]_7_135_centos bin]# pwd
/usr/local/jdk1.7.0_80/bin

We can execute Java commands in the bin directory, such as:

[Email Protected]_7_135_centos bin]#./java-version
Java Version "1.7.0_80"
Java (TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot (TM) 64-bit Server VM (build 24.80-b11, Mixed mode)

If you need to use Java commands in any location, you need to configure environment variables.

4. Setting Environment variables

Write the environment variables to the/etc/profile file or the. bashrc file, refer to 5th. Configure here to/etc/profile

[Email Protected]_7_135_centos bin]# VI +/etc/profile

At the end of the file, add:

Export java_home=/usr/local/jdk1.7.0_80
Export path= $JAVA _home/bin: $PATH

To make the setting effective:

[Email Protected]_7_135_centos ~]# source/etc/profile

Test:

[Email Protected]_7_135_centos ~]# pwd
/root
[Email Protected]_7_135_centos ~]# java-version
Java Version "1.7.0_80"
Java (TM) SE Runtime Environment (build 1.7.0_80-b15)
Java HotSpot (TM) 64-bit Server VM (build 24.80-b11, Mixed mode)

Another: You can add CLASSPATH if needed

Export classpath=.: $JAVA _home/jre/lib/rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

5. The difference between profile and BASHRC file

The difference between the/and ~:

Symbol ~ Represents the current user directory in Linux:

/is a directory separator character.
~ is a placeholder that indicates the address of the personal directory.

/Is the root node,
~ It's home.
If you log in with the root account, it's/root/.
If you log in as a normal user ~ is/home/name/

/etc/profile,/ETC/BASHRC, ~/.bash_profile, ~/.BASHRC four files in the environment variables in the difference and role:

1,/etc/profile used to set the system environment (parameter) variable (number), such as $path. The environment variables are in effect for all users in the system.

2,/ETC/BASHRC This file setting system-bash shell related, for all users in the system to take effect. As long as the user runs the Bash command, the inside thing is working.

3, ~/.bash_profile: Used to set some environment variables, functions and/etc/profile similar, but this is the user level to set, that is, you set the environment variables in/home/{username}/.bash_profile, Then this environment variable is only valid for this user.

4, ~/.BASHRC: function similar to/ETC/BASHRC, only valid for the current user, not for other users to take effect.

In addition, the variables set in/etc/profile are global and can be applied to any user.

The variables set in ~/.BASHRC and so on can only inherit variables from/etc/profile, and they are "parent-child" relationships.

~/.bash_profile is an interactive, login way to enter bash, meaning that only the user is logged in will take effect.

~/.BASHRC is an interactive non-login way into bash, and the user is not necessarily logged in, as long as the command line is run as that user and the file is read.

CentOS Installation JDK1.7 setting environment variables and the difference between profile and BASHRC files

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.